From 9d1d2be6a6a345fed2f31f9f375b2572ba146c04 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 31 Oct 2018 07:30:14 +0100 Subject: [PATCH] test: Add expectations. * check.sh: New file, from test.sh. * test.sh: Run single test with expectations. --- .gitignore | 3 ++ check.sh | 81 ++++++++++++++++++++++++++++++++++ makefile | 8 ++-- test.sh | 40 ++++++++++------- test/06-assignment-echo.stdout | 1 + 5 files changed, 112 insertions(+), 21 deletions(-) create mode 100755 check.sh create mode 100644 test/06-assignment-echo.stdout diff --git a/.gitignore b/.gitignore index d5690d4..8815e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,6 @@ /doc/version.texi /gash/config.scm /pre-inst-env +/test/*.1 +/test/*.2 +/test/*.log diff --git a/check.sh b/check.sh new file mode 100755 index 0000000..62fd478 --- /dev/null +++ b/check.sh @@ -0,0 +1,81 @@ +if [ -n "$V" ]; then + set -x +fi +DIFF=diff +SHELL=${SHELL-bin/gash} +#SHELL=bin/gash + +tests=" +assign +assign2 +for +for-split-sequence +find +if2 +iohere +list +ls +nesting +pipe +substitution +00-exit +01-exit-0 +02-exit-1 +03-echo +04-echo-var +05-assignment-doublequoted-doublequotes +05-assignment +06-assignment-echo +06-assignment-singlequote +07-assignment-double-quote +08-assignment-variable-word +09-compound-word +0a-assign-substitute +0b-command-compound-word +10-if +11-if-false +20-pipe-exit-0 +21-pipe-exit-1 +22-semi-pipe-exit-0 +30-assignment-substitution +30-eval +31-eval-echo-variable +32-for-substitute +33-string-args +35-assignment-eval-echo +" + +broken=" + +" + +expect=$(echo $broken | wc -w) +pass=0 +fail=0 +total=0 +for t in $tests; do + sh test.sh "test/$t" &> test/"$t".log + r=$? + total=$((total+1)) + if [ $r = 0 ]; then + echo $t: [OK] + pass=$((pass+1)) + else + echo $t: [FAIL] + fail=$((fail+1)) + fi +done + +[ $expect != 0 ] && echo "expect: $expect" +[ $fail != 0 ] && echo "failed: $fail" +[ $fail -lt $expect ] && echo "solved: $(($expect - $fail))" +echo "passed: $pass" +echo "total: $total" +if [ $fail != 0 -a $fail -gt $expect ]; then + echo FAILED: $fail/$total + exit 1 +elif [ $fail != 0 ]; then + echo PASS: $pass/$total +else + echo PASS: $total +fi diff --git a/makefile b/makefile index 0fe88bd..62a7df9 100644 --- a/makefile +++ b/makefile @@ -11,9 +11,9 @@ bin/tar: bin/tar.in | do-configure do-configure: ./configure --prefix=$(prefix) -all: all-go do-configure +all: all-go -all-go: +all-go: | do-configure build-aux/build-guile.sh clean: @@ -26,11 +26,11 @@ check: all check-bash check-gash check-bash: all ifneq ($(BASH),) - SHELL=$(BASH) ./test.sh + SHELL=$(BASH) ./check.sh endif check-gash: all - SHELL=bin/gash ./test.sh + SHELL=bin/gash ./check.sh install: all mkdir -p $(DESTDIR)$(bindir) diff --git a/test.sh b/test.sh index cda17f0..babfbe9 100755 --- a/test.sh +++ b/test.sh @@ -1,19 +1,25 @@ -if [ -n "$BUILD_DEBUG" ]; then +set -e +if [ -n "$V" ]; then set -x fi -#SHELL=${SHELL-bin/gash} -SHELL=bin/gash -for f in test/*.sh; do - echo -n "$f: " - b=test/$(basename $f .sh) -# $SHELL --geesh -e $f - $SHELL -e $f - r=$? - if [ -f $b.exit ]; then - e=$(cat $b.exit) - else - e=0 - fi - [ $r = $e ] || exit 1 - echo pass -done +DIFF=${DIFF-diff} +SHELL=${SHELL-bin/gash} + +t=$1 +b=test/$(basename $t .sh) +set +e +$SHELL -e $b.sh > $b.1 2> $b.2 +r=$? +set -e +if [ -f $b.exit ]; then + e=$(cat $b.exit) +else + e=0 +fi +[ $r = $e ] || exit 1 +if [ -f $b.stdout ]; then + $DIFF -u $b.stdout $b.1 +fi +if [ -f $b.stderr ]; then + $DIFF -u $b.stderr $b.2 +fi diff --git a/test/06-assignment-echo.stdout b/test/06-assignment-echo.stdout new file mode 100644 index 0000000..01dca2d --- /dev/null +++ b/test/06-assignment-echo.stdout @@ -0,0 +1 @@ +/bin/bash