ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / fail.at
blob2972c74b6cccdc75ffde8c2079cdfeb5f33d8a3f
1 # fail.at -- test that libtool really fail when it should     -*- Autotest -*-
3 #   Copyright (C) 2005, 2008-2009, 2011-2019, 2021-2024 Free Software
4 #   Foundation, Inc.
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.
24 ####
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])
37 AT_DATA([script],
38 [[#! /bin/sh
39 exit 0
40 ]])
41 chmod +x script
42 if test -x script >/dev/null 2>&1; then
43   test_x="test -x"
44 else
45   test_x=:
48 # compile failure
49 echo 'choke me' > a.c
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)
55   case " $CFLAGS " in
56    *\ -prefer-pic\ *) ;;
57    *)
58     case $build_old_libs,$pic_flag in yes,*-DPIC*)
59       AT_DATA([a.c], [[
60 #ifndef PIC
61   choke me
62 #endif
63 ]])
64       FAIL_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -no-suppress -c a.c])
65       AT_CHECK([test -f a.lo], [1])
66       ;;
67     esac
68     ;;
69   esac
70   ;;
71 esac
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.
78 cat > a.c <<'EOF'
79 extern int nonexistent_function (void);
80 int main (void)
82   return nonexistent_function ();
84 EOF
85 $CC $CPPFLAGS $CFLAGS -c a.c
86 if $CC $CFLAGS $LDFLAGS -o a$EXEEXT a.$OBJEXT; then :; else
87   rm -f a a$EXEEXT
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
104   (
105     . ./c.lo
106     test none = "$pic_object"     || echo choke me >"$pic_object"
107     test none = "$non_pic_object" || echo choke me >"$non_pic_object"
108   )
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])
111   ;;
112 esac
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])
123 AT_CLEANUP