many_ifs.tests 4.8 KB

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