tests: rename 'tests/' => 't/', '*.test' => '*.sh'
[platform/upstream/automake.git] / t / tap-doc2.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 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 # Check that an example given in the documentation really works.
18 # See section "Using the TAP test protocol", subsection "Use TAP
19 # with the Automake test harness".
20
21 am_create_testdir=empty
22 am_parallel_tests=yes
23 . ./defs || Exit 1
24
25 cat > Makefile.am <<'END'
26 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
27                   $(top_srcdir)/build-aux/tap-driver.sh
28 TESTS = foo.test bar.test baz.test
29 EXTRA_DIST = $(TESTS)
30 END
31
32 cat > configure.ac <<'END'
33 AC_INIT([GNU Try Tap], [1.0], [bug-automake@gnu.org])
34 AC_CONFIG_AUX_DIR([build-aux])
35 AM_INIT_AUTOMAKE([foreign parallel-tests -Wall -Werror])
36 AC_CONFIG_FILES([Makefile])
37 AC_REQUIRE_AUX_FILE([tap-driver.sh])
38 AC_PROG_AWK
39 AC_OUTPUT
40 END
41
42 cat > foo.test <<'END'
43 #!/bin/sh
44 echo 1..4 # Number of tests to be executed.
45 echo 'ok 1 - Swallows fly'
46 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
47 echo 'ok 3 - Pigs fly # SKIP not enough acid'
48 echo '# I just love word plays...'
49 echo 'ok 4 - Flies fly too :-)'
50 END
51
52 cat > bar.test <<'END'
53 #!/bin/sh
54 echo 1..3
55 echo 'not ok 1 - Bummer, this test has failed.'
56 echo 'ok 2 - This passed though.'
57 echo 'Bail out! Ennui kicking in, sorry...'
58 echo 'ok 3 - This will not be seen.'
59 END
60
61 cat > baz.test <<'END'
62 #!/bin/sh
63 echo 1..1
64 echo ok 1
65 # Exit with error, even if all the tests have been successful.
66 exit 7
67 END
68
69 chmod a+x *.test
70
71 # Strip extra "informative" lines that could be printed by Solaris
72 # Distributed Make.
73 mkdir build-aux
74 cp "$am_scriptdir"/tap-driver.sh build-aux \
75   || framework_failure_ "fetching the perl TAP driver"
76
77 (export AUTOMAKE ACLOCAL AUTOCONF && $AUTORECONF -vi) || Exit 1
78
79 ./configure --help # Sanity check.
80 ./configure || skip_ "configure failed"
81
82 case $MAKE in *\ -j*) skip_ "can't work easily with concurrent make";; esac
83
84 # Prevent Sun Distributed Make from trying to run in parallel.
85 DMAKE_MODE=serial; export DMAKE_MODE
86
87 $MAKE check >stdout && { cat stdout; Exit 1; }
88 cat stdout
89
90 cat > exp <<'END'
91 PASS: foo.test 1 - Swallows fly
92 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
93 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
94 PASS: foo.test 4 - Flies fly too :-)
95 FAIL: bar.test 1 - Bummer, this test has failed.
96 PASS: bar.test 2 - This passed though.
97 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
98 PASS: baz.test 1
99 ERROR: baz.test - exited with status 7
100 END
101
102 sed -n '/^PASS: foo\.test/,/^ERROR: baz\.test/p' stdout > got
103
104 cat exp
105 cat got
106 diff exp got
107
108 grep '^Please report to bug-automake@gnu\.org$' stdout
109
110 env \
111   TESTS='foo.test baz.test' \
112   TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
113   $MAKE -e check >stdout || { cat stdout; Exit 1; }
114
115 cat > exp <<'END'
116 PASS: foo.test 1 - Swallows fly
117 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
118 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
119 # foo.test: I just love word plays...
120 PASS: foo.test 4 - Flies fly too :-)
121 PASS: baz.test 1
122 END
123
124 sed -n '/^PASS: foo\.test/,/^PASS: baz\.test/p' stdout > got
125
126 cat exp
127 cat got
128 diff exp got
129
130 # Sanity check the distribution.
131 cat > bar.test <<'END'
132 #!/bin/sh
133 echo 1..1
134 echo ok 1
135 END
136 echo AM_TEST_LOG_DRIVER_FLAGS = --ignore-exit >> Makefile.in
137 ./config.status Makefile
138 $MAKE distcheck
139
140 :