1 # fail.at -- test that libtool really fail when it should -*- Autotest -*-
3 # Copyright (C) 2005, 2008-2009, 2011-2019, 2021-2024 Free Software
5 # Written by Ralf Wildenhues, 2005
7 # This file is part of GNU Libtool.
9 # GNU Libtool is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # GNU Libtool is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU Libtool; see the file COPYING. If not, a copy
21 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
22 # or obtained by writing to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 # TODO: many possible failure cases missing. (But how to simulate a full disk?)
28 AT_SETUP([Failure tests])
29 AT_KEYWORDS([libtool])
30 eval `$LIBTOOL --config | $EGREP '^(pic_mode|pic_flag|build_old_libs|build_libtool_libs)='`
31 LDFLAGS="$LDFLAGS -no-undefined"
33 m4_pushdef([FAIL_CHECK],
34 [AT_CHECK([if $1; then (exit 1); else :; fi], [0], [ignore], [ignore])
42 if test -x script >/dev/null 2>&1; then
50 FAIL_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c])
51 AT_CHECK([test -f a.lo], [1])
53 # non-PIC compile failure
54 case $pic_mode in default | no)
58 case $build_old_libs,$pic_flag in yes,*-DPIC*)
64 FAIL_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -no-suppress -c a.c])
65 AT_CHECK([test -f a.lo], [1])
73 # program creation failure.
74 # We can't rely on 'main' not being present: the QNX linker
75 # won't error out in that case, although the resulting binary won't work.
76 # So we provoke a link failure due to an unresolved symbol, and require
77 # libtool to fail only if the link without libtool would have failed, too.
79 extern int nonexistent_function (void);
82 return nonexistent_function ();
85 $CC $CPPFLAGS $CFLAGS -c a.c
86 if $CC $CFLAGS $LDFLAGS -o a$EXEEXT a.$OBJEXT; then :; else
88 FAIL_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o a$EXEEXT a.$OBJEXT])
89 AT_CHECK([{ test -f a && $test_x a; } || { test -f a$EXEEXT && $test_x a$EXEEXT; }], [1])
90 FAIL_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o a$EXEEXT a.$OBJEXT -static])
91 AT_CHECK([{ test -f a && $test_x a; } || { test -f a$EXEEXT && $test_x a$EXEEXT; }], [1])
94 # shared library creation failure
95 case $build_libtool_libs in yes)
96 echo 'int duplicate_name(void) { return 0; }' > a.c
97 echo 'double duplicate_name(double x) { return 2.*x; }' > b.c
98 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c
99 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c b.c
100 # Unfortunately, this may actually succeed on AIX and IRIX :(
101 # So, also add a bogus object file to provoke more failure.
102 echo 'int whatever(void) { return 0;}' > c.c
103 $LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c c.c
106 test none = "$pic_object" || echo choke me >"$pic_object"
107 test none = "$non_pic_object" || echo choke me >"$non_pic_object"
109 FAIL_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la a.lo b.lo c.lo -rpath /foo])
110 AT_CHECK([test -f liba.la], [1])
114 # Ensure we diagnose '-L path'.
115 echo 'int main () { return 0; }' > d.c
116 echo 'int foo () { return 0; }' > space-after-L.c
117 $CC $CPPFLAGS $CFLAGS -c d.c
118 $CC $CPPFLAGS $CFLAGS -c space-after-L.c
119 FAIL_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -L space-after-L.$OBJEXT -o d$EXEEXT d.$OBJEXT])
120 FAIL_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o d$EXEEXT d.$OBJEXT -L])
122 m4_popdef([FAIL_CHECK])