test: protect more yacc declarations against C vs. C++ linkage.
[automake.git] / t / parallel-tests-fd-redirect-exeext.sh
blobb4d1805814c8786de8e7911584ed1f4c98f3263b
1 #! /bin/sh
2 # Copyright (C) 2011-2024 Free Software Foundation, Inc.
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.
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.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
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.sh', and
22 # sister test 'parallel-tests-fd-redirect.sh'.
24 required='cc native'
25 . test-init.sh
27 cat >> configure.ac << 'END'
28 AC_PROG_CC
29 # Calls like "write(9, ...)" are unlikely to work for MinGW-compiled
30 # programs. We must skip this test if this is the case.
31 am__ok=no
32 AC_LINK_IFELSE(
33 [AC_LANG_PROGRAM([[#include <unistd.h>]],
34 [[write (9, "foobar\n", 7); return 0;]])],
35 [AM_RUN_LOG([./conftest$EXEEXT 9>&1]) \
36 dnl Leading ":;" required to avoid having two nested subshells starting
37 dnl with '((' in the generated configure: that is unportable and could
38 dnl confuse some shells (e.g., NetBSD 5.1 /bin/ksh) into thinking we are
39 dnl trying to perform an arithmetic operation.
40 && AM_RUN_LOG([:; (./conftest$EXEEXT 9>&1) | grep "^foobar"]) \
41 && am__ok=yes])
42 test $am__ok = yes || AS_EXIT([63])
43 AM_CONDITIONAL([real_EXEEXT], [test -n "$EXEEXT"])
44 test -n "$EXEEXT" || EXEEXT=.bin
45 AC_OUTPUT
46 END
48 cat > Makefile.am << 'END'
49 AM_TESTS_FD_REDIRECT = 9>&1
50 TESTS = $(check_PROGRAMS)
51 check_PROGRAMS = baz qux.test
52 qux_test_SOURCES = zardoz.c
54 ## Sanity check.
55 if !real_EXEEXT
56 check-local:
57 test -f baz.bin
58 test -f qux.test.bin
59 endif
60 END
62 $ACLOCAL
63 $AUTOCONF
64 $AUTOMAKE -a
66 cat > baz.c <<'END'
67 #include <stdio.h>
68 #include <unistd.h>
69 int main (void)
71 ssize_t res = write (9, " bazbazbaz\n", 11);
72 if (res < 0)
73 perror("write failed");
74 return res != 11;
76 END
78 cat > zardoz.c <<'END'
79 #include <stdio.h>
80 #include <unistd.h>
81 int main (void)
83 ssize_t res = write (9, " quxquxqux\n", 11);
84 if (res < 0)
85 perror("write failed");
86 return res != 11;
88 END
90 st=0; ./configure || st=$?
91 cat config.log # For debugging, as we do tricky checks in configure.
92 if test $st -eq 63; then
93 skip_ "fd redirect in compiled program unsupported"
94 elif test $st -eq 0; then
95 : Continue.
96 else
97 fatal_ "unexpected error in ./configure"
100 # Sanity checks.
101 st=0
102 grep '^baz\.log:.*baz\$(EXEEXT)' Makefile || st=1
103 grep '^\.test\$(EXEEXT)\.log:' Makefile || st=1
104 grep '^qux\.log:' Makefile && st=1
105 test $st -eq 0 || fatal_ "doesn't cover expected code paths"
107 run_make -O -e IGNORE check
108 cat baz.log
109 cat qux.log
110 test $am_make_rc -eq 0
111 grep "^ bazbazbaz$" stdout
112 grep "^ quxquxqux$" stdout
113 $EGREP '(bazbazbaz|quxquxqux)' *.log && exit 1