#!/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 '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