maint: run "make update-copyright"
[platform/upstream/automake.git] / tests / tap-realtime.test
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 # TAP support:
18 #  - testsuite progress on console should happen mostly "in real time";
19 #    i.e., it's not acceptable for the driver to wait the end of the
20 #    script to start displaying results from it.
21 # FIXME: this test uses expect(1) to ensure line buffering from make and
22 # children, and is pretty hacky and complex; is there a better way to
23 # accomplish the checks done here?
24
25 am_parallel_tests=yes
26 . ./defs || Exit 1
27
28 cat >expect-check <<'END'
29 eval spawn $env(SHELL) -c ":"
30 expect eof
31 END
32 expect -f expect-check || {
33     echo "$me: failed to find a working expect program" >&2
34     Exit 77
35 }
36 rm -f expect-check
37
38 # Unfortunately, some make implementations (among them, FreeBSD make,
39 # NetBSD make, and Solaris Distributed make), when run in parallel mode,
40 # serialize the output from their targets' recipes unconditionally.  In
41 # such a situation, there's no way the partial results of a TAP test can
42 # be displayed until the test has terminated.  And this is not something
43 # our TAP driver script can work around; in fact, the driver *is* sending
44 # out its output progressively and "in sync" with test execution -- it is
45 # make that is stowing such output away instead of presenting it to the
46 # user as soon as it gets it.
47 if using_gmake; then :; else
48   case $MAKE in
49     *\ -j*) skip_ "doesn't with non-GNU concurrent make";;
50   esac
51   # Prevent Sun Distributed Make from trying to run in parallel.
52   DMAKE_MODE=serial; export DMAKE_MODE
53 fi
54
55 cat > Makefile.am << 'END'
56 TESTS = all.test
57 END
58 . "$testsrcdir"/tap-setup.sh || fatal_ "sourcing tap-setup.sh"
59
60 cat > all.test <<'END'
61 #! /bin/sh
62 echo 1..3
63
64 # Creative quoting to placate maintainer-check.
65 sleep="sleep "3
66
67 # The awk+shell implementation of the TAP driver must "read ahead" of one
68 # line in order to catch the exit status of the test script it runs.  So
69 # be sure to echo one "dummy" line after each result line in order not to
70 # cause false positives.
71
72 echo ok 1 - foo
73 echo DUMMY
74 $sleep
75 test -f ok-1 || { echo 'Bail out!'; exit 1; }
76
77 echo ok 2 - bar
78 echo DUMMY
79 $sleep
80 test -f ok-2 || { echo 'Bail out!'; exit 1; }
81
82 echo ok 3 - baz
83 echo DUMMY
84 $sleep
85 test -f ok-3 || { echo 'Bail out!'; exit 1; }
86
87 : > all-is-well
88 END
89
90 chmod a+x all.test
91
92 cat > expect-make <<'END'
93 eval spawn $env(MAKE) check
94 expect {
95   "PASS: all.test 1 - foo" {
96     open "ok-1" "w"
97     exp_continue
98   }
99   "PASS: all.test 2 - bar" {
100     open "ok-2" "w"
101     exp_continue
102   }
103   "PASS: all.test 3 - baz" {
104     open "ok-3" "w"
105     exp_continue
106   }
107   "Testsuite summary" {
108     exit 0
109   }
110   timeout {
111     puts "expect timed out"
112     exit 1
113   }
114   default {
115     puts "expect error"
116     exit 1
117   }
118 }
119 END
120
121 # Expect should simulate a tty as stdout, which should ensure a
122 # line-buffered output.
123 MAKE=$MAKE expect -f expect-make
124 test -f all-is-well
125
126 :