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