]>
Commit | Line | Data |
---|---|---|
48d0341c | 1 | #!/bin/sh |
9a9028b1 | 2 | # Test for wordexp(3). |
04277e02 | 3 | # Copyright (C) 1998-2019 Free Software Foundation, Inc. |
9a9028b1 DL |
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 | |
5a82c748 | 18 | # <https://www.gnu.org/licenses/>. |
14c44e2e | 19 | |
57c69bef DL |
20 | set -e |
21 | ||
14c44e2e UD |
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 | |
8540f6d2 JM |
27 | test_program_prefix_before_env=$1; shift |
28 | run_program_env=$1; shift | |
29 | test_program_prefix_after_env=$1; shift | |
ceb579a3 UD |
30 | logfile=${common_objpfx}posix/wordexp-tst.out |
31 | testout=${common_objpfx}posix/wordexp-test-result | |
14c44e2e | 32 | |
3f36c563 UD |
33 | result=0 |
34 | rm -f $logfile | |
31161268 UD |
35 | # This is written in this funny way so that there is no trailing whitespace. |
36 | # The first line contains a space followed by a tab. | |
37 | IFS=" \ | |
38 | ||
39 | " | |
40 | export IFS | |
41 | ||
3f36c563 | 42 | failed=0 |
8540f6d2 JM |
43 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
44 | ${test_program_prefix_after_env} \ | |
14c44e2e | 45 | ${common_objpfx}posix/wordexp-test '$*' > ${testout}1 |
3f36c563 | 46 | cat <<"EOF" | cmp - ${testout}1 >> $logfile || failed=1 |
14c44e2e UD |
47 | wordexp returned 0 |
48 | we_wordv[0] = "$*" | |
49 | EOF | |
3f36c563 UD |
50 | if test $failed -ne 0; then |
51 | echo '$* test failed' | |
52 | status=1 | |
53 | fi | |
14c44e2e | 54 | |
3f36c563 | 55 | failed=0 |
8540f6d2 JM |
56 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
57 | ${test_program_prefix_after_env} \ | |
14c44e2e | 58 | ${common_objpfx}posix/wordexp-test '${*}' unquoted > ${testout}2 |
3f36c563 | 59 | cat <<"EOF" | cmp - ${testout}2 >> $logfile || failed=1 |
14c44e2e UD |
60 | wordexp returned 0 |
61 | we_wordv[0] = "${*}" | |
62 | we_wordv[1] = "unquoted" | |
63 | EOF | |
3f36c563 UD |
64 | if test $failed -ne 0; then |
65 | echo '${*} test failed' | |
66 | status=1 | |
67 | fi | |
14c44e2e | 68 | |
3f36c563 | 69 | failed=0 |
8540f6d2 JM |
70 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
71 | ${test_program_prefix_after_env} \ | |
14c44e2e | 72 | ${common_objpfx}posix/wordexp-test '$@' unquoted > ${testout}3 |
3f36c563 | 73 | cat <<"EOF" | cmp - ${testout}3 >> $logfile || failed=1 |
14c44e2e UD |
74 | wordexp returned 0 |
75 | we_wordv[0] = "$@" | |
76 | we_wordv[1] = "unquoted" | |
77 | EOF | |
3f36c563 UD |
78 | if test $failed -ne 0; then |
79 | echo '$@ test failed' | |
80 | status=1 | |
81 | fi | |
14c44e2e | 82 | |
3f36c563 | 83 | failed=0 |
8540f6d2 JM |
84 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
85 | ${test_program_prefix_after_env} \ | |
14c44e2e | 86 | ${common_objpfx}posix/wordexp-test '"$* quoted"' param > ${testout}4 |
3f36c563 | 87 | cat <<"EOF" | cmp - ${testout}4 >> $logfile || failed=1 |
14c44e2e UD |
88 | wordexp returned 0 |
89 | we_wordv[0] = ""$* quoted" param quoted" | |
90 | EOF | |
3f36c563 UD |
91 | if test $failed -ne 0; then |
92 | echo '$* quoted test failed' | |
93 | status=1 | |
94 | fi | |
14c44e2e | 95 | |
3f36c563 | 96 | failed=0 |
8540f6d2 JM |
97 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
98 | ${test_program_prefix_after_env} \ | |
14c44e2e | 99 | ${common_objpfx}posix/wordexp-test '"$@ quoted"' param > ${testout}5 |
3f36c563 | 100 | cat <<"EOF" | cmp - ${testout}5 >> $logfile || failed=1 |
14c44e2e UD |
101 | wordexp returned 0 |
102 | we_wordv[0] = ""$@ quoted"" | |
103 | we_wordv[1] = "param quoted" | |
104 | EOF | |
3f36c563 UD |
105 | if test $failed -ne 0; then |
106 | echo '$@ quoted test failed' | |
107 | status=1 | |
108 | fi | |
14c44e2e UD |
109 | # Why? Because bash does it that way.. |
110 | ||
3f36c563 | 111 | failed=0 |
8540f6d2 JM |
112 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
113 | ${test_program_prefix_after_env} \ | |
14c44e2e | 114 | ${common_objpfx}posix/wordexp-test '$#' 2 3 4 5 > ${testout}6 |
3f36c563 | 115 | cat <<"EOF" | cmp - ${testout}6 >> $logfile || failed=1 |
14c44e2e UD |
116 | wordexp returned 0 |
117 | we_wordv[0] = "5" | |
118 | EOF | |
3f36c563 UD |
119 | if test $failed -ne 0; then |
120 | echo '$# test failed' | |
121 | status=1 | |
122 | fi | |
14c44e2e | 123 | |
3f36c563 | 124 | failed=0 |
8540f6d2 JM |
125 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
126 | ${test_program_prefix_after_env} \ | |
76fbcfdd | 127 | ${common_objpfx}posix/wordexp-test '$2 ${3} $4' 2nd 3rd "4 th" > ${testout}7 |
3f36c563 | 128 | cat <<"EOF" | cmp - ${testout}7 >> $logfile || failed=1 |
14c44e2e UD |
129 | wordexp returned 0 |
130 | we_wordv[0] = "2nd" | |
131 | we_wordv[1] = "3rd" | |
76fbcfdd UD |
132 | we_wordv[2] = "4" |
133 | we_wordv[3] = "th" | |
14c44e2e | 134 | EOF |
3f36c563 UD |
135 | if test $failed -ne 0; then |
136 | echo '$2 ${3} $4 test failed' | |
137 | status=1 | |
138 | fi | |
14c44e2e | 139 | |
3f36c563 | 140 | failed=0 |
8540f6d2 JM |
141 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
142 | ${test_program_prefix_after_env} \ | |
31161268 | 143 | ${common_objpfx}posix/wordexp-test '${11}' 2 3 4 5 6 7 8 9 10 11 > ${testout}8 |
3f36c563 | 144 | cat <<"EOF" | cmp - ${testout}8 >> $logfile || failed=1 |
31161268 UD |
145 | wordexp returned 0 |
146 | we_wordv[0] = "11" | |
147 | EOF | |
3f36c563 UD |
148 | if test $failed -ne 0; then |
149 | echo '${11} test failed' | |
150 | status=1 | |
151 | fi | |
31161268 | 152 | |
3f36c563 | 153 | failed=0 |
8540f6d2 JM |
154 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
155 | ${test_program_prefix_after_env} \ | |
31161268 | 156 | ${common_objpfx}posix/wordexp-test '"a $@ b"' c d > ${testout}9 |
3f36c563 | 157 | cat <<"EOF" | cmp - ${testout}9 >> $logfile || failed=1 |
31161268 UD |
158 | wordexp returned 0 |
159 | we_wordv[0] = "a "a $@ b"" | |
160 | we_wordv[1] = "c" | |
161 | we_wordv[2] = "d b" | |
162 | EOF | |
3f36c563 UD |
163 | if test $failed -ne 0; then |
164 | echo '"a $@ b" test failed' | |
165 | status=1 | |
166 | fi | |
31161268 | 167 | |
8540f6d2 JM |
168 | ${test_program_prefix_before_env} ${run_program_env} IFS="$IFS" \ |
169 | ${test_program_prefix_after_env} \ | |
e9fc7bbb UD |
170 | ${common_objpfx}posix/wordexp-test '${#@} ${#2} *$**' two 3 4 > ${testout}10 |
171 | cat <<"EOF" | cmp - ${testout}10 || failed=1 | |
172 | wordexp returned 0 | |
173 | we_wordv[0] = "4" | |
174 | we_wordv[1] = "3" | |
175 | we_wordv[2] = "*${#@}" | |
176 | we_wordv[3] = "${#2}" | |
177 | we_wordv[4] = "*$**" | |
178 | we_wordv[5] = "two" | |
179 | we_wordv[6] = "3" | |
180 | we_wordv[7] = "4*" | |
181 | EOF | |
182 | ||
3f36c563 | 183 | exit $result |