generating tests

This commit is contained in:
Thomas Levine 2016-02-28 19:18:54 +00:00
parent 87d5aec23c
commit 77da4ce194
6 changed files with 44 additions and 46 deletions

View File

@ -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"

View File

@ -0,0 +1 @@
.test_testsuite '' ok

View File

@ -0,0 +1 @@
.test_testsuite false not\ ok

View File

@ -0,0 +1 @@
.test_testsuite 'exit 3' skip

View File

@ -1,23 +1,2 @@
tmp=$(mktemp -d) export tmp=$(mktemp -d)
testdir=$tmp/tests export PATH="$PWD:$PATH"
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'"
}

39
urchin
View File

@ -16,22 +16,15 @@ DEFAULT_SHELLS='sh bash dash mksh zsh'
unset CDPATH unset CDPATH
# All temporary files go here # All temporary files go here
tmp=$(mktemp -d) urchin_tmp=$(mktemp -d)
> $tmp/log > $urchin_tmp/log
urchin_exit() { urchin_exit() {
rm -Rf "$tmp" rm -Rf "$urchin_tmp"
exit "$@" exit "$@"
} }
# Source a setup or teardown file
urchin_source() {
if test -f "$1"; then
. ./"$1" > /dev/null
fi
}
stdout_file() { stdout_file() {
x="$tmp/stdout$(fullpath "$1")" x="$urchin_tmp/stdout$(fullpath "$1")"
mkdir -p "$(dirname -- "$x")" mkdir -p "$(dirname -- "$x")"
echo "$x" echo "$x"
} }
@ -103,7 +96,7 @@ recurse() {
if [ -d "$potential_test" ]; then if [ -d "$potential_test" ]; then
( (
cd -- "$potential_test" > /dev/null cd -- "$potential_test" > /dev/null
urchin_source setup_dir if test -f setup_dir; then . ./setup_dir; fi
if [ -n "$ZSH_VERSION" ]; then if [ -n "$ZSH_VERSION" ]; then
# avoid "no matches found: *" error when directories are empty # avoid "no matches found: *" error when directories are empty
@ -117,12 +110,12 @@ recurse() {
fi fi
( (
urchin_source setup if test -f setup; then . ./setup; fi
set +e set +e
recurse "$requested_path" "$test" "$cycle_shell" "$TEST_SHELL" recurse "$requested_path" "$test" "$cycle_shell" "$TEST_SHELL"
exit_code=$? exit_code=$?
set -e set -e
urchin_source teardown if test -f teardown; then . ./teardown; fi
exit $exit_code exit $exit_code
) & ) &
@ -130,13 +123,13 @@ recurse() {
wait $! wait $!
exit_code=$? exit_code=$?
if $exit_on_not_ok && test $exit_code -ne 0; then 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 urchin_exit 1
fi fi
fi fi
done done
wait wait
urchin_source teardown_dir if test -f teardown_dir; then . ./teardown_dir; fi
) )
else else
if [ -x "$potential_test" ]; then if [ -x "$potential_test" ]; then
@ -155,7 +148,7 @@ recurse() {
fi fi
fi fi
( (
urchin_source setup if test -f setup; then . ./setup; fi
# Run the test # Run the test
start=$(date +%s) start=$(date +%s)
@ -173,7 +166,7 @@ recurse() {
set -e set -e
finish=$(date +%s) finish=$(date +%s)
urchin_source teardown if test -f teardown; then . ./setup; fi
if [ $exit_code -eq 0 ]; then if [ $exit_code -eq 0 ]; then
result=ok result=ok
@ -185,7 +178,7 @@ recurse() {
elapsed=$(($finish - $start)) elapsed=$(($finish - $start))
printf "${potential_test}\t${the_test_shell}\t${result}\t${elapsed}\n" \ printf "${potential_test}\t${the_test_shell}\t${result}\t${elapsed}\n" \
>> $tmp/log >> $urchin_tmp/log
exit "$exit_code" exit "$exit_code"
) & ) &
@ -193,7 +186,7 @@ recurse() {
wait $! wait $!
exit_code=$? exit_code=$?
if $exit_on_not_ok && test $exit_code -ne 0; then 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 return 1
fi fi
fi fi
@ -201,7 +194,7 @@ recurse() {
wait wait
else else
# Shell is '' # Shell is ''
printf "${potential_test}\t\tskip\t0\n" >> $tmp/log printf "${potential_test}\t\tskip\t0\n" >> $urchin_tmp/log
fi fi
fi fi
} }
@ -426,7 +419,7 @@ validate_strings() {
} }
cycle_shell=true cycle_shell=true
shell_list=$tmp/shell_list shell_list=$urchin_tmp/shell_list
run_in_series=false run_in_series=false
force=false force=false
exit_on_not_ok=false exit_on_not_ok=false
@ -514,7 +507,7 @@ if basename "$(fullpath "$root")" |
set -e set -e
finish=$(date +%s) 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 urchin_exit $exit_code
else else