test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / test-metadata-global-log.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 and parallel test harness: check the documented
18 # semantics for deciding when the content of a test log file should be
19 # copied in the global test-suite.log file.  Currently, this is done
20 # with the use of the reStructuredText field ':copy-in-global-log:' in
21 # the associated '.trs' files.
22
23 . test-init.sh
24
25 cat >> configure.ac << 'END'
26 AC_OUTPUT
27 END
28
29 cat > Makefile.am << 'END'
30 TEST_LOG_DRIVER = ./passthrough-driver
31 TEST_LOG_COMPILER = $(SHELL) -e
32 END
33
34 cat > passthrough-driver <<'END'
35 #!/bin/sh
36 set -e; set -u;
37 while test $# -gt 0; do
38   case $1 in
39     --log-file) log_file=$2; shift;;
40     --trs-file) trs_file=$2; shift;;
41     --test-name) test_name=$2; shift;;
42     --expect-failure|--color-tests|--enable-hard-errors) shift;;
43     --) shift; break;;
44      *) echo "$0: invalid option/argument: '$1'" >&2; exit 2;;
45   esac
46   shift
47 done
48 echo "$test_name: RUN"
49 "$@" >$log_file 2>&1 5>$trs_file
50 END
51 chmod a+x passthrough-driver
52
53 # The ':test-result:' and ':recheck:' fields and the first line of the
54 # log file should be be irrelevant for the decision of whether a test
55 # output is to be copied in the 'test-suite.log'.
56
57 cat > no-1.test <<END
58 echo :test-result: SKIP >&5
59 echo :copy-in-global-log: no >&5
60 echo :test-result: FAIL >&5
61 echo :test-result: XPASS >&5
62 echo not seen 1
63 END
64
65 # In the last line, with leading and trailing whitespace in the value.
66 cat > no-2.test <<END
67 echo ":test-result: FAIL" >&5
68 echo "not seen 2"
69 echo ":recheck: yes" >&5
70 echo ":copy-in-global-log:$tab $tab no   $tab" >&5
71 END
72
73 for RES in XPASS FAIL XFAIL SKIP ERROR UNKNOWN; do
74   unindent > $RES.test <<END
75     echo :test-result: $RES >&5
76     echo :copy-in-global-log: no >&5
77     echo not seen $RES
78 END
79 done
80
81 # In the first line, with no whitespace.
82 cat > no-3.test <<END
83 echo :copy-in-global-log:no >&5
84 echo ":test-result: FAIL" >&5
85 echo "not seen 3"
86 END
87
88 # Leading whitespace before the field.
89 cat > no-4.test <<END
90 echo ":test-result: FAIL" >&5
91 echo "  $tab $tab$tab   :copy-in-global-log: no" >&5
92 echo "not seen 4"
93 END
94
95 cat > yes-1.test <<END
96 echo :test-result: PASS >&5
97 echo :copy-in-global-log: yes >&5
98 echo seen yes 1
99 END
100
101 # A lacking ':copy-in-global-log:' implies that the content of
102 # the log file should be copied.
103 cat > yes-2.test <<END
104 echo :test-result: PASS >&5
105 echo seen yes 2
106 END
107
108 # Three corner cases.
109
110 cat > corn-1.test <<END
111 echo seen corn 1
112 echo ':copy-in-global-log:' >&5
113 END
114
115 cat > corn-2.test <<END
116 echo seen corn 2
117 echo '$tab $tab$tab' >&5
118 END
119
120 cat > corn-3.test <<'END'
121 echo seen corn 31
122 echo ':copy-in-global-log:#@%!' >&5
123 echo seen corn 32
124 END
125
126 echo TESTS = *.test >> Makefile.am
127
128 $ACLOCAL
129 $AUTOCONF
130 $AUTOMAKE
131
132 ./configure
133
134 # We don't care about the exit status of "make check" here, that
135 # should be checked in other tests.
136 $MAKE check || :
137 cat test-suite.log
138 grep '^seen yes 1$' test-suite.log
139 grep '^seen yes 2$' test-suite.log
140 grep '^seen corn 1$' test-suite.log
141 grep '^seen corn 2$' test-suite.log
142 grep '^seen corn 31$' test-suite.log
143 grep '^seen corn 32$' test-suite.log
144 $FGREP 'not seen' test-suite.log && exit 1
145
146 :