Update copyright notices with scripts/update-copyrights
[jlayton/glibc.git] / posix / wordexp-tst.sh
1 #! /bin/sh
2 # Test for wordexp(3).
3 # Copyright (C) 1998-2014 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <http://www.gnu.org/licenses/>.
19
20 set -e
21
22 # Some of these tests may look a little weird.
23 # The first parameter to wordexp-test is what it gives to wordexp.
24 # The others are just there to be parameters.
25
26 common_objpfx=$1; shift
27 test_program_prefix=$1; shift
28 logfile=${common_objpfx}posix/wordexp-tst.out
29 testout=${common_objpfx}posix/wordexp-test-result
30
31 result=0
32 rm -f $logfile
33 # This is written in this funny way so that there is no trailing whitespace.
34 # The first line contains a space followed by a tab.
35 IFS="   \
36
37 "
38 export IFS
39
40 failed=0
41 ${test_program_prefix} \
42 ${common_objpfx}posix/wordexp-test '$*' > ${testout}1
43 cat <<"EOF" | cmp - ${testout}1 >> $logfile || failed=1
44 wordexp returned 0
45 we_wordv[0] = "$*"
46 EOF
47 if test $failed -ne 0; then
48   echo '$* test failed'
49   status=1
50 fi
51
52 failed=0
53 ${test_program_prefix} \
54 ${common_objpfx}posix/wordexp-test '${*}' unquoted > ${testout}2
55 cat <<"EOF" | cmp - ${testout}2 >> $logfile || failed=1
56 wordexp returned 0
57 we_wordv[0] = "${*}"
58 we_wordv[1] = "unquoted"
59 EOF
60 if test $failed -ne 0; then
61   echo '${*} test failed'
62   status=1
63 fi
64
65 failed=0
66 ${test_program_prefix} \
67 ${common_objpfx}posix/wordexp-test '$@' unquoted > ${testout}3
68 cat <<"EOF" | cmp - ${testout}3 >> $logfile || failed=1
69 wordexp returned 0
70 we_wordv[0] = "$@"
71 we_wordv[1] = "unquoted"
72 EOF
73 if test $failed -ne 0; then
74   echo '$@ test failed'
75   status=1
76 fi
77
78 failed=0
79 ${test_program_prefix} \
80 ${common_objpfx}posix/wordexp-test '"$* quoted"' param > ${testout}4
81 cat <<"EOF" | cmp - ${testout}4 >> $logfile || failed=1
82 wordexp returned 0
83 we_wordv[0] = ""$* quoted" param quoted"
84 EOF
85 if test $failed -ne 0; then
86   echo '$* quoted test failed'
87   status=1
88 fi
89
90 failed=0
91 ${test_program_prefix} \
92 ${common_objpfx}posix/wordexp-test '"$@ quoted"' param > ${testout}5
93 cat <<"EOF" | cmp - ${testout}5 >> $logfile || failed=1
94 wordexp returned 0
95 we_wordv[0] = ""$@ quoted""
96 we_wordv[1] = "param quoted"
97 EOF
98 if test $failed -ne 0; then
99   echo '$@ quoted test failed'
100   status=1
101 fi
102 # Why?  Because bash does it that way..
103
104 failed=0
105 ${test_program_prefix} \
106 ${common_objpfx}posix/wordexp-test '$#' 2 3 4 5 > ${testout}6
107 cat <<"EOF" | cmp - ${testout}6 >> $logfile || failed=1
108 wordexp returned 0
109 we_wordv[0] = "5"
110 EOF
111 if test $failed -ne 0; then
112   echo '$# test failed'
113   status=1
114 fi
115
116 failed=0
117 ${test_program_prefix} \
118 ${common_objpfx}posix/wordexp-test '$2 ${3} $4' 2nd 3rd "4 th" > ${testout}7
119 cat <<"EOF" | cmp - ${testout}7 >> $logfile || failed=1
120 wordexp returned 0
121 we_wordv[0] = "2nd"
122 we_wordv[1] = "3rd"
123 we_wordv[2] = "4"
124 we_wordv[3] = "th"
125 EOF
126 if test $failed -ne 0; then
127   echo '$2 ${3} $4 test failed'
128   status=1
129 fi
130
131 failed=0
132 ${test_program_prefix} \
133 ${common_objpfx}posix/wordexp-test '${11}' 2 3 4 5 6 7 8 9 10 11 > ${testout}8
134 cat <<"EOF" | cmp - ${testout}8 >> $logfile || failed=1
135 wordexp returned 0
136 we_wordv[0] = "11"
137 EOF
138 if test $failed -ne 0; then
139   echo '${11} test failed'
140   status=1
141 fi
142
143 failed=0
144 ${test_program_prefix} \
145 ${common_objpfx}posix/wordexp-test '"a $@ b"' c d > ${testout}9
146 cat <<"EOF" | cmp - ${testout}9 >> $logfile || failed=1
147 wordexp returned 0
148 we_wordv[0] = "a "a $@ b""
149 we_wordv[1] = "c"
150 we_wordv[2] = "d b"
151 EOF
152 if test $failed -ne 0; then
153   echo '"a $@ b" test failed'
154   status=1
155 fi
156
157 ${test_program_prefix} \
158 ${common_objpfx}posix/wordexp-test '${#@} ${#2} *$**' two 3 4 > ${testout}10
159 cat <<"EOF" | cmp - ${testout}10 || failed=1
160 wordexp returned 0
161 we_wordv[0] = "4"
162 we_wordv[1] = "3"
163 we_wordv[2] = "*${#@}"
164 we_wordv[3] = "${#2}"
165 we_wordv[4] = "*$**"
166 we_wordv[5] = "two"
167 we_wordv[6] = "3"
168 we_wordv[7] = "4*"
169 EOF
170
171 exit $result