ltmain.in: Use func_warning for all warnings
[libtool.git] / tests / execute-mode.at
blob571b7974c9b69bdd14a9ce138b06e8b059c8bb19
1 # execute-mode.at -- libtool --mode=execute             -*- Autotest -*-
3 #   Copyright (C) 2008-2019, 2021-2024 Free Software Foundation, Inc.
4 #   Written by Ralf Wildenhues, 2008
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.
23 ####
25 AT_SETUP([execute mode])
26 AT_KEYWORDS([libtool])
28 eval `$LIBTOOL --config | $EGREP '^(FGREP)='`
30 AT_DATA([foo],
31 [[#! /bin/sh
32 if test $# -gt 0; then
33   for arg
34   do
35     printf %s\\n "$arg"
36   done
37 else
38   :
40 ]])
42 AT_DATA([lt-wrapper],
43 [[#! /bin/sh
44 # Generated by GNU libtool.
45 # fake wrapper script.
46 program=lt-real
47 progdir=.
48 if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
49   # Run the actual program with our arguments.
50   exec "$progdir/$program" ${1+"$@"}
51   echo "$0: cannot exec $program $*" >&2
52   exit 1
54 ]])
56 AT_DATA([lt-real],
57 [[#! /bin/sh
58 for arg
60   printf %s\\n "$arg"
61 done
62 cat
63 ]])
65 AT_DATA([libfakelib.la],
66 [[# libfakelib.la - a libtool library file
67 # Generated by ltmain.sh (GNU libtool 1.2605 2008/03/04 22:31:32) 2.3a
69 # Please DO NOT delete this file!
70 # It is necessary for linking the library.
72 dlname=''
73 library_names=''
74 old_library='libfakelib.a'
75 inherited_linker_flags=''
76 dependency_libs=''
77 weak_library_names=''
78 current=
79 age=
80 revision=
81 installed=no
82 shouldnotlink=yes
83 dlopen=''
84 dlpreopen=''
85 libdir=''
86 ]])
88 mkdir sub
89 cp foo sub/foo
90 chmod +x foo sub/foo lt-wrapper lt-real
92 AT_DATA([liba.c],
93 [[int a () { return 0; }
94 ]])
96 AT_DATA([main.c],
97 [[#include <stdio.h>
98 extern int a ();
99 int main (int argc, char **argv)
101   int i;
102   for (i=1; i<argc; ++i)
103     {
104       if (i != 1)
105         fputc ('\n', stdout);
106       fputs (argv[i], stdout);
107     }
108   fputc ('\n', stdout);
109   return a ();
113 LDFLAGS="$LDFLAGS -no-undefined"
114 instdir=`pwd`/inst
115 libdir=$instdir/lib
117 AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c liba.c],
118          [], [ignore], [ignore])
119 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o liba.la -rpath $libdir liba.lo],
120          [], [ignore], [ignore])
121 AT_CHECK([$CC $CPPFLAGS $CFLAGS -c main.c],
122          [], [ignore], [ignore])
123 AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o main$EXEEXT main.$OBJEXT liba.la],
124          [], [ignore], [ignore])
126 # end of preparatory blurb.
127 # Now, when doing the tests, we both try the fake wrappers plus the real one
128 # (only the latter exposes the C wrappers used for w32 systems).
129 # With the latter, however, we need to ignore additional output; esp. wine
130 # may be rather noisy.
132 AT_CHECK([$LIBTOOL --mode=execute ./foo])
133 AT_CHECK([$LIBTOOL --mode=execute sub/foo])
134 AT_CHECK([$LIBTOOL --mode=execute ./foo foo], [], [foo
136 AT_CHECK([$LIBTOOL --mode=execute ./lt-wrapper foo </dev/null], [], [foo
138 AT_CHECK([cd sub && $LIBTOOL --mode=execute ./foo ../foo], [], [../foo
140 # suppose that ./foo is gdb, and lt-wrapper is the wrapper script.
141 AT_CHECK([$LIBTOOL --mode=execute ./foo lt-wrapper bar baz </dev/null], [],
142          [./lt-real
147 # check that stdin works even with -dlopen.
148 AT_CHECK([echo bar | $LIBTOOL --mode=execute -dlopen libfakelib.la ./lt-wrapper foo],
149          [], [foo
153 # Check that a missing real program causes an error.
154 # The error message and code are likely to be 126,
155 # "No such file or directory" but system-dependent.
156 mv -f lt-real lt-backup
157 AT_CHECK([$LIBTOOL --mode=execute ./lt-wrapper foo </dev/null || exit 1],
158          [1], [ignore], [ignore])
159 mv -f lt-backup lt-real
161 # Now use arguments that require decent quoting.
162 AT_CHECK([$LIBTOOL --mode=execute ./foo "arg  with special chars: \$!&*'\`()"],
163          [], [arg  with special chars: $!&*'`()
165 AT_CHECK([$LIBTOOL --mode=execute ./lt-wrapper "arg  with special chars: \$!&*'\`()" </dev/null],
166          [], [arg  with special chars: $!&*'`()
168 AT_CHECK([$LIBTOOL --mode=execute ./foo lt-wrapper "arg  with special chars: \$!&*'\`()"],
169          [], [./lt-real
170 arg  with special chars: $!&*'`()
172 LT_AT_NOINST_EXEC_CHECK([./main], [], [], [stdout], [ignore],
173                         ["arg  with special chars: \$!&*'\`()"])
174 AT_CHECK([$FGREP 'arg  with special chars: $!&*'\''`()' stdout], [], [ignore])
176 # We always pair two args.  The first one is never the empty string.
177 arg1=
178 for arg2 in \
179    'def ghi' '' \
180    'd"e' 'f"g' \
181    'd\"e' 'f\"g' \
182    'd\\"e' 'f\\"g' \
183    'd\\\"e' 'f\\\"g' \
184    'd\' '' \
185    'd\\' '' \
186    'd\\\' '' \
187    'd\\\\' '' \
188    '<' '>' \
189    '<def>' ''
191   if test -z "$arg1"; then
192     arg1=$arg2; continue
193   fi
194   AT_CHECK([$LIBTOOL --mode=execute ./foo abc "$arg1" "$arg2" xyz], [], [stdout], [ignore])
195   AT_CHECK([$FGREP "$arg1" stdout], [], [ignore])
196   AT_CHECK([test -z "$arg2" || $FGREP "$arg2" stdout], [], [ignore])
197   AT_CHECK([test `$SED -n '/^abc$/,/^xyz$/p' stdout | wc -l` -eq 4])
198   AT_CHECK([$LIBTOOL --mode=execute ./lt-wrapper abc "$arg1" "$arg2" xyz </dev/null], [], [stdout])
199   AT_CHECK([$FGREP "$arg1" stdout], [], [ignore])
200   AT_CHECK([test -z "$arg2" || $FGREP "$arg2" stdout], [], [ignore])
201   AT_CHECK([test `$SED -n '/^abc$/,/^xyz$/p' stdout | wc -l` -eq 4])
202   AT_CHECK([$LIBTOOL --mode=execute ./foo lt-wrapper abc "$arg1" "$arg2" xyz], [], [stdout])
203   AT_CHECK([$FGREP "$arg1" stdout], [], [ignore])
204   AT_CHECK([test -z "$arg2" || $FGREP "$arg2" stdout], [], [ignore])
205   AT_CHECK([test `$SED -n '/^abc$/,/^xyz$/p' stdout | wc -l` -eq 4])
206   AT_CHECK([$LIBTOOL --mode=execute ./main$EXEEXT abc "$arg1" "$arg2" xyz], [], [stdout])
207   AT_CHECK([$FGREP "$arg1" stdout], [], [ignore])
208   AT_CHECK([test -z "$arg2" || $FGREP "$arg2" stdout], [], [ignore])
209   # Do not match EOL here, cross setups may have an extra \r here.
210   AT_CHECK([test `$SED -n '/^abc/,/^xyz/p' stdout | wc -l` -eq 4])
211   arg1=
212 done
214 # Check that .la files are not transformed by the wrapper searching loop.
215 AT_CHECK([$LIBTOOL --mode=execute echo ./main$EXEEXT liba.lo libfakelib.la], [], [stdout])
216 # This could be .libs/lt-main or similar (or just plain 'main').
217 AT_CHECK([$GREP main stdout], [], [ignore])
218 AT_CHECK([$GREP liba.lo stdout], [], [ignore])
219 AT_CHECK([$GREP libfakelib.la stdout], [], [ignore])
221 AT_CLEANUP