Skip to content

Commit 603bab4

Browse files
authored
Merge pull request #84 from revbayes/fix-tests
Don't skip remaining tests if one segfaults.
2 parents 1b0befe + 3da13e0 commit 603bab4

File tree

1 file changed

+47
-83
lines changed

1 file changed

+47
-83
lines changed

tutorials/run_tutorial_tests.sh

Lines changed: 47 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -50,52 +50,74 @@ fi
5050
tests=()
5151
status=()
5252

53+
RED="\033[31;1m" #bold red
54+
GREEN="\033[32;1m" #bold green
55+
BLUE="\033[34;1m" # bold blue
56+
BOLD="\033[1m"
57+
CLEAR="\033[0m"
58+
UNDERLINE="\033[4m"
59+
60+
BLUE2=$'\033[34;1m'
61+
CLEAR2=$'\033[0m'
62+
63+
5364
for t in */tests.txt; do
5465
testname=`echo $t | cut -d '/' -f 1`;
5566

5667
cd $testname
5768
tests+=($testname)
5869

59-
printf "\n\n#### Running test: $testname\n\n"
60-
61-
for script in $(cat tests.txt);
62-
do
70+
printf "\n${BOLD}#### Running tests for tutorial ${CLEAR}${UNDERLINE}$testname${CLEAR}\n"
71+
72+
test_result=0
73+
for script in $(cat tests.txt); do
74+
printf " ${script}: "
75+
6376
if [ ! -e "scripts/${script}" ] ; then
6477
echo "script '${script}' from ${t} is missing!"
6578
exit 1
6679
fi
6780

81+
mkdir -p output
6882
(
69-
cd scripts
70-
cat "$script" |
83+
cd scripts
84+
cat "$script" |
7185
sed 's/generations=[0-9]*/generations=1/g' |
7286
sed 's/^n_gen *= *[0-9]*/n_gen = 1/' |
7387
sed 's/\.burnin([0-9][0-9]*/.burnin(1/' |
7488
sed 's/\.run([0-9][0-9]*/.run(1/' |
7589
sed 's/checkpointInterval=[0-9]*/checkpointInterval=1/g' > "cp_$script"
7690
)
77-
${rb_exec} -b scripts/cp_$script
78-
res="$?"
79-
if [ $res = 1 ]; then
80-
res="error: $f"
81-
break
82-
elif [ $res = 139 ]; then
83-
res="segfault: $f"
84-
break
85-
elif [ $res != 0 ]; then
86-
res="error $res: $f"
87-
break
91+
${rb_exec} -b scripts/cp_$script &> "output/${script%.[Rr]ev}.errout"
92+
script_result="$?"
93+
94+
if [ "${script_result}" = 139 ]; then
95+
script_result="SEGFAULT"
96+
elif [ "${script_result}" != 0 ]; then
97+
script_result="error ${script_result}"
8898
fi
89-
if [ $res != 0 ] ; then
90-
echo "${testname} ==> error $res"
99+
100+
if [ "${script_result}" != 0 ] ; then
101+
script_result="${script}=${script_result}"
102+
tail -n 5 "output/${script%.[Rr]ev}.errout" | sed "s/^/ ${BLUE2}|${CLEAR2} /g"
103+
printf "\n ${RED}FAIL${CLEAR}: ${script_result}\n"
104+
echo
105+
if [ "${test_result}" = 0 ] ; then
106+
test_result="\t${script_result}\n"
107+
else
108+
test_result="${test_result}\t${script_result}\n"
109+
fi
110+
else
111+
printf "${GREEN}done${CLEAR}.\n"
91112
fi
92113
rm scripts/cp_$script
93114
rm -rf output
94115
done
95116

96-
status+=("$res")
117+
status+=("${test_result}")
118+
119+
cd $OLDPWD
97120

98-
cd -
99121
done
100122

101123
printf "\n\n#### Checking output from tests... \n"
@@ -106,74 +128,16 @@ i=0
106128
while [ $i -lt ${#tests[@]} ]; do
107129
t=${tests[$i]}
108130

109-
if [ -d test_$t ]; then
110-
cd test_$t
111-
112-
# check if output matches expected output
113-
errs=()
114-
exp_out_dir="output_expected"
115-
# Sebastian: For now we only use single cores until we fix Travis mpirun
116-
# if [ "${mpi}" = "true" ]; then
117-
# if [ -d "output_expected_mpi" ]; then
118-
# exp_out_dir="output_expected_mpi"
119-
# fi
120-
# fi
121-
if [ "$windows" = "true" ]; then
122-
find output -type f -exec dos2unix {} \;
123-
find output -type f -exec sed -i 's/e-00/e-0/g' {} \;
124-
find output -type f -exec sed -i 's/e+00/e+0/g' {} \;
125-
fi
126-
127-
# some special handling for the *.errout files
128-
for f in scripts/*.[Rr]ev ; do
129-
tmp0=${f#scripts/}
130-
tmp1=${tmp0%.[Rr]ev}
131-
132-
# Delete all before the 1st occurrence of the string ' Processing file' (inclusive)
133-
# Use a temporary intermediate file to make this work w/ both GNU and BSD sed
134-
sed '1,/ Processing file/d' output/${tmp1}.errout > output/${tmp1}.errout.tmp
135-
mv output/${tmp1}.errout.tmp output/${tmp1}.errout
136-
137-
# Also delete the final line of failing tests, which reprints the path to the script
138-
# that differs between Windows and Unix (has no effect if the line is absent)
139-
sed '/ Error:\tProblem processing/d' output/${tmp1}.errout > output/${tmp1}.errout.tmp
140-
mv output/${tmp1}.errout.tmp output/${tmp1}.errout
141-
142-
# Account for OS-specific differences in path separators
143-
if [ "$windows" = "true" ]; then
144-
sed 's/\\/\//g' output/${tmp1}.errout > output/${tmp1}.errout.tmp
145-
mv output/${tmp1}.errout.tmp output/${tmp1}.errout
146-
fi
147-
done
148-
149-
for f in $(ls ${exp_out_dir}); do
150-
if [ ! -e output/$f ]; then
151-
errs+=("missing: $f")
152-
elif ! diff output/$f ${exp_out_dir}/$f > /dev/null; then
153-
errs+=("mismatch: $f")
154-
fi
155-
done
156-
157-
cd ..
158-
fi
159-
160-
# check if a script exited with an error
161-
if [ "${status[$i]}" != 0 ]; then
162-
errs=("${status[$i]}")
163-
fi
164-
165131
# failure if we have an error message
166-
if [ ${#errs[@]} -gt 0 ]; then
132+
if [ "${status[$i]}" != 0 ]; then
167133
if [ -f XFAIL ] ; then
168134
((xfailed++))
169-
printf ">>>> Test failed: $t (expected)\n"
135+
printf ">>>> Test ${RED}failed${CLEAR}: $t (expected)\n"
170136
else
171137
((failed++))
172-
printf ">>>> Test failed: $t\n"
138+
printf ">>>> Test ${RED}failed${CLEAR}: $t\n"
173139
fi
174-
for errmsg in "${errs[@]}"; do
175-
printf "\t$errmsg\n"
176-
done
140+
printf "${status[$i]}"
177141
else
178142
((pass++))
179143
printf "#### Test passed: $t\n"

0 commit comments

Comments
 (0)