~mmach/netext73/busybox

« back to all changes in this revision

Viewing changes to shell/ash_test/ash-z_slow/many_ifs.tests

  • Committer: mmach
  • Date: 2021-04-14 13:54:24 UTC
  • Revision ID: netbit73@gmail.com-20210414135424-8x3fxf716zs4wflb
1

Show diffs side-by-side

added added

removed removed

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