am-ft: make the environment available earlier
[platform/upstream/automake.git] / t / tap-bad-prog.tap
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 # TAP support:
18 #  - missing, unreadable, or not-executable test scripts cause proper
19 #    error reports
20
21 . test-init.sh
22
23 fetch_tap_driver
24
25 plan_ 6
26
27 cat >> configure.ac <<END
28 AC_OUTPUT
29 END
30
31 cat > Makefile.am << 'END'
32 TEST_LOG_DRIVER = $(srcdir)/tap-driver
33 TESTS = none.test noread.test noexec.test
34 none.test:
35 END
36
37 cat > noexec.test <<'END'
38 #!/bin/sh
39 echo 1..1
40 echo ok 1
41 END
42
43 cp noexec.test noread.test
44 chmod a-r noread.test
45
46 $ACLOCAL
47 $AUTOCONF
48 $AUTOMAKE
49
50 ./configure
51
52 command_ok_ '"make check" returns non-zero exit status' \
53             run_make -O -e FAIL check
54
55 # FIXME: maybe grep for stricter error messages in the next checks?
56
57 command_ok_ "non-existent test is reported" \
58             grep '^ERROR: none\.test' stdout
59
60 desc="non-executable test is reported"
61 # Redirect output to avoid confusing automake's testsuite own TAP driver.
62 if ./noexec.test >/dev/null; then
63   skip_ -r "any file is executable" "$desc"
64 else
65   command_ok_ "$desc" -- grep '^ERROR: noexec\.test' stdout
66 fi
67
68 desc="non-readable test is reported"
69 if test -r noread.test; then
70   skip_ -r "any file is readable" "$desc"
71 else
72   command_ok_ "$desc" -- grep '^ERROR: noread\.test' stdout
73 fi
74
75 # Check that no spurious test result is reported.  This is lower-priority
76 # (and in fact the check currently fails for our awk-based driver).
77 directive=
78 if test $am_tap_implementation = shell; then
79   directive=TODO
80 else
81   # Older versions of IPC::Open3 (e.g., version 1.05 on perl 5.12.4 or
82   # version 1.0103 on perl 5.6.2) fail to properly trap errors in exec(2)
83   # calls in the child process; hence, the TAP driver cannot be properly
84   # informed of such error.
85   if $PERL -w -e '
86     use IPC::Open3 qw/open3/;
87     $@ = "";
88     eval { open3(*STDIN, *STDOUT, *STDERR, "am--no-such-command") };
89     $@ =~ m/\bopen3:.*am--no-such-command/
90       or die "Bad \$@ value: \"$@\"\n";
91   '; then
92     : # OK. IPC::Open3 should be good enough.
93   else
94     for s in '"missing plan" message' 'results'; do
95       skip_ -r "IPC::Open3 not good enough" "no spurious $s"
96     done
97     exit 0
98   fi
99 fi
100
101 command_ok_ 'no spurious "missing plan" message' \
102     -D "$directive" -- not grep 'missing.* plan' stdout
103 command_ok_ 'no spurious results' \
104   -D "$directive" -r 'still get "missing plan"' \
105   count_test_results total=3 pass=0 fail=0 xpass=0 xfail=0 skip=0 error=3
106
107 :