TF_RUN 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/bin/bash
  2. . "$TF_DIR/include/subtest.sh"
  3. . "$TF_DIR/include/tools.sh"
  4. . "$(sfpath)" || tf_exit_error "failed to init shellfu"
  5. export PRETTY=plain
  6. shellfu import inigrep || tf_exit_error "failed to import inigrep"
  7. #shellcheck disable=SC2016
  8. specchar() {
  9. #
  10. # List all "special" chars and their names
  11. #
  12. local what=$1
  13. {
  14. echo ' space'
  15. echo '!exclamation'
  16. echo '"quote'
  17. echo '#hash'
  18. echo '$dollar'
  19. echo '%percent'
  20. echo '&ampersand'
  21. echo "'apostrophe"
  22. echo '(lbracket'
  23. echo ')rbracket'
  24. echo '*asterisk'
  25. echo '+plus'
  26. echo ',comma'
  27. echo '-minus'
  28. echo '.dot'
  29. echo '/slash'
  30. echo ':colon'
  31. echo ';semicolon'
  32. echo '<lt'
  33. echo '=equal'
  34. echo '>gt'
  35. echo '?question'
  36. echo '@at'
  37. echo '[lsbracket'
  38. echo '\backslash'
  39. echo ']rsbracket'
  40. echo '^caret'
  41. echo '_underscore'
  42. echo '`backtick'
  43. echo '{lcbracket'
  44. echo '|pipe'
  45. echo '}rcbracket'
  46. echo '~tilde'
  47. # echo '☯yinyang'
  48. } \
  49. | case $what in
  50. CHARS) grep -o ^. ;;
  51. NAMES) sed s/.// ;;
  52. "") cat ;;
  53. *) grep -x ".$what" \
  54. | grep -o ^. ;;
  55. esac
  56. }
  57. tf_enum_subtests() {
  58. #
  59. # Enumerate test names
  60. #
  61. {
  62. specchar NAMES \
  63. | sed s/^/k_/
  64. specchar NAMES \
  65. | sed s/^/s_/
  66. specchar NAMES \
  67. | sed s/^/v_/
  68. } \
  69. | grep -vxF k_dot
  70. }
  71. tf_do_subtest() {
  72. local t_name=$1
  73. local t_cmd
  74. local char
  75. local charname=${t_name:2}
  76. local o_out="oracle/$t_name.stdout"
  77. local o_err="oracle/$t_name.stderr"
  78. local o_es=0
  79. local t_in="test/$t_name.stdin"
  80. char=$(specchar "$charname")
  81. echo -n > "$o_out"
  82. echo -n > "$o_err"
  83. # Variables marked with "a" ant "z" are traps, what we want inigrep to
  84. # catch is placed in $key_tt, $section_t or $value_tt
  85. #
  86. local section_a="section_a"
  87. local section_t="section_t"
  88. local section_z="section_z"
  89. local key_aa="key_aa"
  90. local key_az="key_az"
  91. local key_ta="key_ta"
  92. local key_tt="key_tt"
  93. local key_tz="key_tz"
  94. local key_za="key_za"
  95. local key_zz="key_zz"
  96. local value_aa="value_aa"
  97. local value_az="value_az"
  98. local value_ta="value_ta"
  99. local value_tt="value_tt"
  100. local value_tz="value_tz"
  101. local value_za="value_za"
  102. local value_zz="value_zz"
  103. # test input
  104. #
  105. case $t_name in
  106. v_*)
  107. value_ta="anoter value with $charname ($char) inside"
  108. value_tt="value with $charname ($char) inside"
  109. value_tz="yet anoter value with $charname ($char) inside"
  110. ;;
  111. s_*)
  112. section_a="another_section_with_${charname}${char}inside"
  113. section_t="section_with_${charname}${char}inside"
  114. section_z="yet_another_section_with_${charname}${char}inside"
  115. value_tt="value from section with $charname inside"
  116. ;;
  117. k_*)
  118. key_ta="another_key_with_${charname}${char}inside"
  119. key_tt="key_with_${charname}${char}inside"
  120. key_tz="yet_another_key_with_${charname}${char}inside"
  121. value_tt="value for key with $charname inside"
  122. ;;
  123. esac
  124. {
  125. echo "#t_name: $t_name"
  126. echo "#charname: $charname"
  127. echo "#char: $char"
  128. echo
  129. echo "[$section_a]"
  130. echo " $key_aa = $value_aa"
  131. echo " $key_az = $value_az"
  132. echo
  133. echo "[$section_t]"
  134. echo " $key_ta = $value_ta"
  135. echo " $key_tt = $value_tt" # aiming THIS; rest is traps
  136. echo " $key_tz = $value_tz"
  137. echo
  138. echo "[$section_z]"
  139. echo " $key_za = $value_za"
  140. echo " $key_zz = $value_zz"
  141. echo
  142. } > "$t_in"
  143. # test command
  144. #
  145. case $t_name in
  146. v_*) t_cmd="inigrep section_t.key_tt" ;;
  147. s_apostrophe) t_cmd='inigrep "section_with_apostrophe'"'"'inside.key_tt"' ;;
  148. s_*) t_cmd="inigrep 'section_with_${charname}${char}inside.key_tt'" ;;
  149. k_apostrophe) t_cmd='inigrep "section_t.key_with_apostrophe'"'"'inside"' ;;
  150. k_*) t_cmd="inigrep 'section_t.key_with_${charname}${char}inside'" ;;
  151. esac
  152. # oracle output
  153. #
  154. case $t_name in
  155. v_*) echo "value with $charname ($char) inside" ;;
  156. s_*) echo "value from section with $charname inside" ;;
  157. k_*) echo "value for key with $charname inside" ;;
  158. esac > "$o_out"
  159. case $t_name in
  160. k_backslash)
  161. o_es=2
  162. echo -n '' > "$o_out"
  163. echo "invalid char '\\' in key name: $key_tt" > "$o_err"
  164. ;;
  165. k_equal)
  166. o_es=2
  167. echo -n '' > "$o_out"
  168. echo "invalid char '=' in key name: $key_tt" > "$o_err"
  169. ;;
  170. k_lsbracket)
  171. o_es=2
  172. echo -n '' > "$o_out"
  173. echo "invalid char '[' in key name: $key_tt" > "$o_err"
  174. ;;
  175. s_rsbracket)
  176. o_es=2
  177. echo -n '' > "$o_out"
  178. echo "invalid char ']' in section name: $section_t" > "$o_err"
  179. ;;
  180. esac
  181. # pray and...
  182. #
  183. tf_testflt -n "$t_name" -i "$t_in" -O "$o_out" -E "$o_err" -S $o_es "$t_cmd"
  184. }
  185. mkdir -p test oracle result
  186. tf_do_subtests