File: quote.test

package info (click to toggle)
libtool 1.5.22-4%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 13,260 kB
  • ctags: 645
  • sloc: sh: 11,177; ansic: 4,354; makefile: 816; cpp: 91; fortran: 19
file content (151 lines) | stat: -rwxr-xr-x 4,248 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /bin/sh
# quote.test - make sure that shell metacharacters do not blow up libtool

# Test script header.
need_prefix=no
if test -z "$srcdir"; then
  srcdir=`echo "$0" | sed 's%/[^/]*$%%'`
  test "$srcdir" = "$0" && srcdir=.
  test "${VERBOSE+set}" != "set" && VERBOSE=yes
fi
. $srcdir/defs || exit 1

# Do the torture test.
status=0

echo=echo
if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then :
else
  # The Solaris, AIX, and Digital Unix default echo programs unquote
  # backslashes.  This makes it impossible to quote backslashes using
  #   echo "$something" | sed 's/\\/\\\\/g'
  #
  # So, first we look for a working echo in the user's PATH.
  IFS="${IFS= 	}"; save_ifs="$IFS"; IFS="${IFS}:"
  for dir in $PATH /usr/ucb; do
    if test -f $dir/echo && test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t'; then
      echo="$dir/echo"
      break
    fi
  done
  IFS="$save_ifs"

  if test "X$echo" = Xecho; then
    # We didn't find a better echo, so look for alternatives.
    if test "X`(print -r '\t') 2>/dev/null`" = 'X\t'; then
      # This shell has a builtin print -r that does the trick.
      echo='print -r'
    elif test -f /bin/ksh && test "X$CONFIG_SHELL" != X/bin/ksh; then
      # If we have ksh, try running $0 again with it.
      CONFIG_SHELL=/bin/ksh
      export CONFIG_SHELL
      exec "$CONFIG_SHELL" "$0" --no-reexec ${1+"$@"}
    else
      # Try using printf.
      echo='printf %s\n'
      if test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then :
      else
        # Oops.  We lost completely, so just stick with echo.
        echo=echo
      fi
    fi
  fi
fi

# Extract $wl from the libtool configuration
eval `$libtool --config | grep '^wl='`

for mode in compile link install; do
  $echo "== $mode mode"

  # Unfortunately, without an array data type, it is nearly impossible
  # to protect libtool from metacharacters in filenames.  So, we just
  # try metacharacters in the options it needs to pass to other programs.

  # preargs and postargs need to go through libtool unmodified.
  case "$mode" in
  compile)
    preargs="$CC -c"
    preflag=
    match_preflag=
    flag="-DVAR="
    postargs="foo.c"
    ;;

  link)
    preargs="$CC -o hell -g -O"
    preflag=-Wl,
    match_preflag="$wl"
    flag="-someflag="
    postargs="foo.o"
    ;;

  install)
    preargs="install -c"
    preflag=
    match_preflag=
    flag="--something="
    postargs="hell /usr/local/bin/hell"
    ;;
  esac

  # Trivial.
  $echo "= trying: no quoting"
  result=`$libtool -n --mode=$mode $preargs ${preflag}"${flag}test" $postargs` || status=1
  # We used to have the contents of $match in the case statement,
  # without an intermediate variable, but it would fail on at least
  # Solaris' and HP-UX's /bin/sh.  Ugh!
  # We must nost attempt to match $preargs in the output, because libtool
  # may modify them.  For example, on Cygwin, ``libtool --mode=link gcc -o
  # foo foo.o''  becomes ``gcc -o foo.exe foo.o''.
  match="${match_preflag}${flag}test "
  case "$result" in
  *"$match"*)
    $echo "= passed: $result"
    ;;
  *)
    $echo "= failed: $result"
    status=1
    ;;
  esac

  # Metacharacters that should be backslashified.
  for mchar in \\ \" \` \$; do
    $echo "= trying: \\$mchar quoting"
    result=`$libtool -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=1
    match="${match_preflag}${flag}\\${mchar}test\\${mchar} "
    alt_match="${match_preflag}\"${flag}\\${mchar}test\\${mchar}\" "
    case "$result" in
    *"$match"*)
      $echo "= passed: $result"
      ;;
    *"$alt_match"*)
      $echo "= passed (harmless ksh bug): $result"
      ;;
    *)
      $echo "= failed: $result"
      status=1
      ;;
    esac
  done

  # Metacharacters that should be double quoted.
  for mchar in "[" "]" "~" "#" "^" "&" "*" "(" ")" "{" "}" "|" ";" "<" ">" "?" \
      "'" " " "	"; do

    $echo "= trying: \"$mchar\" quoting"
    result=`$libtool -n --mode=$mode $preargs ${preflag}"${flag}${mchar}test${mchar}" $postargs` || status=1
    match="${match_preflag}\"${flag}${mchar}test${mchar}\" "
    case "$result" in
    *"$match"*)
      $echo "= passed: $result"
      ;;
    *)
      $echo "= failed: $result"
      status=1
      ;;
    esac
  done
done

exit $status