From 77da4ce194f70ed1c271ae6e4184833ecf1b2146 Mon Sep 17 00:00:00 2001 From: Thomas Levine <_@thomaslevine.com> Date: Sun, 28 Feb 2016 19:18:54 +0000 Subject: [PATCH] generating tests --- tests/Single-file test suites/.test_testsuite | 23 +++++++++++ tests/Single-file test suites/exit 0 | 1 + tests/Single-file test suites/exit 1 | 1 + tests/Single-file test suites/exit 3 | 1 + tests/Single-file test suites/setup | 25 +----------- urchin | 39 ++++++++----------- 6 files changed, 44 insertions(+), 46 deletions(-) create mode 100755 tests/Single-file test suites/.test_testsuite create mode 100755 tests/Single-file test suites/exit 0 create mode 100755 tests/Single-file test suites/exit 1 create mode 100755 tests/Single-file test suites/exit 3 diff --git a/tests/Single-file test suites/.test_testsuite b/tests/Single-file test suites/.test_testsuite new file mode 100755 index 0000000..c951ee1 --- /dev/null +++ b/tests/Single-file test suites/.test_testsuite @@ -0,0 +1,23 @@ +#!/bin/sh +set -e + +testdir=$tmp/tests +mkdir -p $testdir +touch $testdir/.urchin +testcase=$testdir/testcase + +contents="$1" +expectation="$2" + +# Set up the test suite. +echo "$contents" > $testcase + +chmod +x $testcase +case "$expectation" in ok) regex='^ok 1 - testcase';; + not\ ok) regex='^not ok 1 - testcase';; + skip) regex='^ok 1 - testcase # SKIP';; + *) chmod -x $testcase;; +esac + +# Run the test suite +../../urchin -n -t $testdir | grep "$regex" diff --git a/tests/Single-file test suites/exit 0 b/tests/Single-file test suites/exit 0 new file mode 100755 index 0000000..60ec233 --- /dev/null +++ b/tests/Single-file test suites/exit 0 @@ -0,0 +1 @@ +.test_testsuite '' ok diff --git a/tests/Single-file test suites/exit 1 b/tests/Single-file test suites/exit 1 new file mode 100755 index 0000000..dd475ed --- /dev/null +++ b/tests/Single-file test suites/exit 1 @@ -0,0 +1 @@ +.test_testsuite false not\ ok diff --git a/tests/Single-file test suites/exit 3 b/tests/Single-file test suites/exit 3 new file mode 100755 index 0000000..31d1ee4 --- /dev/null +++ b/tests/Single-file test suites/exit 3 @@ -0,0 +1 @@ +.test_testsuite 'exit 3' skip diff --git a/tests/Single-file test suites/setup b/tests/Single-file test suites/setup index a8bd957..dde93d2 100644 --- a/tests/Single-file test suites/setup +++ b/tests/Single-file test suites/setup @@ -1,23 +1,2 @@ -tmp=$(mktemp -d) -testdir=$tmp/tests -touch "$testdir/.urchin" -testcase=$testdir/testcase - -test_testsuite() { - contents="$1" - expectation="$2" - - # Set up the test suite. - echo "$contents" > "$testcase" - - chmod +x $testcase - case "$expectation" in ok) regex='^ok 1 - testcase';; - not\ ok) regex='^not ok 1 - testcase';; - skip) regex='^ok 1 - testcase # SKIP';; - *) chmod -x $testcase;; - esac - - # Run the test suite - echo "#!/bin/sh -../../urchin -n -t '$testdir' | grep '$regex'" -} +export tmp=$(mktemp -d) +export PATH="$PWD:$PATH" diff --git a/urchin b/urchin index 12c9cb3..eff4da3 100755 --- a/urchin +++ b/urchin @@ -16,22 +16,15 @@ DEFAULT_SHELLS='sh bash dash mksh zsh' unset CDPATH # All temporary files go here -tmp=$(mktemp -d) -> $tmp/log +urchin_tmp=$(mktemp -d) +> $urchin_tmp/log urchin_exit() { - rm -Rf "$tmp" + rm -Rf "$urchin_tmp" exit "$@" } -# Source a setup or teardown file -urchin_source() { - if test -f "$1"; then - . ./"$1" > /dev/null - fi -} - stdout_file() { - x="$tmp/stdout$(fullpath "$1")" + x="$urchin_tmp/stdout$(fullpath "$1")" mkdir -p "$(dirname -- "$x")" echo "$x" } @@ -103,7 +96,7 @@ recurse() { if [ -d "$potential_test" ]; then ( cd -- "$potential_test" > /dev/null - urchin_source setup_dir + if test -f setup_dir; then . ./setup_dir; fi if [ -n "$ZSH_VERSION" ]; then # avoid "no matches found: *" error when directories are empty @@ -117,12 +110,12 @@ recurse() { fi ( - urchin_source setup + if test -f setup; then . ./setup; fi set +e recurse "$requested_path" "$test" "$cycle_shell" "$TEST_SHELL" exit_code=$? set -e - urchin_source teardown + if test -f teardown; then . ./teardown; fi exit $exit_code ) & @@ -130,13 +123,13 @@ recurse() { wait $! exit_code=$? if $exit_on_not_ok && test $exit_code -ne 0; then - urchin_source teardown_dir + if test -f teardown_dir; then . ./teardown_dir; fi urchin_exit 1 fi fi done wait - urchin_source teardown_dir + if test -f teardown_dir; then . ./teardown_dir; fi ) else if [ -x "$potential_test" ]; then @@ -155,7 +148,7 @@ recurse() { fi fi ( - urchin_source setup + if test -f setup; then . ./setup; fi # Run the test start=$(date +%s) @@ -173,7 +166,7 @@ recurse() { set -e finish=$(date +%s) - urchin_source teardown + if test -f teardown; then . ./setup; fi if [ $exit_code -eq 0 ]; then result=ok @@ -185,7 +178,7 @@ recurse() { elapsed=$(($finish - $start)) printf "${potential_test}\t${the_test_shell}\t${result}\t${elapsed}\n" \ - >> $tmp/log + >> $urchin_tmp/log exit "$exit_code" ) & @@ -193,7 +186,7 @@ recurse() { wait $! exit_code=$? if $exit_on_not_ok && test $exit_code -ne 0; then - urchin_source teardown_dir + if test -f teardown_dir; then . ./teardown_dir; fi return 1 fi fi @@ -201,7 +194,7 @@ recurse() { wait else # Shell is '' - printf "${potential_test}\t\tskip\t0\n" >> $tmp/log + printf "${potential_test}\t\tskip\t0\n" >> $urchin_tmp/log fi fi } @@ -426,7 +419,7 @@ validate_strings() { } cycle_shell=true -shell_list=$tmp/shell_list +shell_list=$urchin_tmp/shell_list run_in_series=false force=false exit_on_not_ok=false @@ -514,7 +507,7 @@ if basename "$(fullpath "$root")" | set -e finish=$(date +%s) - report_outcome "$root" $tap_format $tmp/log $start $finish + report_outcome "$root" $tap_format $urchin_tmp/log $start $finish urchin_exit $exit_code else