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.
25 AT_SETUP([execute mode])
26 AT_KEYWORDS([libtool])
28 eval `$LIBTOOL --config | $EGREP '^(FGREP)='`
32 if test $# -gt 0; then
44 # Generated by GNU libtool.
45 # fake wrapper script.
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
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.
74 old_library='libfakelib.a'
75 inherited_linker_flags=''
90 chmod +x foo sub/foo lt-wrapper lt-real
93 [[int a () { return 0; }
99 int main (int argc, char **argv)
102 for (i=1; i<argc; ++i)
105 fputc ('\n', stdout);
106 fputs (argv[i], stdout);
108 fputc ('\n', stdout);
113 LDFLAGS="$LDFLAGS -no-undefined"
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], [],
147 # check that stdin works even with -dlopen.
148 AT_CHECK([echo bar | $LIBTOOL --mode=execute -dlopen libfakelib.la ./lt-wrapper 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: \$!&*'\`()"],
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.
191 if test -z "$arg1"; then
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])
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])