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.
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.
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/>.
14 # Usage: $SHELL ifs.sh
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.
28 echo 1 | read ksh_read
30 eval '((ksh_arith+=1))' 2>/dev/null
38 i=$1 s=$2 r=$3 S='' R=''
53 "$s") case $ksh_arith in
55 *) passed=`expr $passed + 1` ;;
63 *) ordered=`expr $ordered + 1` ;;
68 "$S") case $ksh_arith in
70 *) failed=`expr $failed + 1` ;;
75 *) failed=`expr $failed + 1` ;;
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'" ;;
91 *) ordered=`expr $ordered + 1` ;;
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)" )` ;;
101 "$r") case $ksh_arith in
103 *) passed=`expr $passed + 1` ;;
109 *) case $ksh_arith in
111 *) ordered=`expr $ordered + 1` ;;
116 "$R") case $ksh_arith in
118 *) failed=`expr $failed + 1` ;;
121 *) case $ksh_arith in
123 *) failed=`expr $failed + 1` ;;
127 *) echo "echo \"$i\" | ( IFS=\"$ifs\" read x y; echo \"(\$x)(\$y)\" ) # expected \"$r\" got \"$g\"" ;;
133 *) case $ksh_arith in
135 *) ordered=`expr $ordered + 1` ;;
178 for d1 in '' ' ' ':' ' :' ': ' ' : '
181 '') split "$d0$f1$d1" "[0]" "()()" ;;
183 *) split "$d0$f1$d1" "[1]($f1)" "($f1)()" ;;
199 for d1 in ' ' ':' ' :' ': ' ' : '
202 $f1$d1|$d1$f2) continue ;;
204 for d2 in '' ' ' ':' ' :' ': ' ' : '
207 '') split "$d0$f1$d1$f2$d2" "[1]($f1)" "($f1)()" ;;
209 *) split "$d0$f1$d1$f2$d2" "[2]($f1)($f2)" "($f1)($f2)" ;;
226 for d1 in ':' ' :' ': ' ' : '
229 $f1$d1|$d1$f2) continue ;;
231 for d2 in ' ' ':' ' :' ': ' ' : '
237 $f2$d2|$d2$f3) continue ;;
239 for d3 in '' ' ' ':' ' :' ': ' ' : '
242 '') split "$d0$f1$d1$f2$d2$f3$d3" "[2]($f1)($f2)" "($f1)($f2)" ;;
247 split "$d0$f1$d1$f2$d2$f3$d3" "[3]($f1)($f2)($f3)" "($f1)($x)"
259 1) ((tests=passed+failed)) ;;
260 *) tests=`expr $passed + $failed` ;;
264 *) ordered=" ordered $ordered" ;;
268 *) fatal=" -- fundamental IFS error -- $TESTS tests expected"
270 echo "# tests $tests passed $passed failed $failed$ordered$fatal"