123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #!/bin/bash
-
- . "$TF_DIR/include/subtest.sh"
- . "$TF_DIR/include/tools.sh"
-
- . "$(sfpath)" || tf_exit_error "failed to init shellfu"
- export PRETTY=plain
- shellfu import inigrep || tf_exit_error "failed to import inigrep"
-
- #shellcheck disable=SC2016
- specchar() {
- #
- # List all "special" chars and their names
- #
- local what=$1
- {
- echo ' space'
- echo '!exclamation'
- echo '"quote'
- echo '#hash'
- echo '$dollar'
- echo '%percent'
- echo '&ersand'
- echo "'apostrophe"
- echo '(lbracket'
- echo ')rbracket'
- echo '*asterisk'
- echo '+plus'
- echo ',comma'
- echo '-minus'
- echo '.dot'
- echo '/slash'
- echo ':colon'
- echo ';semicolon'
- echo '<lt'
- echo '=equal'
- echo '>gt'
- echo '?question'
- echo '@at'
- echo '[lsbracket'
- echo '\backslash'
- echo ']rsbracket'
- echo '^caret'
- echo '_underscore'
- echo '`backtick'
- echo '{lcbracket'
- echo '|pipe'
- echo '}rcbracket'
- echo '~tilde'
- # echo '☯yinyang'
- } \
- | case $what in
- CHARS) grep -o ^. ;;
- NAMES) sed s/.// ;;
- "") cat ;;
- *) grep -x ".$what" \
- | grep -o ^. ;;
- esac
- }
-
- tf_enum_subtests() {
- #
- # Enumerate test names
- #
- {
- specchar NAMES \
- | sed s/^/k_/
- specchar NAMES \
- | sed s/^/s_/
- specchar NAMES \
- | sed s/^/v_/
- } \
- | grep -vxF k_dot
- }
-
- tf_do_subtest() {
- local t_name=$1
- local t_cmd
- local char
- local charname=${t_name:2}
- local o_out="oracle/$t_name.stdout"
- local o_err="oracle/$t_name.stderr"
- local o_es=0
- local t_in="test/$t_name.stdin"
- char=$(specchar "$charname")
- echo -n > "$o_out"
- echo -n > "$o_err"
-
- # Variables marked with "a" ant "z" are traps, what we want inigrep to
- # catch is placed in $key_tt, $section_t or $value_tt
- #
- local section_a="section_a"
- local section_t="section_t"
- local section_z="section_z"
- local key_aa="key_aa"
- local key_az="key_az"
- local key_ta="key_ta"
- local key_tt="key_tt"
- local key_tz="key_tz"
- local key_za="key_za"
- local key_zz="key_zz"
- local value_aa="value_aa"
- local value_az="value_az"
- local value_ta="value_ta"
- local value_tt="value_tt"
- local value_tz="value_tz"
- local value_za="value_za"
- local value_zz="value_zz"
-
- # test input
- #
- case $t_name in
- v_*)
- value_ta="anoter value with $charname ($char) inside"
- value_tt="value with $charname ($char) inside"
- value_tz="yet anoter value with $charname ($char) inside"
- ;;
- s_*)
- section_a="another_section_with_${charname}${char}inside"
- section_t="section_with_${charname}${char}inside"
- section_z="yet_another_section_with_${charname}${char}inside"
- value_tt="value from section with $charname inside"
- ;;
- k_*)
- key_ta="another_key_with_${charname}${char}inside"
- key_tt="key_with_${charname}${char}inside"
- key_tz="yet_another_key_with_${charname}${char}inside"
- value_tt="value for key with $charname inside"
- ;;
- esac
- {
- echo "#t_name: $t_name"
- echo "#charname: $charname"
- echo "#char: $char"
- echo
- echo "[$section_a]"
- echo " $key_aa = $value_aa"
- echo " $key_az = $value_az"
- echo
- echo "[$section_t]"
- echo " $key_ta = $value_ta"
- echo " $key_tt = $value_tt" # aiming THIS; rest is traps
- echo " $key_tz = $value_tz"
- echo
- echo "[$section_z]"
- echo " $key_za = $value_za"
- echo " $key_zz = $value_zz"
- echo
- } > "$t_in"
-
- # test command
- #
- case $t_name in
- v_*) t_cmd="inigrep section_t.key_tt" ;;
- s_apostrophe) t_cmd='inigrep "section_with_apostrophe'"'"'inside.key_tt"' ;;
- s_*) t_cmd="inigrep 'section_with_${charname}${char}inside.key_tt'" ;;
- k_apostrophe) t_cmd='inigrep "section_t.key_with_apostrophe'"'"'inside"' ;;
- k_*) t_cmd="inigrep 'section_t.key_with_${charname}${char}inside'" ;;
- esac
-
- # oracle output
- #
- case $t_name in
- v_*) echo "value with $charname ($char) inside" ;;
- s_*) echo "value from section with $charname inside" ;;
- k_*) echo "value for key with $charname inside" ;;
- esac > "$o_out"
-
- case $t_name in
- k_backslash)
- o_es=2
- echo -n '' > "$o_out"
- echo "invalid char '\\' in key name: $key_tt" > "$o_err"
- ;;
- k_equal)
- o_es=2
- echo -n '' > "$o_out"
- echo "invalid char '=' in key name: $key_tt" > "$o_err"
- ;;
- k_lsbracket)
- o_es=2
- echo -n '' > "$o_out"
- echo "invalid char '[' in key name: $key_tt" > "$o_err"
- ;;
- s_rsbracket)
- o_es=2
- echo -n '' > "$o_out"
- echo "invalid char ']' in section name: $section_t" > "$o_err"
- ;;
- esac
-
- # pray and...
- #
- tf_testflt -n "$t_name" -i "$t_in" -O "$o_out" -E "$o_err" -S $o_es "$t_cmd"
- }
-
- mkdir -p test oracle result
- tf_do_subtests
|