tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / tap-more.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 # More on TAP support:
18 #  - more than one TAP-generating test script in $(TESTS)
19 #  - VPATH builds
20 #  - use with parallel make (if supported)
21 #  - basic use of diagnostic messages (lines beginning with "#")
22 #  - flags for TAP driver defined through AC_SUBST in configure.ac
23 #  - messages generated by the testsuite harness reference the
24 #    correct test script(s)
25 #  - "make distcheck" works
26
27 . test-init.sh
28
29 fetch_tap_driver
30
31 cat >> configure.ac <<END
32 AC_SUBST([AM_TEST_LOG_DRIVER_FLAGS], ['--comments'])
33 AC_OUTPUT
34 END
35
36 cat > Makefile.am << 'END'
37 TEST_LOG_DRIVER = $(srcdir)/tap-driver
38 TESTS = 1.test 2.test 3.test
39 EXTRA_DIST = $(TESTS) tap-driver
40 END
41
42 cat > 1.test <<'END'
43 #! /bin/sh
44 echo 1..2
45 echo ok 1 - mu
46 if test -f not-skip; then
47   echo "not ok 2 zardoz"
48 else
49   echo "ok 2 zardoz # SKIP"
50 fi
51 END
52
53 cat > 2.test <<'END'
54 #! /bin/sh
55 echo 1..3
56 echo "ok"
57 echo "not ok # TODO not implemented"
58 echo "ok 3"
59 END
60
61 cat > 3.test <<END
62 #! /bin/sh
63 echo 1..1
64 echo ok - blah blah blah
65 echo '# Some diagnostic'
66 if test -f bail-out; then
67   echo 'Bail out! Kernel Panic'
68 else
69   :
70 fi
71 END
72
73 chmod a+x [123].test
74
75 $ACLOCAL
76 $AUTOCONF
77 $AUTOMAKE
78
79 # Try a VPATH and by default serial build first, and then an in-tree
80 # and by default parallel build.
81 for try in 0 1; do
82
83   if test $try -eq 0; then
84     # VPATH serial build.
85     mkdir build
86     cd build
87     srcdir=..
88     am_make=$MAKE
89   elif test $try -eq 1; then
90     # In-tree parallel build.
91     srcdir=.
92     case $MAKE in
93       *\ -j*)
94         # Degree of parallelism already specified by the user: do
95         # not override it.
96         :
97         ;;
98       *)
99         # Some make implementations (e.g., HP-UX) don't grok '-j',
100         # some require no space between '-j' and the number of jobs
101         # (e.g., older GNU make versions), and some *do* require a
102         # space between '-j' and the number of jobs (e.g., Solaris
103         # dmake).  We need a runtime test to see what works.
104         echo 'all:' > Makefile
105         for am_make in "$MAKE -j3" "$MAKE -j 3" "$MAKE"; do
106           $am_make && break
107         done
108         rm -f Makefile
109         MAKE=$am_make
110         unset am_make
111         ;;
112     esac
113   else
114     fatal_ "internal error, invalid value of '$try' for \$try"
115   fi
116
117   $srcdir/configure
118   ls -l # For debugging.
119
120   # Success.
121
122   run_make -O check
123   count_test_results total=6 pass=4 fail=0 xpass=0 xfail=1 skip=1 error=0
124   grep '^PASS: 1\.test 1 - mu$' stdout
125   grep '^SKIP: 1\.test 2 zardoz # SKIP$' stdout
126   test $(grep -c '1\.test' stdout) -eq 2
127   grep '^PASS: 2\.test 1$' stdout
128   grep '^XFAIL: 2\.test 2 # TODO not implemented$' stdout
129   grep '^PASS: 2\.test 3$' stdout
130   test $(grep -c '2\.test' stdout) -eq 3
131   grep '^PASS: 3\.test 1 - blah blah blah$' stdout
132   grep '^# 3\.test: Some diagnostic$' stdout
133   test $(grep -c '3\.test' stdout) -eq 2
134
135   # Failure.
136
137   : > not-skip
138   : > bail-out
139   run_make -e FAIL -O check
140   count_test_results total=7 pass=4 fail=1 xpass=0 xfail=1 skip=0 error=1
141   grep '^PASS: 1\.test 1 - mu$' stdout
142   grep '^FAIL: 1\.test 2 zardoz$' stdout
143   test $(grep -c '1\.test' stdout) -eq 2
144   grep '^PASS: 2\.test 1$' stdout
145   grep '^XFAIL: 2\.test 2 # TODO not implemented$' stdout
146   grep '^PASS: 2\.test 3$' stdout
147   test $(grep -c '2\.test' stdout) -eq 3
148   grep '^PASS: 3\.test 1 - blah blah blah$' stdout
149   grep '^# 3\.test: Some diagnostic$' stdout
150   grep '^ERROR: 3\.test - Bail out! Kernel Panic$' stdout
151   test $(grep -c '3\.test' stdout) -eq 3
152
153   cd $srcdir
154
155 done
156
157 $MAKE distcheck
158
159 :