-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_baseline.sh
executable file
·96 lines (81 loc) · 2.38 KB
/
check_baseline.sh
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
#!/bin/bash
COMMAND="stack"
OPTIONS=" exec GrinHC -- "
LEX_COMMAND="--lex "
PARSE_COMMAND="--parse "
STEP_COMMAND="--step "
TEST_SUFFIX=".in"
EVAL_SUFFIX=".out"
LEX_SUFFIX=".out.lex"
PARSE_SUFFIX=".out.parse"
STEP_SUFFIX=".out.step"
if [ -z "$1" ]
then
echo "Usage: check_baseline.sh <test|testdir>"
exit 1
fi
TEST_DIR="$(realpath $1)"
FAILED=false
if [ -d $TEST_DIR ] && [ "$(basename $TEST_DIR)" == "baselines" ]
then
for file in "$TEST_DIR"/*"$TEST_SUFFIX"; do
echo -n "Checking $file"
# Create temp files within /tmp
tmpfile_eval=$(mktemp)
tmpfile_lex=$(mktemp)
tmpfile_parse=$(mktemp)
tmpfile_step=$(mktemp)
# Create outfile name for tested file
eval_outfile="${file%.*}"$EVAL_SUFFIX
lex_outfile="${file%.*}"$LEX_SUFFIX
parse_outfile="${file%.*}"$PARSE_SUFFIX
step_outfile="${file%.*}"$STEP_SUFFIX
echo -n "."
# Evaluate and diff the output
eval $COMMAND$OPTIONS$file > $tmpfile_eval 2>&1
eval $COMMAND$OPTIONS$LEX_COMMAND$file > $tmpfile_lex 2>&1
eval $COMMAND$OPTIONS$PARSE_COMMAND$file > $tmpfile_parse 2>&1
eval $COMMAND$OPTIONS$STEP_COMMAND$file > $tmpfile_step 2>&1
# Generate diffs
diff_output_eval="$(diff $tmpfile_eval $eval_outfile)"
diff_output_lex="$(diff $tmpfile_lex $lex_outfile)"
diff_output_parse="$(diff $tmpfile_parse $parse_outfile)"
diff_output_step="$(diff $tmpfile_step $step_outfile)"
echo -n "."
# Print out any differences between generated output and outfiles
if [ -n "$diff_output_eval" ]
then
echo "$diff_output_eval"
FAILED=true
fi
if [ -n "$diff_output_lex" ]
then
echo "$diff_output_lex"
FAILED=true
fi
if [ -n "$diff_output_parse" ]
then
echo "$diff_output_parse"
FAILED=true
fi
if [ -n "$diff_output_step" ]
then
echo "$diff_output_step"
FAILED=true
fi
echo -n "."
rm $tmpfile_eval
rm $tmpfile_lex
rm $tmpfile_parse
rm $tmpfile_step
echo "Done"
done
echo "Completed Testing."
fi
# Exit with failure since a test failed
if [ $FAILED = true ]
then
exit 1
fi
# Exit successfully, indicating tests passed
exit 0