84f3c9975ebfeb5f9e875cfc84086dd153522726
[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 COLUMNS=40
9 regenerate=
10 diffcmd () {
11         comm --nocheck-order --output-delimiter=::: -3 $@ |
12         perl -pe'END{exit !!$.} s/^:::/>/ || s/^/</'
13 }
14
15 for option in "$@"
16 do
17         case "$option" in
18         -G) regenerate=1 && shift;;
19         -*) echo "Usage: $0 [-G] [<files>...]"; exit 64;;
20         esac
21 done
22
23 for candidate in ${@:-t*.in}
24 do
25         test_count=$((test_count+1))
26         file="${candidate%.in}"
27         test -r "$file.in" || continue
28
29         name="$(echo ${file#*-} | tr _ \ )"
30         cmd="barcat $file.in"
31         case "$name" in *\ -*) cmd="$cmd -${name#* -}";; esac
32
33         if test -n "$regenerate"
34         then
35                 if test -e $file.sh
36                 then
37                         echo "ok $test_count # skip $file.out"
38                         continue
39                 fi
40                 $cmd >$file.out 2>&1
41         else
42                 if test -e $file.sh;  then $cmd 2>&1 | ./$file.sh; fi &&
43                 if test -e $file.out; then $cmd 2>&1 | diffcmd "$file.out" -; fi
44         fi
45
46         if test 0 != $?
47         then
48                 fail_count=$((fail_count+1))
49                 printf 'not '
50         fi
51         echo "ok $test_count - $name"
52 done
53
54 echo "1..$test_count"
55 exit $((fail_count>0))