diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-09-06 09:32:31 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-09-16 11:54:04 +0200 |
| commit | 4c70989cb77c1c9e77f30d134e7eba6e9dc06ac9 (patch) | |
| tree | ed207e2f2ac5944d84ef6cb69abce4ef98237df7 /validation/test-suite | |
| parent | e82ef9b847274e428682dd889194da54c9945a58 (diff) | |
| download | sparse-dev-4c70989cb77c1c9e77f30d134e7eba6e9dc06ac9.tar.gz | |
testsuite: new eq/min/max syntax for pattern checking
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation/test-suite')
| -rwxr-xr-x | validation/test-suite | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/validation/test-suite b/validation/test-suite index bdc1424f..a92debd8 100755 --- a/validation/test-suite +++ b/validation/test-suite @@ -46,6 +46,7 @@ get_tag_value() check_output_contains=0 check_output_excludes=0 check_output_pattern=0 + check_output_pattern_minmax=0 lines=$(grep 'check-[a-z-]*' $1 | \ sed -e 's/^.*\(check-[a-z-]*:*\) *\(.*\)$/\1 \2/') @@ -65,6 +66,7 @@ get_tag_value() check-output-contains:) check_output_contains=1 ;; check-output-excludes:) check_output_excludes=1 ;; check-output-pattern-) check_output_pattern=1 ;; + check-output-pattern) check_output_pattern_minmax=1 ;; esac done << EOT $lines @@ -154,6 +156,47 @@ nbr_patterns() return $? } +## +# minmax_patterns(ifile tag ofile) - does ofile contains the +# the patterns given by ifile's tags +# the right number of time? +minmax_patterns() +{ + ifile="$1" + patt="$2" + ofile="$3" + grep "$patt([0-9-]*\(, *\)*[0-9-]*):" "$ifile" | \ + sed -e "s/^.*$patt(\([0-9]*\)): *\(.*\)/\1 eq \2/" \ + -e "s/^.*$patt(\([0-9-]*\), *\([0-9-]*\)): *\(.*\)/\1 \2 \3/" | \ + while read min max pat; do + n=$(grep -s "$pat" "$ofile" | wc -l) + if [ "$max" = "eq" ]; then + if [ "$n" -ne "$min" ]; then + error "test '$ifile' failed" + error " Pattern '$pat' expected $min times but got $n times" + return 1 + fi + continue + fi + if [ "$min" != '-' ]; then + if [ "$n" -lt "$min" ]; then + error "test '$ifile' failed" + error " Pattern '$pat' expected min $min times but got $n times" + return 1 + fi + fi + if [ "$max" != '-' ]; then + if [ "$n" -gt "$max" ]; then + error "test '$ifile' failed" + error " Pattern '$pat' expected max $max times but got $n times" + return 1 + fi + fi + done + + return $? +} + do_usage() { echo "$prog_name - a tiny automatic testing script" @@ -277,6 +320,13 @@ do_test() test_failed=1 fi fi + if [ $check_output_pattern_minmax -eq 1 ]; then + # verify the 'check-output-pattern(...)' tags + minmax_patterns "$file" 'check-output-pattern' $file.output.got + if [ "$?" -ne "0" ]; then + test_failed=1 + fi + fi [ "$test_failed" -eq "$must_fail" ] || failed=1 |
