summaryrefslogtreecommitdiff
path: root/t/check12.sh
blob: a21c6daffa1c79def269158374fca9b16dc6c3d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#! /bin/sh
# Copyright (C) 2010-2012 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Test to make sure dejagnu tests, automake-style tests, and check-local
# target can coexist.

required=runtest
. ./defs || Exit 1

cat >> configure.ac << 'END'
AC_OUTPUT
END

cat > Makefile.am << 'END'
AUTOMAKE_OPTIONS =
EXTRA_DIST =
CLEANFILES =
END

## Simple tests.

cat > a.test << 'END'
#!/bin/sh
echo a.test: exit status: ${A_EXIT_STATUS-0}
exit ${A_EXIT_STATUS-0}
END
cat > b.test << 'END'
#!/bin/sh
echo b.test: exit status: ${B_EXIT_STATUS-0}
exit ${B_EXIT_STATUS-0}
END
chmod +x a.test b.test

cat >> Makefile.am << 'END'
TESTS = a.test b.test
EXTRA_DIST += $(TESTS)
END

A_EXIT_STATUS=0; export A_EXIT_STATUS
B_EXIT_STATUS=0; export B_EXIT_STATUS

## DejaGnu tests.

cat >> Makefile.am << 'END'
AUTOMAKE_OPTIONS += dejagnu
DEJATOOL = hammer spanner
AM_RUNTESTFLAGS = HAMMER=$(srcdir)/hammer SPANNER=$(srcdir)/spanner
EXTRA_DIST += hammer.test/hammer.exp
EXTRA_DIST += spanner.test/spanner.exp
END

cat > hammer << 'END'
#! /bin/sh
echo "Everything looks like a ${NAIL-nail} to me!"
END

NAIL=nail; export NAIL

cat > spanner << 'END'
#! /bin/sh
echo "I'm a right spanner!"
END
chmod +x hammer spanner

mkdir hammer.test spanner.test

cat > hammer.test/hammer.exp << 'END'
set test test_hammer
spawn $HAMMER
expect {
    "Everything looks like a nail to me!" { pass "$test" }
    default { fail "$test" }
}
END

cat > spanner.test/spanner.exp << 'END'
set test test_spanner
spawn $SPANNER
expect {
    "I'm a right spanner!" { pass "$test" }
    default { fail "$test" }
}
END

## User-defined extra tests.

cat >> Makefile.am <<'END'
check-local:
	case $$CHECKLOCAL_EXIT_STATUS in \
	  0) echo 'check-local succeeded :-)';; \
	  *) echo 'check-local failed :-(';; \
	esac >local.log
	exit $$CHECKLOCAL_EXIT_STATUS
CLEANFILES += local.log
END
CHECKLOCAL_EXIT_STATUS=0; export CHECKLOCAL_EXIT_STATUS

## Go with the testcase execution.

$ACLOCAL
$AUTOCONF
$AUTOMAKE --add-missing

for vpath in : false; do

  if $vpath; then
    srcdir=..
    mkdir build_
    cd build_
  else
    srcdir=.
  fi

  if test -f config.status; then
    $MAKE distclean
  fi

  $srcdir/configure

  $MAKE check
  test -f hammer.log
  test -f hammer.sum
  test -f spanner.log
  test -f spanner.sum
  # This checks will be run only by the autogenerated 'check12-p.test'.
  if test x"$am_parallel_tests" = x"yes"; then
    test -f test-suite.log
    test -f a.log
    test -f b.log
  else :; fi
  grep 'check-local succeeded :-)' local.log

  cp -f config.status config-status.sav

  $MAKE distclean
  test ! -r hammer.log
  test ! -r hammer.sum
  test ! -r spanner.log
  test ! -r spanner.sum
  test ! -r test-suite.log
  test ! -r a.log
  test ! -r b.log
  test ! -r local.log

  mv -f config-status.sav config.status
  ./config.status

  NAIL=screw $MAKE check && Exit 1
  test -f hammer.log
  test -f hammer.sum
  test -f spanner.log
  test -f spanner.sum
  grep 'FAIL: test_hammer' hammer.sum
  grep 'FAIL:' spanner.sum && Exit 1

  B_EXIT_STATUS=1 $MAKE check && Exit 1
  # This checks will be run only by the autogenerated 'check12-p.test'.
  if test x"$am_parallel_tests" = x"yes"; then
    cat test-suite.log
    cat a.log
    cat b.log
    grep '^a\.test: exit status: 0$' a.log
    grep '^b\.test: exit status: 1$' b.log
    grep '^FAIL: b$' test-suite.log
    grep '^b\.test: exit status: 1$' test-suite.log
    grep '^a\.test' test-suite.log && Exit 1
    : For shells with busted 'set -e'.
  else :; fi

  CHECKLOCAL_EXIT_STATUS=1 $MAKE check && Exit 1
  grep 'check-local failed :-(' local.log

  # Do not trust the exit status of 'make -k'.
  NAIL=screw B_EXIT_STATUS=23 CHECKLOCAL_EXIT_STATUS=1 $MAKE -k check || :
  test -f hammer.log
  test -f hammer.sum
  test -f spanner.log
  test -f spanner.sum
  grep 'FAIL: test_hammer' hammer.sum
  grep 'FAIL:' spanner.sum && Exit 1
  # This checks will be run only by the autogenerated 'check12-p.test'.
  if test x"$am_parallel_tests" = x"yes"; then
    cat test-suite.log
    cat a.log
    cat b.log
    grep '^a\.test: exit status: 0$' a.log
    grep '^b\.test: exit status: 23$' b.log
    grep '^FAIL: b$' test-suite.log
    grep '^b\.test: exit status: 23$' test-suite.log
    grep '^a\.test' test-suite.log && Exit 1
    : For shells with busted 'set -e'.
  else :; fi
  grep 'check-local failed :-(' local.log

  cd $srcdir

done

$MAKE distcheck

: