tests: prune some weed in a non-POSIX test
[platform/upstream/automake.git] / t / parallel-tests-extra-programs.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 # Parallel test harness: check that $(TESTS) can lazily depend on
18 # (or even be) $(EXTRA_PROGRAMS).
19
20 required='cc native'
21 . test-init.sh
22
23 cat >> configure.ac << 'END'
24 AC_PROG_CC
25 AC_OUTPUT
26 END
27
28 # Will be extended later.
29 cat > Makefile.am << 'END'
30 TEST_EXTENSIONS = .bin .test
31 EXTRA_PROGRAMS =
32 TESTS =
33 END
34
35 #
36 # Now try various kinds of test dependencies ...
37 #
38
39 # 1. A program that is also a test, and whose source files
40 #    already exist.
41
42 cat >> Makefile.am <<'END'
43 EXTRA_PROGRAMS += foo.bin
44 TESTS += foo.bin
45 foo_bin_SOURCES = foo.c
46 END
47
48 cat > foo.c <<'END'
49 #include <stdio.h>
50 int main (void)
51 {
52   printf ("foofoofoo\n");
53   return 0;
54 }
55 END
56
57 # 2. A program that is also a test, and whose source files
58 #    are buildable by make.
59 cat >> Makefile.am <<'END'
60 EXTRA_PROGRAMS += bar.bin
61 TESTS += bar.bin
62 bar_bin_SOURCES = bar.c
63 bar.c: foo.c
64         sed -e 's/foofoofoo/barbarbar/' foo.c > $@
65 END
66
67 # 3. A test script that already exists, whose execution depends
68 #    on a program whose source files already exist and which is
69 #    not itself a test.
70 cat >> Makefile.am <<'END'
71 EXTRA_PROGRAMS += y
72 TESTS += baz.test
73 baz.log: y$(EXEEXT)
74 END
75
76 cat > baz.test <<'END'
77 #!/bin/sh
78 $srcdir/y "$@" | sed 's/.*/&ep&ep&ep/'
79 END
80 chmod a+x baz.test
81
82 cat > y.c <<'END'
83 #include <stdio.h>
84 int main (void)
85 {
86   printf ("y\n");
87   return 0;
88 }
89 END
90
91 # 4. A program that is also a test, but whose source files
92 #    do not exit and are not buildable by make.
93
94 cat >> Makefile.am <<'END'
95 EXTRA_PROGRAMS += none.bin
96 TESTS += none.bin
97 none_bin_SOURCES = none.c
98 END
99
100 #
101 # Setup done, go with the tests.
102 #
103
104 $ACLOCAL
105 $AUTOCONF
106 $AUTOMAKE -a
107
108 ./configure
109
110 # What we check now:
111 #  1. even if we cannot build the 'none.bin' program, all the other
112 #     test programs should be built, and all the other tests should
113 #     be run;
114 #  2. still, since we cannot create the 'none.log' file, the
115 #    'test-suite.log' file shouldn't be created (as it depends
116 #     on *all* the test logs).
117
118 run_make -E -O -e IGNORE -- -k check
119 ls -l
120 if using_gmake; then
121   test $am_make_rc -gt 0 || exit 1
122 else
123   # Don't trust exit status of "make -k" for non-GNU make.
124   $MAKE check && exit 1
125   : For shells with busted 'set -e'.
126 fi
127
128 # Files that should have been created, with the expected content.
129 cat bar.c
130 grep foofoofoo foo.log
131 grep barbarbar bar.log
132 grep yepyepyep baz.log
133 # Files that shouldn't have been created.
134 test ! -e none.log
135 test ! -e test-suite.log
136 # Expected testsuite progress output.
137 grep '^PASS: baz\.test$' stdout
138 # Don't anchor the end of the next two patterns, to allow for non-empty
139 # $(EXEEXT).
140 grep '^PASS: foo\.bin' stdout
141 grep '^PASS: bar\.bin' stdout
142 # Expected error messages from make.  Some make implementations (e.g.,
143 # FreeBSD make) seem to print the error on stdout instead, so check for
144 # it there as well.
145 $EGREP 'none\.(bin|o|c)' stderr stdout
146
147 # What we check now:
148 #  1. if we make the last EXTRA_PROGRAM buildable, the failed tests
149 #     pass;
150 #  2. on a lazy re-run, the passed tests are not re-run, and
151 #  3. their log files are not updated or touched.
152
153 : > stamp
154 $sleep
155
156 echo 'int main (void) { return 0; }' > none.c
157
158 run_make -O -e IGNORE check RECHECK_LOGS=
159 ls -l # For debugging.
160 test $am_make_rc -eq 0 || exit 1
161
162 # For debugging.
163 stat stamp foo.log bar.log baz.log || :
164
165 # Files that shouldn't have been updated or otherwise touched.
166 is_newest stamp foo.log bar.log baz.log
167 # Files that should have been created now.
168 test -f none.log
169 test -f test-suite.log
170 # Tests that shouldn't have been re-run.
171 $EGREP '(foo|bar)\.bin|baz\.test$' stdout && exit 1
172 # Tests that should have been run.  Again, we don't anchor the end
173 # of the next pattern, to allow for non-empty $(EXEEXT).
174 grep '^PASS: none\.bin' stdout
175
176 :