t/regress: prepend commands to output files, cmddiff to compare
[barcat.git] / t / regress.t
1 #!/bin/sh
2
3 cd "${0%/*}" || exit 1
4
5 test_count=0
6 fail_count=0
7
8 colorize=
9 test -t 1 && colorize=1
10 color () {
11         test -n "$colorize" &&
12         printf '\33[%sm' $@
13 }
14
15 for option in "$@"
16 do
17         case "$option" in
18         -*) echo "Usage: $0 [<files>...]"; exit 64;;
19         esac
20 done
21
22 params="${@:-t*.out}"
23 color 0\;36
24 echo "1..$(echo $params | wc -w)"
25 color 0
26
27 for candidate in $params
28 do
29         test_count=$((test_count+1))
30         file="${candidate%.out}"
31         name="$(echo ${file#*-} | tr _ \ )"
32
33         if test -e "$file.out"
34         then
35                 ./cmddiff "$file.out"
36         else
37                 color 33
38                 echo "not ok $test_count - $name # TODO"
39                 color 0
40                 continue
41         fi
42
43         if test 0 != $?
44         then
45                 case "$name" in
46                 *' #TODO')
47                         color 33
48                         ;;
49                 *)
50                         fail_count=$((fail_count+1))
51                         color 1\;31
52                 esac
53
54                 printf 'not '
55         fi
56         echo "ok $test_count - $name"
57         color 0
58 done
59
60 if test $fail_count = 0
61 then
62         color 32
63         echo "# passed all $test_count test(s)"
64 else
65         color 31
66         echo "# failed $fail_count among $test_count test(s)"
67         fail_count=1  # exit code
68 fi
69 color 0
70
71 exit $fail_count