Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2414d9c

Browse files
Added a "check-mains.sh" script.
Signed-off-by: Dean Wampler <dean.wampler@ibm.com>
1 parent ca5ed34 commit 2414d9c

File tree

2 files changed

+247
-8
lines changed

2 files changed

+247
-8
lines changed

‎check-mains.sh

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
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+

‎check-scripts.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ default_dirs=( "src/script/scala" )
44
out_root="target/script-tests"
55
out_ext="out"
66
timestamp=$(date +"%Y-%m-%d_%H-%M-%S")
7+
error_log="$out_root/scripts-errors-$timestamp.log"
78
expected_errors_in=(
89

910
src/script/scala/progscala3/IndentationSyntax.scala
@@ -67,12 +68,12 @@ So, this bash script starts the REPL (using "sbt console") for each file and the
6768
uses :load to load the file. The output for that console sessions is written to
6869
$out_root/path/to/file.$out_ext.
6970
70-
A list of files with errors or warnings is written to $out_root/errors-$timestamp.log.
71+
A list of files with errors or warnings is written to $error_log.
7172
7273
The following files are known to throw errors intentionally:
7374
$(for f in ${expected_errors_in[@]}; do echo " $f"; done)
7475
75-
Failures for these known files are ignored, but logged in $out_root/errors-$timestamp.log.
76+
Failures for these known files are ignored, but logged in $error_log.
7677
In most of them, you'll see a comment on the same line, like "// ERROR" or "// COMPILATION ERROR",
7778
which are easier to spot when looking at error messages. In the rest of the cases, you have to
7879
look at the book discussion to see if the error is expected. Unfortunately, this means that any
@@ -86,14 +87,15 @@ N warnings found
8687
1 error found
8788
N errors found
8889
90+
8991
** HOWEVER, to be really safe, all the outputs should still be inspected manually. **
9092
9193
Usage: 0ドル [-h|--help] [-v|--verbose] [-c|--clean] [-n|--no-exec] [dir ...]
9294
Where:
9395
-h | --help Print this message and exit.
9496
-v | --verbose Print each file name to the console as it is processed and dump
9597
to stdout the test output (in the script's corresponding
96-
"target/script-tests/...").
98+
"$out_root/...").
9799
-c | --clean Delete all previous output.
98100
-n | --no-exec Don't execute the commands, just echo what would be done.
99101
--check | --check-only
@@ -139,16 +141,14 @@ do
139141
done
140142

141143
[[ ${#dirs[@]} -gt 0 ]] || dirs=( ${default_dirs[@]} )
142-
$VERBOSE && echo "Reading directories ${dirs[@]}"
144+
$VERBOSE && echo "Reading directories: ${dirs[@]}"
143145

144146
if $CLEAN
145147
then
146148
$VERBOSE && echo "Cleaning old output in $out_root..."
147149
[[ -n "$out_root" ]] && rm -rf "$out_root" # safety check!
148150
fi
149151

150-
151-
error_log="$out_root/errors-$timestamp.log"
152152
rm -f $error_log
153153

154154
print_count() {
@@ -197,7 +197,7 @@ let total_problem_count=0
197197
check() {
198198
script="1ドル"
199199
out="$out_root/$script.$out_ext"
200-
$VERBOSE && echo "$f --> $out"
200+
$VERBOSE && echo "$script --> $out"
201201
if ! $CHECK_ONLY
202202
then
203203
$NOOP rm -f "$out"
@@ -217,7 +217,7 @@ EOF
217217
# return $?
218218
}
219219

220-
problem_count="$out_root/problem_count.txt" # see "hack" note below.
220+
problem_count="$out_root/scripts-problem-count.txt" # see "hack" note below.
221221
rm -f "$problem_count"
222222
for dir in "${dirs[@]}"
223223
do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /