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