6 default_cmd
="sparse \$file"
7 tests_list
=`find . -name '*.c' | sed -e 's#^\./\(.*\)#\1#' | sort`
8 prog_name
=`basename $0`
11 # - tests that have not been converted to test-suite format
14 # - tests that failed but are known to fail
20 # defaults to not verbose
24 # get_value(key, file) - gets the value of a (key, value) pair in file.
26 # returns 0 on success, 1 if the file does not have the key
29 last_result
=`grep $1: $2 | sed -e "s/^.*$1:\(.*\)$/\1/"`
30 [ -z "$last_result" ] && return 1
35 # get_tag(key, file) - does file has the tag key in it ?
37 # returns 0 if present, 1 otherwise
40 last_result
=`grep $1 $2`
45 # verbose(string) - prints string if we are in verbose mode
48 [ "$V" -eq "1" ] && echo " $1"
53 # error(string[, die]) - prints an error and exits with value die if given
57 [ -n "$2" ] && exit $2
63 echo "$prog_name - a tiny automatic testing script"
64 echo "Usage: $prog_name [command] [command arguments]"
67 echo " none runs the whole test suite"
68 echo " single file runs the test in 'file'"
69 echo " format file [name [cmd]] helps writing a new test case using cmd"
71 echo " help prints usage"
75 # do_test(file) - tries to validate a test case
77 # it "parses" file, looking for check-* tags and tries to validate
78 # the test against an expected result
80 # - 0 if the test passed,
82 # - 2 if it is not a "test-suite" test.
88 # can this test be handled by test-suite ?
89 # (it has to have a check-name key in it)
90 get_value
"check-name" $file
91 if [ "$?" -eq 1 ]; then
92 unhandled_tests
=`expr $unhandled_tests + 1`
95 test_name
=$last_result
97 echo " TEST $test_name ($file)"
99 # does the test provide a specific command ?
100 cmd
=`eval echo $default_path/$default_cmd`
101 get_value
"check-command" $file
102 if [ "$?" -eq "0" ]; then
103 last_result
=`echo $last_result | sed -e 's/^ *//'`
104 cmd
=`eval echo $default_path/$last_result`
106 verbose
"Using command : $cmd"
108 # grab the expected exit value
109 get_value
"check-exit-value" $file
110 if [ "$?" -eq "0" ]; then
111 expected_exit_value
=`echo $last_result | tr -d ' '`
113 expected_exit_value
=0
115 verbose
"Expecting exit value: $expected_exit_value"
117 # grab the expected output
118 sed -n '/check-output-start/,/check-output-end/p' $file \
119 |
grep -v check-output
> "$file".output.expected
120 sed -n '/check-error-start/,/check-error-end/p' $file \
121 |
grep -v check-error
> "$file".error.expected
123 # grab the actual output & exit value
124 $cmd 1> $file.output.got
2> $file.error.got
127 for stream
in output error
; do
128 diff -u "$file".
$stream.expected
"$file".
$stream.got
> "$file".
$stream.
diff
129 if [ "$?" -ne "0" ]; then
130 error
"actual $stream text does not match expected $stream text."
131 error
"see $file.$stream.* for further investigation."
136 if [ "$actual_exit_value" -ne "$expected_exit_value" ]; then
137 error
"Actual exit value does not match the expected one."
138 error
"expected $expected_exit_value, got $actual_exit_value."
142 if [ "$test_failed" -eq "1" ]; then
143 ko_tests
=`expr $ko_tests + 1`
144 get_tag
"check-known-to-fail" $file
145 [ "$?" -eq "0" ] && known_ko_tests
=`expr $known_ko_tests + 1`
148 ok_tests
=`expr $ok_tests + 1`
155 for i
in $tests_list; do
159 # prints some numbers
160 tests_nr
=`expr $ok_tests + $ko_tests`
161 echo -n "Out of $tests_nr tests, $ok_tests passed, $ko_tests failed"
162 echo " ($known_ko_tests of them are known to fail)"
163 if [ "$unhandled_tests" -ne "0" ]; then
164 echo "$unhandled_tests tests could not be handled by $prog_name"
169 # do_format(file[, name[, cmd]]) - helps a test writer to format test-suite tags
175 elif [ -z "$3" ]; then
183 cmd
=`eval echo $default_path/$fcmd`
184 $cmd 1> $file.output.got
2> $file.error.got
190 if [ "$fcmd" != "$default_cmd" ]; then
191 echo " * check-command: $fcmd"
193 if [ "$fexit_value" -ne "0" ]; then
194 echo " * check-exit-value: $fexit_value"
196 for stream
in output error
; do
197 if [ -s "$file.$stream.got" ]; then
199 echo " * check-$stream-start"
200 cat "$file.$stream.got"
201 echo " * check-$stream-end"
209 # arg_file(filename) - checks if filename exists
217 error
"Can't open file $1"
231 0) echo "$2 passed !";;
232 1) echo "$2 failed !";;
233 2) echo "$2 can't be handled by $prog_name";;
238 do_format
"$2" "$3" "$4"