tests: remove recipes that run tests with 'prove'
[platform/upstream/automake.git] / tests / parallel-tests-fd-redirect-exeext.test
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 # parallel-tests support: redirection of file descriptors with
18 # AM_TESTS_FD_REDIRECT, for tests which are binary executables
19 # We use some tricks to ensure that all code paths in 'lib/am/check2.am'
20 # are covered, even on platforms where $(EXEEXT) would be naturally empty.
21 # See also the more generic test 'check-fd-redirect.test', and
22 # sister test 'parallel-tests-fd-redirect.test'.
23
24 required='cc native'
25 am_parallel_tests=yes
26 . ./defs || Exit 1
27
28 cat >> configure.ac << 'END'
29 AC_PROG_CC
30 # Calls like "write(9, ...)" are unlikely to work for MinGW-compiled
31 # programs.  We must skip this test if this is the case.
32 am__ok=no
33 AC_LINK_IFELSE(
34     [AC_LANG_PROGRAM([[#include <unistd.h>]],
35                      [[write (9, "foobar\n", 7); return 0;]])],
36     [AM_RUN_LOG([./conftest$EXEEXT 9>&1]) \
37 dnl Leading ":;" required to avoid having two nested subshells starting
38 dnl with '((' in the generated configure: that is unportable and could
39 dnl confuse some shells (e.g., NetBSD 5.1 /bin/ksh) into thinking we are
40 dnl trying to perform an arithmetic operation.
41        && AM_RUN_LOG([:; (./conftest$EXEEXT 9>&1) | grep "^foobar"]) \
42        && am__ok=yes])
43 test $am__ok = yes || AS_EXIT([63])
44 AM_CONDITIONAL([real_EXEEXT], [test -n "$EXEEXT"])
45 test -n "$EXEEXT" || EXEEXT=.bin
46 AC_OUTPUT
47 END
48
49 cat > Makefile.am << 'END'
50 AM_TESTS_FD_REDIRECT = 9>&1
51 TESTS = $(check_PROGRAMS)
52 check_PROGRAMS = baz qux.test
53 qux_test_SOURCES = zardoz.c
54
55 ## Sanity check.
56 if !real_EXEEXT
57 check-local:
58         test -f baz.bin
59         test -f qux.test.bin
60 endif
61 END
62
63 $ACLOCAL
64 $AUTOCONF
65 $AUTOMAKE -a
66
67 cat > baz.c <<'END'
68 #include <stdio.h>
69 #include <unistd.h>
70 int main (void)
71 {
72   ssize_t res = write (9, " bazbazbaz\n", 11);
73   if (res < 0)
74     perror("write failed");
75   return res != 11;
76 }
77 END
78
79 cat > zardoz.c <<'END'
80 #include <stdio.h>
81 #include <unistd.h>
82 int main (void)
83 {
84   ssize_t res = write (9, " quxquxqux\n", 11);
85   if (res < 0)
86     perror("write failed");
87   return res != 11;
88 }
89 END
90
91 st=0; ./configure || st=$?
92 cat config.log # For debugging, as we do tricky checks in configure.
93 if test $st -eq 63; then
94   skip_ "fd redirect in compiled program unsupported"
95 elif test $st -eq 0; then
96   : Continue.
97 else
98   fatal_ "unexpected error in ./configure"
99 fi
100
101 # Sanity checks.
102 st=0
103 grep '^baz\.log:.*baz\$(EXEEXT)' Makefile || st=1
104 grep '^\.test\$(EXEEXT)\.log:' Makefile || st=1
105 grep '^qux\.log:' Makefile && st=1
106 test $st -eq 0 || fatal_ "doesn't cover expected code paths"
107
108 st=0
109 $MAKE check >stdout || st=1
110 cat stdout
111 cat baz.log
112 cat qux.log
113 test $st -eq 0
114 grep "^ bazbazbaz$" stdout
115 grep "^ quxquxqux$" stdout
116 $EGREP '(bazbazbaz|quxquxqux)' *.log && Exit 1
117
118 :