Imported Upstream version 2.4.2
[platform/upstream/libtool.git] / tests / fail.at
1 # fail.at -- test that libtool really fail when it should     -*- Autotest -*-
2 #
3 #   Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
4 #   Written by Ralf Wildenhues, 2005
5 #
6 #   This file is part of GNU Libtool.
7 #
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.
12 #
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.
17 #
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.
23 ####
24
25 # TODO: many possible failure cases missing.  (But how to simulate a full disk?)
26
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"
31
32 m4_pushdef([FAIL_CHECK],
33 [AT_CHECK([if $1; then (exit 1); else :; fi], [0], [ignore], [ignore])
34 ])
35
36 AT_DATA([script],
37 [[#! /bin/sh
38 exit 0
39 ]])
40 chmod +x script
41 if test -x script >/dev/null 2>&1; then
42   test_x="test -x"
43 else
44   test_x=:
45 fi
46
47 # compile failure
48 echo 'choke me' > a.c
49 FAIL_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c a.c])
50 AT_CHECK([test -f a.lo], [1])
51
52 # non-PIC compile failure
53 case $pic_mode in default | no)
54   case " $CFLAGS " in
55    *\ -prefer-pic\ *) ;;
56    *)
57     case $build_old_libs,$pic_flag in yes,*-DPIC*)
58       AT_DATA([a.c], [[
59 #ifndef PIC
60   choke me
61 #endif
62 ]])
63       FAIL_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -no-suppress -c a.c])
64       AT_CHECK([test -f a.lo], [1])
65       ;;
66     esac
67     ;;
68   esac
69   ;;
70 esac
71
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.
77 cat > a.c <<'EOF'
78 extern int nonexistent_function (void);
79 int main (void)
80 {
81   return nonexistent_function ();
82 }
83 EOF
84 $CC $CPPFLAGS $CFLAGS -c a.c
85 if $CC $CFLAGS $LDFLAGS -o a$EXEEXT a.$OBJEXT; then :; else
86   rm -f a a$EXEEXT
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])
91 fi
92
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
103   (
104     . ./c.lo
105     test "$pic_object" != none && echo choke me >"$pic_object"
106     test "$non_pic_object" != none && echo choke me >"$non_pic_object"
107   )
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])
110   ;;
111 esac
112
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])
120
121 m4_popdef([FAIL_CHECK])
122 AT_CLEANUP