]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/ifs-posix.tests
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / ifs-posix.tests
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14 # Usage: $SHELL ifs.sh
15 #
16 # This script generates 6856 tests for the set(1) and read(1)
17 # builtins w.r.t. IFS whitespace and non-whitespace characters.
18 # Each failed test produces one line on the standard output that
19 # contains the test along with the expected and actual results.
20 # The last output line contains the test result counts. ordered>0
21 # are the number of tests where IFS=": " produced different results
22 # than IFS=" :". If a test fails the same way for IFS=": " and
23 # IFS=" :" then the second output line is suppressed.
24
25 TESTS=6856
26
27 ksh_read=0
28 echo 1 | read ksh_read
29 ksh_arith=0
30 eval '((ksh_arith+=1))' 2>/dev/null
31
32 failed=0
33 ordered=0
34 passed=0
35
36 split()
37 {
38 i=$1 s=$2 r=$3 S='' R=''
39 for ifs in ': ' ' :'
40 do IFS=$ifs
41 set x $i
42 shift
43 IFS=' '
44 g="[$#]"
45 while :
46 do case $# in
47 0) break ;;
48 esac
49 g="$g($1)"
50 shift
51 done
52 case $g in
53 "$s") case $ksh_arith in
54 1) ((passed+=1)) ;;
55 *) passed=`expr $passed + 1` ;;
56 esac
57 case $S in
58 '') S=$g
59 ;;
60 "$g") ;;
61 *) case $ksh_arith in
62 1) ((ordered+=1)) ;;
63 *) ordered=`expr $ordered + 1` ;;
64 esac
65 ;;
66 esac
67 ;;
68 "$S") case $ksh_arith in
69 1) ((failed+=1)) ;;
70 *) failed=`expr $failed + 1` ;;
71 esac
72 ;;
73 *) case $ksh_arith in
74 1) ((failed+=1)) ;;
75 *) failed=`expr $failed + 1` ;;
76 esac
77 case $s in
78 "$S") ;;
79 ?0*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#]\" # expected \"$s\" got \"$g\"" ;;
80 ?1*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)\" # expected \"$s\" got \"$g\"" ;;
81 ?2*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)(\$2)\" # expected \"$s\" got \"$g\"" ;;
82 ?3*) echo "IFS=\"$ifs\"; x=\"$i\"; set x \$x; shift; echo \"[\$#](\$1)(\$2)(\$3)\" # expected \"$s\" got \"$g\"" ;;
83 *) echo TEST ERROR i="'$i'" s="'$s'" ;;
84 esac
85 case $S in
86 '') S=$g
87 ;;
88 "$g") ;;
89 *) case $ksh_arith in
90 1) ((ordered+=1)) ;;
91 *) ordered=`expr $ordered + 1` ;;
92 esac
93 ;;
94 esac
95 esac
96 case $ksh_read in
97 1) echo "$i" | IFS=$ifs read x y; g="($x)($y)" ;;
98 *) g=`export ifs; echo "$i" | ( IFS=$ifs; read x y; echo "($x)($y)" )` ;;
99 esac
100 case $g in
101 "$r") case $ksh_arith in
102 1) ((passed+=1)) ;;
103 *) passed=`expr $passed + 1` ;;
104 esac
105 case $R in
106 '') R=$g
107 ;;
108 "$g") ;;
109 *) case $ksh_arith in
110 1) ((ordered+=1)) ;;
111 *) ordered=`expr $ordered + 1` ;;
112 esac
113 ;;
114 esac
115 ;;
116 "$R") case $ksh_arith in
117 1) ((failed+=1)) ;;
118 *) failed=`expr $failed + 1` ;;
119 esac
120 ;;
121 *) case $ksh_arith in
122 1) ((failed+=1)) ;;
123 *) failed=`expr $failed + 1` ;;
124 esac
125 case $r in
126 "$R") ;;
127 *) echo "echo \"$i\" | ( IFS=\"$ifs\" read x y; echo \"(\$x)(\$y)\" ) # expected \"$r\" got \"$g\"" ;;
128 esac
129 case $R in
130 '') R=$g
131 ;;
132 "$g") ;;
133 *) case $ksh_arith in
134 1) ((ordered+=1)) ;;
135 *) ordered=`expr $ordered + 1` ;;
136 esac
137 ;;
138 esac
139 ;;
140 esac
141 done
142 }
143
144 for str in \
145 '-' \
146 'a' \
147 '- -' \
148 '- a' \
149 'a -' \
150 'a b' \
151 '- - -' \
152 '- - a' \
153 '- a -' \
154 '- a b' \
155 'a - -' \
156 'a - b' \
157 'a b -' \
158 'a b c' \
159
160 do
161 IFS=' '
162 set x $str
163
164 shift
165 case $# in
166 0) continue ;;
167 esac
168
169 f1=$1
170 case $f1 in
171 '-') f1='' ;;
172 esac
173
174 shift
175 case $# in
176 0) for d0 in '' ' '
177 do
178 for d1 in '' ' ' ':' ' :' ': ' ' : '
179 do
180 case $f1$d1 in
181 '') split "$d0$f1$d1" "[0]" "()()" ;;
182 ' ') ;;
183 *) split "$d0$f1$d1" "[1]($f1)" "($f1)()" ;;
184 esac
185 done
186 done
187 continue
188 ;;
189 esac
190 f2=$1
191 case $f2 in
192 '-') f2='' ;;
193 esac
194
195 shift
196 case $# in
197 0) for d0 in '' ' '
198 do
199 for d1 in ' ' ':' ' :' ': ' ' : '
200 do
201 case ' ' in
202 $f1$d1|$d1$f2) continue ;;
203 esac
204 for d2 in '' ' ' ':' ' :' ': ' ' : '
205 do
206 case $f2$d2 in
207 '') split "$d0$f1$d1$f2$d2" "[1]($f1)" "($f1)()" ;;
208 ' ') ;;
209 *) split "$d0$f1$d1$f2$d2" "[2]($f1)($f2)" "($f1)($f2)" ;;
210 esac
211 done
212 done
213 done
214 continue
215 ;;
216 esac
217 f3=$1
218 case $f3 in
219 '-') f3='' ;;
220 esac
221
222 shift
223 case $# in
224 0) for d0 in '' ' '
225 do
226 for d1 in ':' ' :' ': ' ' : '
227 do
228 case ' ' in
229 $f1$d1|$d1$f2) continue ;;
230 esac
231 for d2 in ' ' ':' ' :' ': ' ' : '
232 do
233 case $f2$d2 in
234 ' ') continue ;;
235 esac
236 case ' ' in
237 $f2$d2|$d2$f3) continue ;;
238 esac
239 for d3 in '' ' ' ':' ' :' ': ' ' : '
240 do
241 case $f3$d3 in
242 '') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;;
243 ' ') ;;
244 *) x=$f2$d2$f3$d3
245 x=${x#' '}
246 x=${x%' '}
247 split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)"
248 ;;
249 esac
250 done
251 done
252 done
253 done
254 continue
255 ;;
256 esac
257 done
258 case $ksh_arith in
259 1) ((tests=passed+failed)) ;;
260 *) tests=`expr $passed + $failed` ;;
261 esac
262 case $ordered in
263 0) ordered="" ;;
264 *) ordered=" ordered $ordered" ;;
265 esac
266 case $tests in
267 $TESTS) fatal="" ;;
268 *) fatal=" -- fundamental IFS error -- $TESTS tests expected"
269 esac
270 echo "# tests $tests passed $passed failed $failed$ordered$fatal"