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