Merge branch 'maint'
[platform/upstream/automake.git] / t / check12.sh
1 #! /bin/sh
2 # Copyright (C) 2010-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 # Test to make sure dejagnu tests, automake-style tests, and check-local
18 # target can coexist.
19
20 required=runtest
21 . ./defs || Exit 1
22
23 cat >> configure.ac << 'END'
24 AC_OUTPUT
25 END
26
27 cat > Makefile.am << 'END'
28 AUTOMAKE_OPTIONS =
29 EXTRA_DIST =
30 CLEANFILES =
31 END
32
33 ## Simple tests.
34
35 cat > a.test << 'END'
36 #!/bin/sh
37 echo a.test: exit status: ${A_EXIT_STATUS-0}
38 exit ${A_EXIT_STATUS-0}
39 END
40 cat > b.test << 'END'
41 #!/bin/sh
42 echo b.test: exit status: ${B_EXIT_STATUS-0}
43 exit ${B_EXIT_STATUS-0}
44 END
45 chmod +x a.test b.test
46
47 cat >> Makefile.am << 'END'
48 TESTS = a.test b.test
49 EXTRA_DIST += $(TESTS)
50 END
51
52 A_EXIT_STATUS=0; export A_EXIT_STATUS
53 B_EXIT_STATUS=0; export B_EXIT_STATUS
54
55 ## DejaGnu tests.
56
57 cat >> Makefile.am << 'END'
58 AUTOMAKE_OPTIONS += dejagnu
59 DEJATOOL = hammer spanner
60 AM_RUNTESTFLAGS = HAMMER=$(srcdir)/hammer SPANNER=$(srcdir)/spanner
61 EXTRA_DIST += hammer.test/hammer.exp
62 EXTRA_DIST += spanner.test/spanner.exp
63 END
64
65 cat > hammer << 'END'
66 #! /bin/sh
67 echo "Everything looks like a ${NAIL-nail} to me!"
68 END
69
70 NAIL=nail; export NAIL
71
72 cat > spanner << 'END'
73 #! /bin/sh
74 echo "I'm a right spanner!"
75 END
76 chmod +x hammer spanner
77
78 mkdir hammer.test spanner.test
79
80 cat > hammer.test/hammer.exp << 'END'
81 set test test_hammer
82 spawn $HAMMER
83 expect {
84     "Everything looks like a nail to me!" { pass "$test" }
85     default { fail "$test" }
86 }
87 END
88
89 cat > spanner.test/spanner.exp << 'END'
90 set test test_spanner
91 spawn $SPANNER
92 expect {
93     "I'm a right spanner!" { pass "$test" }
94     default { fail "$test" }
95 }
96 END
97
98 ## User-defined extra tests.
99
100 cat >> Makefile.am <<'END'
101 check-local:
102         case $$CHECKLOCAL_EXIT_STATUS in \
103           0) echo 'check-local succeeded :-)';; \
104           *) echo 'check-local failed :-(';; \
105         esac >local.log
106         exit $$CHECKLOCAL_EXIT_STATUS
107 CLEANFILES += local.log
108 END
109 CHECKLOCAL_EXIT_STATUS=0; export CHECKLOCAL_EXIT_STATUS
110
111 ## Go with the testcase execution.
112
113 $ACLOCAL
114 $AUTOCONF
115 $AUTOMAKE --add-missing
116
117 for vpath in : false; do
118
119   if $vpath; then
120     srcdir=..
121     mkdir build_
122     cd build_
123   else
124     srcdir=.
125   fi
126
127   if test -f config.status; then
128     $MAKE distclean
129   fi
130
131   $srcdir/configure
132
133   $MAKE check
134   test -f hammer.log
135   test -f hammer.sum
136   test -f spanner.log
137   test -f spanner.sum
138   # This checks will be run only by the autogenerated 'check12-p.test'.
139   if test x"$am_parallel_tests" = x"yes"; then
140     test -f test-suite.log
141     test -f a.log
142     test -f b.log
143   else :; fi
144   grep 'check-local succeeded :-)' local.log
145
146   cp -f config.status config-status.sav
147
148   $MAKE distclean
149   test ! -r hammer.log
150   test ! -r hammer.sum
151   test ! -r spanner.log
152   test ! -r spanner.sum
153   test ! -r test-suite.log
154   test ! -r a.log
155   test ! -r b.log
156   test ! -r local.log
157
158   mv -f config-status.sav config.status
159   ./config.status
160
161   NAIL=screw $MAKE check && Exit 1
162   test -f hammer.log
163   test -f hammer.sum
164   test -f spanner.log
165   test -f spanner.sum
166   grep 'FAIL: test_hammer' hammer.sum
167   grep 'FAIL:' spanner.sum && Exit 1
168
169   B_EXIT_STATUS=1 $MAKE check && Exit 1
170   # This checks will be run only by the autogenerated 'check12-p.test'.
171   if test x"$am_parallel_tests" = x"yes"; then
172     cat test-suite.log
173     cat a.log
174     cat b.log
175     grep '^a\.test: exit status: 0$' a.log
176     grep '^b\.test: exit status: 1$' b.log
177     grep '^FAIL: b$' test-suite.log
178     grep '^b\.test: exit status: 1$' test-suite.log
179     grep '^a\.test' test-suite.log && Exit 1
180     : For shells with busted 'set -e'.
181   else :; fi
182
183   CHECKLOCAL_EXIT_STATUS=1 $MAKE check && Exit 1
184   grep 'check-local failed :-(' local.log
185
186   # Do not trust the exit status of 'make -k'.
187   NAIL=screw B_EXIT_STATUS=23 CHECKLOCAL_EXIT_STATUS=1 $MAKE -k check || :
188   test -f hammer.log
189   test -f hammer.sum
190   test -f spanner.log
191   test -f spanner.sum
192   grep 'FAIL: test_hammer' hammer.sum
193   grep 'FAIL:' spanner.sum && Exit 1
194   # This checks will be run only by the autogenerated 'check12-p.test'.
195   if test x"$am_parallel_tests" = x"yes"; then
196     cat test-suite.log
197     cat a.log
198     cat b.log
199     grep '^a\.test: exit status: 0$' a.log
200     grep '^b\.test: exit status: 23$' b.log
201     grep '^FAIL: b$' test-suite.log
202     grep '^b\.test: exit status: 23$' test-suite.log
203     grep '^a\.test' test-suite.log && Exit 1
204     : For shells with busted 'set -e'.
205   else :; fi
206   grep 'check-local failed :-(' local.log
207
208   cd $srcdir
209
210 done
211
212 $MAKE distcheck
213
214 :