Fixed package groups
[platform/upstream/libtool.git] / tests / quote.test
1 #! /bin/sh
2 # quote.test - make sure that shell metacharacters do not blow up libtool
3 #
4 #   Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
5 #   Written by Gary V. Vaughan, 2003
6 #
7 #   This file is part of GNU Libtool.
8 #
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.
13 #
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.
18 #
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 ####
25
26 . tests/defs || exit 1
27
28 # Do the torture test.
29 status=$EXIT_SUCCESS
30
31 case $1 in
32   --no-reexec)
33     ;;
34   *)
35     func_get_config "SHELL" "$LIBTOOL --config"
36     exec $SHELL "$0" --no-reexec ${1+"$@"}
37     ;;
38 esac
39
40 func_get_config "ECHO wl" "$LIBTOOL --config"
41
42 for mode in compile link install; do
43   echo "== $mode mode"
44
45   # Unfortunately, without an array data type, it is nearly impossible
46   # to protect libtool from metacharacters in filenames.  So, we just
47   # try metacharacters in the options it needs to pass to other programs.
48
49   # preargs and postargs need to go through libtool unmodified.
50   case "$mode" in
51   compile)
52     preargs="$CC -c"
53     preflag=
54     match_preflag=
55     flag="-DVAR="
56     postargs="foo.c"
57     ;;
58
59   link)
60     preargs="$CC -o hell -g -O"
61     preflag=-Wl,
62     match_preflag="$wl"
63     flag="-someflag="
64     postargs="foo.o"
65     ;;
66
67   install)
68     preargs="install -c"
69     preflag=
70     match_preflag=
71     flag="--something="
72     postargs="hell /usr/local/bin/hell"
73     ;;
74   esac
75
76   # Trivial.
77   echo "= trying: no quoting"
78   result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}test" $postargs` || status=$EXIT_FAILURE
79   # We used to have the contents of $match in the case statement,
80   # without an intermediate variable, but it would fail on at least
81   # Solaris' and HP-UX's /bin/sh.  Ugh!
82   # We must not attempt to match $preargs in the output, because libtool
83   # may modify them.  For example, on Cygwin, ``libtool --mode=link gcc -o
84   # foo foo.o''  becomes ``gcc -o foo.exe foo.o''.
85   match="${match_preflag}${flag}test "
86   case "$result" in
87   *"$match"*)
88     $ECHO "= passed: $result"
89     ;;
90   *)
91     $ECHO "= failed: $result"
92     status=$EXIT_FAILURE
93     ;;
94   esac
95
96   # Metacharacters that should be backslashified.
97   for mchar in \\ \" \` \$; do
98     $ECHO "= trying: \\$mchar quoting"
99     result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=$EXIT_FAILURE
100     match="${match_preflag}${flag}\\${mchar}test\\${mchar} "
101     alt_match="${match_preflag}\"${flag}\\${mchar}test\\${mchar}\" "
102     case "$result" in
103     *"$match"*)
104       $ECHO "= passed: $result"
105       ;;
106     *"$alt_match"*)
107       $ECHO "= passed (harmless ksh bug): $result"
108       ;;
109     *)
110       $ECHO "= failed: $result"
111       status=$EXIT_FAILURE
112       ;;
113     esac
114   done
115
116   # Metacharacters that should be double quoted.
117   for mchar in "[" "]" "~" "#" "^" "&" "*" "(" ")" "{" "}" "|" ";" "<" ">" "?" \
118       "'" " " " "; do
119
120     $ECHO "= trying: \"$mchar\" quoting"
121     result=`$LIBTOOL -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=$EXIT_FAILURE
122     match="${match_preflag}\"${flag}${mchar}test${mchar}\" "
123     case "$result" in
124     *"$match"*)
125       $ECHO "= passed: $result"
126       ;;
127     *)
128       $ECHO "= failed: $result"
129       status=$EXIT_FAILURE
130       ;;
131     esac
132   done
133 done
134
135 exit $status