Repository navigation
Expand file tree
/
Copy pathcheck-scripts.sh
More file actions
executable file
·288 lines (260 loc) · 9.37 KB
/
Copy pathcheck-scripts.sh
File metadata and controls
executable file
·288 lines (260 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env zsh
default_dirs=( "src/script/scala" )
out_root="target/script-tests"
out_ext="out"
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
error_log="$out_root/scripts-errors-$timestamp.log"
expected_errors_in_list=(
src/script/scala/progscala3/IndentationSyntax.scala
src/script/scala/progscala3/appdesign/Deprecated.scala
src/script/scala/progscala3/basicoop/DollarsPercentagesOpaque.scala
src/script/scala/progscala3/basicoop/GoodBad.scala
src/script/scala/progscala3/basicoop/MatchableOpaque.scala
src/script/scala/progscala3/basicoop/tagging/Tags.scala
src/script/scala/progscala3/basicoop/tagging/Tags2.scala
src/script/scala/progscala3/collections/MultiMap.scala
src/script/scala/progscala3/contexts/ExtensionMethodScoping.scala
src/script/scala/progscala3/contexts/ImplicitEvidence.scala
src/script/scala/progscala3/contexts/ImplicitNotFound.scala
src/script/scala/progscala3/contexts/MatchGivens.scala
src/script/scala/progscala3/contexts/SeqUnzip.scala
src/script/scala/progscala3/dynamic/SelectableSQL.scala
src/script/scala/progscala3/meta/compiletime/RequireConst.scala
src/script/scala/progscala3/meta/compiletime/SummonAll.scala
src/script/scala/progscala3/meta/inline/ConditionalMatch.scala
src/script/scala/progscala3/meta/inline/Overrides.scala
src/script/scala/progscala3/meta/inline/Recursive.scala
src/script/scala/progscala3/objectsystem/variance/MutableVariance.scala
src/script/scala/progscala3/patternmatching/AssignmentsFragile.scala
src/script/scala/progscala3/patternmatching/Matchable.scala
src/script/scala/progscala3/patternmatching/MatchExhaustive.scala
src/script/scala/progscala3/patternmatching/MatchForFiltering.scala
src/script/scala/progscala3/patternmatching/MatchSurprise.scala
src/script/scala/progscala3/patternmatching/MatchTypesErasure.scala
src/script/scala/progscala3/patternmatching/UnapplySingleValue2.scala
src/script/scala/progscala3/rounding/InfixMethod.scala
src/script/scala/progscala3/rounding/InfixType.scala
src/script/scala/progscala3/rounding/TypeErasureProblem.scala
src/script/scala/progscala3/typelessdomore/FibonacciTailrec.scala
src/script/scala/progscala3/typelessdomore/Human.scala
src/script/scala/progscala3/typelessdomore/MethodBroadInference.scala
src/script/scala/progscala3/typelessdomore/MethodNestedReturn.scala
src/script/scala/progscala3/typelessdomore/MethodRecursiveReturn.scala
src/script/scala/progscala3/typelessdomore/RepeatedParameters.scala
src/script/scala/progscala3/typesystem/bounds/ViewToContextBounds.scala
src/script/scala/progscala3/typesystem/deptypes/DependentTypes.scala
src/script/scala/progscala3/typesystem/deptypes/DependentTypesBounds.scala
src/script/scala/progscala3/typesystem/deptypes/DependentTypesSimple.scala
src/script/scala/progscala3/typesystem/deptypes/DependentTypesTuples.scala
src/script/scala/progscala3/typesystem/intersectionunion/Intersection.scala
src/script/scala/progscala3/typesystem/intersectionunion/Union.scala
src/script/scala/progscala3/typesystem/typepaths/TypePath.scala
src/script/scala/progscala3/typesystem/valuetypes/SingletonTypes.scala
src/script/scala/progscala3/typesystem/valuetypes/TypeProjection.scala
)
declare -A expected_errors_in
for name in ${expected_errors_in_list[@]}
do
expected_errors_in["$name"]=true
done
declare -A skip_scripts
skip_scripts["src/script/scala/progscala3/typesystem/matchtypes/MatchTypes2.scala"]=true
error() {
echo "ERROR: $@"
help
exit 1
}
pause() {
echo
printf 'Hit return to continue...'
read line
echo
}
help() {
cat << EOF
Checks the script files by loading them in the interpreter. Note that Scala 3
changes the way "scripts" are interpreted. They are now expected to have @main
methods (or old-style main methods), while the "scripts" in this repo are really
just intended for interactive sessions. Hence, ":load file" is used here. There
are files with @main methods under src/main that can be interpreted as Scala 3
"scripts" by the REPL, in which case you just pass the path as a command-line
argument.
So, this bash script starts the REPL (using "sbt console") for each file and then
uses :load to load the file. The output for that console sessions is written to
$out_root/path/to/file.$out_ext.
A list of files with errors or warnings is written to $error_log.
The following files are known to throw errors intentionally:
$(for f in ${(k)expected_errors_in}; do echo " $f"; done)
Failures for these known files are ignored, but logged in $error_log.
In most of them, you'll see a comment on the same line, like "// ERROR" or "// COMPILATION ERROR",
which are easier to spot when looking at error messages. In the rest of the cases, you have to
look at the book discussion to see if the error is expected. Unfortunately, this means that any
unexpected errors in these files will be missed, unless you inspect the output carefully!
For finding unexpected errors, the console output is searched for errors by looking
for any of the following lines near the end (where N=2+):
1 warning found
N warnings found
1 error found
N errors found
** HOWEVER, to be really safe, all the outputs should still be inspected manually. **
Usage: $0 [options]
Where the options are:
-h | --help Print this message and exit.
-v | --verbose Print each file name to the console as it is processed and dump
to stdout the test output (in the script's corresponding
"$out_root/...").
-c | --clean Delete all previous output.
-n | --no-exec Don't execute the commands, just echo what would be done.
-i | --interactive Pause after each script is run, waiting for confirmation to continue.
This is the probably the easiest way, if tedious, to visually verify
that ever script returns the expected results. Implies --verbose.
--check | --check-only
Don't run the scripts; just check for reported errors only
on any existing output files under $out_root.
dir ... Start in these directories. (default "${default_dirs[@]}")
You can specify individual script files, too.
EOF
}
: ${VERBOSE:=false}
: ${CLEAN:=false}
: ${CHECK_ONLY=false}
: ${INTERACTIVE=false}
: ${NOOP:=}
dirs=()
while [[ $# -gt 0 ]]
do
case $1 in
-h|--h*)
help
exit 0
;;
-v|--v*)
VERBOSE=true
;;
--check*)
CHECK_ONLY=true
;;
-c|--cl*)
CLEAN=true
;;
-i|--interactive)
INTERACTIVE=true
VERBOSE=true
;;
-n|--n*)
NOOP=echo
;;
-*)
error "Unknown argument $1"
;;
*)
dirs+=($1)
;;
esac
shift
done
[[ ${#dirs[@]} -gt 0 ]] || dirs=( ${default_dirs[@]} )
$VERBOSE && echo "Reading directories: ${dirs[@]}"
if $CLEAN
then
$VERBOSE && echo "Cleaning old output in $out_root..."
[[ -n "$out_root" ]] && $NOOP rm -rf "$out_root" # safety check!
fi
rm -f $error_log
print_count() {
let count=$1; shift
file=$1; shift
out=$1; shift
message="$1"; shift
printf '%5d: %s %s %s\n' $count "$file" "$out" "$message" >> $error_log
$INTERACTIVE && printf '%s %s %s\n' "$file" "$out" "$message"
}
count_problem() {
script=$1
out=$2
let count=0
[[ -z $NOOP ]] && let count=$(grep -cE "^.+ (error|warning)s? found$" "$out")
[[ $count -gt 0 ]] && print_count $count $script $out
return $count
}
report() {
let run_status=$1
script=$2
out=$3
if [[ -n "$expected_errors_in[\"$script\"]" ]]
then
print_count 0 "$script" "$out" "NOTE: because of known deliberate errors, unexpected errors might be missed!"
return 0
fi
let error_count=0
if [[ $run_status -ne 0 ]]
then
echo "ERROR: $script failed! ($out)"
let error_count+=1
fi
count_problem "$script" "$out"
let error_count+=$?
# $VERBOSE && cat "$out"
return $error_count
}
export total_problem_count
let total_problem_count=0
check() {
script="$1"
if [[ -n $skip_scripts["$script"] ]]
then
echo "*** WARNING: Skipping script with known errors: $script ***"
return 0
fi
out="$out_root/$script.$out_ext"
$VERBOSE && echo "$script --> $out"
if ! $CHECK_ONLY
then
$NOOP rm -f "$out"
$NOOP mkdir -p $(dirname $out)
if [[ -z "$NOOP" ]]
then
TERM=dumb sbt console <<EOF > "$out"
:load $script
EOF
else
$NOOP "TERM=dumb sbt console ... :load $script ... > $out"
fi
fi
$NOOP report $? "$script" "$out"
$INTERACTIVE && $NOOP cat "$out"
let total_problem_count+=$?
# return $?
}
problem_count="$out_root/scripts-problem-count.txt" # see "hack" note below.
$NOOP rm -f "$problem_count"
scala_files=()
for dir in "${dirs[@]}"
do
find "$dir" -name '*.scala' | while read f
do
scala_files+=("$f")
done
$VERBOSE && echo "Trying ${#scala_files[@]} scripts..."
for f in ${scala_files[@]}
do
check $f
# hack! The value of total_problem_count is lost to the outer shell,
# so write the values to a file for consumption "outside".
[[ -z $NOOP ]] && echo $total_problem_count >> "$problem_count"
$INTERACTIVE && pause
done
done
if [[ -f "$problem_count" ]]
then
let total_problem_count=$(tail -n 1 "$problem_count")
rm -f "$problem_count"
if [[ $total_problem_count -gt 0 ]]
then
echo "ERROR: $total_problem_count issues found. See $error_log"
print_count $total_problem_count $error_log "" "issues found!"
exit 1
fi
fi
echo "No obvious issues found (although this can be erroneous!). So, consider checking all the output files in $out_root!"
exit 0