| 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
|
|---|
|
|---|