-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotest
executable file
·91 lines (80 loc) · 2.74 KB
/
dotest
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
#!/bin/bash
#
# Automated regression test driver for wat-frontend
#
# Place tests in a directory and create subdirectories for each phase to be
# tested. (At the moment "lex" and "parse" subdirectories are expected.)
#
# To lex a "components" directory (for example), execute
# ./dotest lex tests/components/
#
# To parse the same directory, execute
# ./dotest parse tests/components/
#
# The test results are output to the "lex" subdirectory as "x.toks.out" and
# "x.toks.err" or "parse" subdirectory as "x.ast.out" and "x.ast.err" for some
# test "x.wat" (WebAssembly text) or "x.tok" (plain tokens).
#
# If baseline ".expect" files exist, the results are diffed against them. Otherwise,
# baseline files are created from the output files. An empty baseline test means
# a result is not expected (and the result in the corresponding error or output file
# is expected instead).
#
# Note that the test directories must contain only ".tok" files for token tests or
# ".wat" files for WebAssembly text tests. This script _will_ run on any file in the
# directory.
run_tests () {
local command=$1
local source_dir=$2
local output_dir=$3
local result=$4
for file in $source_dir*
do
if [ -f $file ]
then
if [ $source_dir = "tests/tokens/" ]
then
local test=`basename $file .tok`
else
local test=`basename $file .wat`
fi
# run command
./dist/build/wat-frontend/wat-frontend $command $file -o $output_dir/
# touch ouputs or create them (the parser deletes all previous results)
touch $output_dir/$test.$result.out
touch $output_dir/$test.$result.err
# diff with expected results or copy results to set expectations
echo $test:
if [ -r $output_dir/$test.$result.out.expect ]
then
diff $output_dir/$test.$result.out.expect $output_dir/$test.$result.out
else
cp $output_dir/$test.$result.out $output_dir/$test.$result.out.expect
fi
if [ -r $output_dir/$test.$result.err.expect ]
then
diff $output_dir/$test.$result.err.expect $output_dir/$test.$result.err
else
cp $output_dir/$test.$result.err $output_dir/$test.$result.err.expect
fi
fi
done
}
command=$1
source_dir=$2
if [ $command = "lex" ]
then
# set output directory, create if it does not exist
output_dir=${source_dir}lex
mkdir -p ./$output_dir
# run lexer tests
run_tests $command $source_dir $output_dir "toks"
elif [ $command = "parse" ]
then
output_dir=${source_dir}parse
mkdir -p ./$output_dir
# run parser tests
run_tests $command $source_dir $output_dir "ast"
else echo "Only \"lex\" or \"parse\" tests are currently available"
fi
exit 0