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