# execute-mode.at -- libtool --mode=execute -*- Autotest -*-
#
# Copyright (C) 2008-2019, 2021-2026 Free Software Foundation, Inc.
# Written by Ralf Wildenhues, 2008
#
# This file is part of GNU Libtool.
#
# GNU Libtool is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# GNU Libtool is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Libtool. If not, see .
####
AT_SETUP([execute mode])
AT_KEYWORDS([libtool])
eval `$LIBTOOL --config | $EGREP '^(FGREP)='`
AT_DATA([foo],
[[#! /bin/sh
if test $# -gt 0; then
for arg
do
printf %s\\n "$arg"
done
else
:
fi
]])
AT_DATA([lt-wrapper],
[[#! /bin/sh
# Generated by GNU libtool.
# fake wrapper script.
program=lt-real
progdir=.
if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
# Run the actual program with our arguments.
exec "$progdir/$program" ${1+"$@"}
echo "$0: cannot exec $program $*" >&2
exit 1
fi
]])
AT_DATA([lt-real],
[[#! /bin/sh
for arg
do
printf %s\\n "$arg"
done
cat
]])
AT_DATA([libfakelib.la],
[[# libfakelib.la - a libtool library file
# Generated by ltmain.sh (GNU libtool 1.2605 2008/03/04 22:31:32) 2.3a
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
dlname=''
library_names=''
old_library='libfakelib.a'
inherited_linker_flags=''
dependency_libs=''
weak_library_names=''
current=
age=
revision=
installed=no
shouldnotlink=yes
dlopen=''
dlpreopen=''
libdir=''
]])
mkdir sub
cp foo sub/foo
chmod +x foo sub/foo lt-wrapper lt-real
AT_DATA([liba.c],
[[int a () { return 0; }
]])
AT_DATA([main.c],
[[#include
extern int a ();
int main (int argc, char **argv)
{
int i;
for (i=1; i' in execute mode without other
# characters, so the symbols are escaped during testing in OpenBSD.
escape=
case $host_os in openbsd*)
escape='\' ;;
esac
# We always pair two args. The first one is never the empty string.
arg1=
for arg2 in \
'def ghi' '' \
'd"e' 'f"g' \
'd\"e' 'f\"g' \
'd\\"e' 'f\\"g' \
'd\\\"e' 'f\\\"g' \
'd\' '' \
'd\\' '' \
'd\\\' '' \
'd\\\\' '' \
"$escape<" "$escape>" \
'' ''
do
if test -z "$arg1"; then
arg1=$arg2; continue
fi
AT_CHECK([$LIBTOOL --mode=execute ./foo abc "$arg1" "$arg2" xyz], [], [stdout], [ignore])
AT_CHECK([$FGREP "$arg1" stdout], [], [ignore])
AT_CHECK([test -z "$arg2" || $FGREP "$arg2" stdout], [], [ignore])
AT_CHECK([test `$SED -n '/^abc$/,/^xyz$/p' stdout | wc -l` -eq 4])
AT_CHECK([$LIBTOOL --mode=execute ./lt-wrapper abc "$arg1" "$arg2" xyz