test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / test-driver-custom.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 Free Software Foundation, Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
7 # any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 # Custom test drivers: per-extension test drivers.
18
19 . test-init.sh
20
21 cat >> configure.ac << 'END'
22 AC_OUTPUT
23 END
24
25 cat > Makefile.am << 'END'
26 # Automake shouldn't match the '/test' in 'sub/test' as '.test' suffix.
27 TESTS = 1.chk 2.test 3 4.c.chk 5.suf sub/test
28
29 TEST_EXTENSIONS = .chk .test
30
31 CHK_LOG_DRIVER = ./chk-wrapper
32 TEST_LOG_DRIVER = $(SHELL) $(srcdir)/test-wrapper
33 LOG_DRIVER = noext-wrapper
34
35 AM_CHK_LOG_DRIVER_FLAGS = --am-chk
36 CHK_LOG_DRIVER_FLAGS = --chk
37 AM_TEST_LOG_DRIVER_FLAGS = -am-test
38 TEST_LOG_DRIVER_FLAGS = -test
39 AM_LOG_DRIVER_FLAGS = am
40 LOG_DRIVER_FLAGS = _
41 END
42
43 mkdir sub bin
44 PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
45
46 cat > wrapper.skel <<'END'
47 #! /bin/sh
48 set -e
49
50 me=`echo "$0" | sed 's,^.*/,,'`
51 if test -z "$me"; then
52   echo "$0: cannot determine program name" >&2
53   exit 99
54 fi
55
56 am_log_wflags='@am_log_wflags@'
57 log_wflags='@log_wflags@'
58
59 test_name=INVALID
60 log_file=BAD.log
61 trs_file=BAD.trs
62 extra_opts=
63 while test $# -gt 0; do
64   case $1 in
65     --test-name) test_name=$2; shift;;
66     --log-file) log_file=$2; shift;;
67     --trs-file) trs_file=$2; shift;;
68     # Ignored.
69     --expect-failure) shift;;
70     --color-tests) shift;;
71     --enable-hard-errors) shift;;
72     # Remembered in the same order they're passed in.
73     $am_log_wflags|$log_wflags) extra_opts="$extra_opts $1";;
74     # Explicitly terminate option list.
75     --) shift; break;;
76     # Shouldn't happen
77     *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
78   esac
79   shift
80 done
81
82 echo "$me" "$test_name" $extra_opts > "$log_file"
83 : > "$trs_file"
84
85 exec "$@"
86 exit 127
87 END
88
89 sed -e 's|@am_log_wflags@|--am-chk|' \
90     -e 's|@log_wflags@|--chk|' \
91     < wrapper.skel > chk-wrapper
92
93 sed -e 's|@am_log_wflags@|-am-test|' \
94     -e 's|@log_wflags@|-test|' \
95     < wrapper.skel > test-wrapper
96
97 sed -e 's|@am_log_wflags@|am|' \
98     -e 's|@log_wflags@|_|' \
99     < wrapper.skel > bin/noext-wrapper
100
101 # 'test-wrapper' is deliberately not made executable.
102 chmod a+x chk-wrapper bin/noext-wrapper
103
104 # Not needed anymore.
105 rm -f wrapper.skel
106
107 cat > 1.chk << 'END'
108 #! /bin/sh
109 exit 0
110 END
111 chmod a+x 1.chk
112 cp 1.chk 2.test
113 cp 1.chk 3
114 cp 1.chk 4.c.chk
115 cp 1.chk 5.suf
116 cp 1.chk sub/test
117
118 $ACLOCAL
119 $AUTOCONF
120 $AUTOMAKE
121
122 ./configure
123 $MAKE
124 VERBOSE=yes $MAKE check
125 ls -l . sub
126
127 test ! -e BAD.log
128 test ! -e BAD.trs
129
130 echo 'chk-wrapper 1.chk --am-chk --chk' > 1.exp
131 echo 'test-wrapper 2.test -am-test -test' > 2.exp
132 echo 'noext-wrapper 3 am _' > 3.exp
133 echo 'chk-wrapper 4.c.chk --am-chk --chk' > 4.c.exp
134 echo 'noext-wrapper 5.suf am _' > 5.suf.exp
135 echo 'noext-wrapper sub/test am _' > sub/test.exp
136
137 st=0
138 for x in 1 2 3 4.c 5.suf sub/test; do
139   cat $x.log
140   diff $x.exp $x.log || st=1
141 done
142
143 exit $st