|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +out_root="target/main-tests" |
| 4 | +out_ext="out" |
| 5 | +timestamp=$(date +"%Y-%m-%d_%H-%M-%S") |
| 6 | +error_log="$out_root/mains-errors-$timestamp.log" |
| 7 | +def_mains=( |
| 8 | + ScriptWrapper |
| 9 | + progscala3.appdesign.IntDoubleStringMain |
| 10 | + progscala3.appdesign.dbc.TryBankAccount |
| 11 | + progscala3.appdesign.dbc.TryMyLogger |
| 12 | + progscala3.appdesign.parthenon.RunPayroll |
| 13 | + progscala3.basicoop.HelloServiceMain |
| 14 | + progscala3.basicoop.TryComplex |
| 15 | + progscala3.basicoop.scaladb.TryScalaDBRevisited |
| 16 | + progscala3.basicoop.tagging.TryTagging |
| 17 | + progscala3.basicoop.tagging.TryTagging2 |
| 18 | + progscala3.collections.TryListBuilder |
| 19 | + progscala3.concurrency.akka.ServiceClient |
| 20 | + progscala3.concurrency.boundary.BoundaryExamples |
| 21 | + progscala3.concurrency.futures.TryFutureFold |
| 22 | + progscala3.concurrency.futures.TryFuturesCallbacks |
| 23 | + progscala3.concurrency.futures2.TryFuturesForComp |
| 24 | + progscala3.concurrency.process.TryProcess |
| 25 | + progscala3.contexts.TryDerived |
| 26 | + progscala3.contexts.accounting.TryImplicitConversions |
| 27 | + progscala3.contexts.json.TryJSONBuilder |
| 28 | + progscala3.contexts.scaladb.TryScalaDB |
| 29 | + progscala3.contexts.typeclass.new1.TryJSONTypeClasses |
| 30 | + progscala3.contexts.typeclass.new2.TryJSONTypeClasses |
| 31 | + progscala3.contexts.typeclass.new3.TryJSONTypeClasses |
| 32 | + progscala3.contexts.typeclass.new4.TryJSONTypeClasses |
| 33 | + progscala3.contexts.typeclass.old.TryJSONTypeClasses |
| 34 | + progscala3.dsls.payroll.internal.TryPayroll |
| 35 | + progscala3.dsls.payroll.parsercomb.TryPayroll |
| 36 | + progscala3.forcomps.RemoveBlanks |
| 37 | + progscala3.forcomps.TryLoginFormValidatorNec |
| 38 | + progscala3.forcomps.TryLoginFormValidatorSingle |
| 39 | + progscala3.fp.categories.TryFunctionF2A |
| 40 | + progscala3.fp.categories.TryFunctionF2B |
| 41 | + progscala3.fp.categories.TryFunctionF2C |
| 42 | + progscala3.fp.categories.TryFunctionF2D |
| 43 | + progscala3.fp.categories.TryFunctor2 |
| 44 | + progscala3.fp.loops.JavaFactorial |
| 45 | + progscala3.introscala.Hello |
| 46 | + progscala3.introscala.Hello2 |
| 47 | + progscala3.introscala.UpperMain1 |
| 48 | + progscala3.introscala.UpperMain1$package |
| 49 | + progscala3.introscala.shapes.ProcessShapesDriver |
| 50 | + progscala3.javainterop.JavaWithScalaTuples |
| 51 | + progscala3.meta.TryInvariant |
| 52 | + progscala3.meta.TryInvariant1 |
| 53 | + progscala3.meta.TryStaging |
| 54 | + progscala3.meta.TryTracer |
| 55 | + progscala3.meta.TryUsingClassTagViews |
| 56 | + "progscala3.meta.performance.InlinePerf true 10" |
| 57 | + progscala3.objectsystem.CommandArgs |
| 58 | + progscala3.objectsystem.JavaArrays |
| 59 | + progscala3.objectsystem.objects.TryPerson |
| 60 | + progscala3.rounding.FileSizes |
| 61 | + progscala3.rounding.TryCatch |
| 62 | + progscala3.rounding.TryCatchARM |
| 63 | + progscala3.rounding.saferexceptions.SaferExceptions |
| 64 | + progscala3.rounding.saferexceptions.SaferExceptionsNested |
| 65 | + progscala3.typesystem.intersectionunion.IntersectionUnion |
| 66 | + progscala3.typesystem.payroll.TryPhantomTypes |
| 67 | + progscala3.typesystem.payroll.TryPhantomTypesPipeline |
| 68 | + progscala3.typesystem.selftype.TryButtonSubjectObserver |
| 69 | +) |
| 70 | +expected_errors_in=() |
| 71 | + |
| 72 | +error() { |
| 73 | + echo "ERROR: $@" |
| 74 | + help |
| 75 | + exit 1 |
| 76 | +} |
| 77 | + |
| 78 | +help() { |
| 79 | + cat << EOF |
| 80 | +Checks that the "mains" run successfully by running them with the "runMain" sbt command. |
| 81 | + |
| 82 | +So, this bash script starts the REPL (using "sbt console") for each "main" and then |
| 83 | +uses :runMain to execute it. The output for that console sessions is written to |
| 84 | +$out_root/path/to/file.$out_ext. |
| 85 | + |
| 86 | +A list of files with errors or warnings is written to $error_log. |
| 87 | + |
| 88 | +** HOWEVER, to be really safe, all the outputs should still be inspected manually. ** |
| 89 | + |
| 90 | +Usage: 0ドル [-h|--help] [-v|--verbose] [-c|--clean] [-n|--no-exec] [dir ...] |
| 91 | +Where: |
| 92 | +-h | --help Print this message and exit. |
| 93 | +-v | --verbose Print each file name to the console as it is processed and dump |
| 94 | + to stdout the test output (in the script's corresponding |
| 95 | + "$out_root/..."). |
| 96 | +-c | --clean Delete all previous output. |
| 97 | +-n | --no-exec Don't execute the commands, just echo what would be done. |
| 98 | +--check | --check-only |
| 99 | + Don't run the mains; just check for reported errors only |
| 100 | + on any existing output files under $out_root. |
| 101 | +main ... Run these "mains". (default "${def_mains[@]}") |
| 102 | +EOF |
| 103 | +} |
| 104 | + |
| 105 | +: ${VERBOSE:=false} |
| 106 | +: ${CLEAN:=false} |
| 107 | +: ${CHECK_ONLY=false} |
| 108 | +: ${NOOP:=} |
| 109 | +mains=() |
| 110 | + |
| 111 | +while [[ $# -gt 0 ]] |
| 112 | +do |
| 113 | + case 1ドル in |
| 114 | + -h|--h*) |
| 115 | + help |
| 116 | + exit 0 |
| 117 | + ;; |
| 118 | + -v|--v*) |
| 119 | + VERBOSE=true |
| 120 | + ;; |
| 121 | + --check*) |
| 122 | + CHECK_ONLY=true |
| 123 | + ;; |
| 124 | + -c|--cl*) |
| 125 | + CLEAN=true |
| 126 | + ;; |
| 127 | + -n|--n*) |
| 128 | + NOOP=echo |
| 129 | + ;; |
| 130 | + -*) |
| 131 | + error "Unknown argument 1ドル" |
| 132 | + ;; |
| 133 | + *) |
| 134 | + mains+=(1ドル) |
| 135 | + ;; |
| 136 | + esac |
| 137 | + shift |
| 138 | +done |
| 139 | + |
| 140 | +[[ ${#mains[@]} -gt 0 ]] || mains=( ${def_mains[@]} ) |
| 141 | +$VERBOSE && echo "Running mains: ${mains[@]}" |
| 142 | + |
| 143 | +if $CLEAN |
| 144 | +then |
| 145 | + $VERBOSE && echo "Cleaning old output in $out_root..." |
| 146 | + [[ -n "$out_root" ]] && rm -rf "$out_root" # safety check! |
| 147 | +fi |
| 148 | + |
| 149 | +rm -f $error_log |
| 150 | + |
| 151 | +print_count() { |
| 152 | + let count=1ドル; shift |
| 153 | + main=1ドル; shift |
| 154 | + out=1ドル; shift |
| 155 | + message="1ドル"; shift |
| 156 | + printf '%5d: %s %s %s\n' $count "$main" "$out" "$message" >> $error_log |
| 157 | +} |
| 158 | + |
| 159 | +count_problem() { |
| 160 | + main=1ドル |
| 161 | + out=2ドル |
| 162 | + let count=$(grep -cE "^.+ (error|warning)s? found$" "$out") |
| 163 | + [[ $count -gt 0 ]] && print_count $count $main $out |
| 164 | + return $count |
| 165 | +} |
| 166 | + |
| 167 | +report() { |
| 168 | + let status=1ドル |
| 169 | + main=2ドル |
| 170 | + out=3ドル |
| 171 | + for skip in ${expected_errors_in[@]} |
| 172 | + do |
| 173 | + if [[ "$skip" = "$main" ]] |
| 174 | + then |
| 175 | + print_count 0 "$main" "$out" "NOTE: because of known deliberate errors, unexpected errors might be missed!" |
| 176 | + return 0 |
| 177 | + fi |
| 178 | + done |
| 179 | + let error_count=0 |
| 180 | + if [[ $status -ne 0 ]] |
| 181 | + then |
| 182 | + echo "ERROR: $main failed! ($out)" |
| 183 | + let error_count+=1 |
| 184 | + fi |
| 185 | + count_problem "$main" "$out" |
| 186 | + let error_count+=$? |
| 187 | + # $VERBOSE && cat "$out" |
| 188 | + return $error_count |
| 189 | +} |
| 190 | + |
| 191 | +export total_problem_count |
| 192 | +let total_problem_count=0 |
| 193 | + |
| 194 | +check() { |
| 195 | + main="1ドル" |
| 196 | + shift |
| 197 | + out="$out_root/$main.$out_ext" |
| 198 | + $VERBOSE && echo "$main --> $out" |
| 199 | + if ! $CHECK_ONLY |
| 200 | + then |
| 201 | + $NOOP rm -f "$out" |
| 202 | + if [[ -z "$NOOP" ]] |
| 203 | + then |
| 204 | + mkdir -p $(dirname "$out") |
| 205 | + TERM=dumb sbt "runMain $main $@" > "$out" |
| 206 | + else |
| 207 | + $NOOP mkdir -p $(dirname $out) |
| 208 | + $NOOP "TERM=dumb sbt runMain $main $@ > $out" |
| 209 | + fi |
| 210 | + fi |
| 211 | + $NOOP report $? "$main" "$out" |
| 212 | + let total_problem_count+=$? |
| 213 | + # return $? |
| 214 | +} |
| 215 | + |
| 216 | +problem_count="$out_root/mains-problem-count.txt" # see "hack" note below. |
| 217 | +rm -f "$problem_count" |
| 218 | +for main in "${mains[@]}" |
| 219 | +do |
| 220 | + check $main |
| 221 | + # hack! The value of total_problem_count is lost to the outer shell, |
| 222 | + # so write the values to a file for consumption "outside". |
| 223 | + echo $total_problem_count >> "$problem_count" |
| 224 | +done |
| 225 | + |
| 226 | +if [[ -f "$problem_count" ]] |
| 227 | +then |
| 228 | + let total_problem_count=$(tail -n 1 "$problem_count") |
| 229 | + rm -f "$problem_count" |
| 230 | + if [[ $total_problem_count -gt 0 ]] |
| 231 | + then |
| 232 | + echo "ERROR: $total_problem_count issues found. See $error_log" |
| 233 | + print_count $total_problem_count $error_log "" "issues found!" |
| 234 | + exit 1 |
| 235 | + fi |
| 236 | +fi |
| 237 | +echo "No obvious issues found, but consider checking all the output files in $out_root!" |
| 238 | +exit 0 |
| 239 | + |
0 commit comments