1 Commits

Author SHA1 Message Date
Thomas Levine
1737b4cbbb source setup and teardown 2016-02-26 16:32:52 +00:00
16 changed files with 46 additions and 71 deletions

31
HISTORY
View File

@@ -4,40 +4,9 @@ HISTORY
Version 0.0.7
---------------------
### Molly-guard
The Molly-guard is now more accepting. For example, you no longer need to
pass -f in this case: https://github.com/creationix/nvm/issues/357
### Skipping tests
Previously, tests were run if they were executable and were otherwise marked
as skipped. Now, an executable script can indicate that it is skipped by
exiting with code 3. For example, if a test requires some dependancy, it
might look for the dependency and then skip if it does not see the dependency.
It might look like this.
#!/bin/sh
if which inkscape; then
exit 3 # status code 3 for skip
fi
inkscape blah blah ...
I chose status code 3 sort of arbitrarily at first, but it turns out that it
would the appropriate status code if these tests were Nagios plugins, as the
concept of skipping a test is similar to the Nagios concept of unknown service
status (https://nagios-plugins.org/doc/guidelines.html#AEN78).
### Run on a file
It is now possible to run urchin on a single file.
This occurred to me when I wanted to run
urchin test/fast/Unit\ tests/nvm_ls_current
on the nvm tests. I wound up running this instead.
urchin test/fast/Unit\ tests/ | grep nvm_ls_current
The Molly guard is assessed, and the corresponding setup, setup_dir,
teardown, and teardown_dir files are run in the appropriate order.
Version 0.0.6
---------------------

16
TODO
View File

@@ -123,6 +123,22 @@ cleanly create and teardown temporary files.
On the other hand, this could just be sourced explicitly in the test file,
without the special setup and teardown feature.
Run on a file
----------------
Presently you can run urchin only on a directory.
It would be neat if you could run it on a file as well.
This occurred to me when I wanted to run
urchin test/fast/Unit\ tests/nvm_ls_current
on the nvm tests. I wound up running this instead.
urchin test/fast/Unit\ tests/ | grep nvm_ls_current
The Molly guard would be assessed, and the corresponding setup, setup_dir,
teardown, and teardown_dir files would be run in the appropriate order.
Running automated tasks
-------------------------
Urchin might be appropriate for if you have lots of tasks that you want to run

View File

@@ -1 +0,0 @@
echo setup

View File

@@ -1 +0,0 @@
echo setup_dir

View File

@@ -1 +0,0 @@
echo teardown

View File

@@ -1 +0,0 @@
echo teardown_dir

View File

@@ -1,2 +0,0 @@
echo thetest
exit 1

View File

@@ -1,3 +0,0 @@
#!/bin/sh
../../urchin .test
# This will exit 0 if it worked.

View File

@@ -1,2 +0,0 @@
#!/bin/sh
! ../../urchin not-a-file

View File

@@ -1,4 +0,0 @@
tmp=$(mktemp)
echo "Using temp file $tmp"
../../urchin .wrappers > $tmp
diff $tmp .wrapper-expectation

View File

@@ -1 +0,0 @@
exit 1

View File

@@ -1 +0,0 @@
exit 3

View File

@@ -1 +0,0 @@
exit 0

View File

@@ -1 +0,0 @@
test $(../../urchin -t .test/ | grep -c SKIP) -eq 1

51
urchin
View File

@@ -16,6 +16,13 @@ unset CDPATH
# Urchin version number
VERSION=0.0.6
fullpath() {
(
cd -- "$1"
pwd
)
}
indent() {
level="$1"
if test "$level" -gt 0; then
@@ -48,7 +55,7 @@ recurse() {
(
cd -- "$potential_test"
[ -f setup_dir ] && [ -x setup_dir ] && ./setup_dir >> "$stdout_file"
[ -f setup_dir ] && [ -x setup_dir ] && . ./setup_dir >> "$stdout_file"
if [ -n "$ZSH_VERSION" ]; then
# avoid "no matches found: *" error when directories are empty
@@ -57,21 +64,21 @@ recurse() {
for test in *
do
[ -f setup ] && [ -x setup ] && ./setup >> "$stdout_file"
[ -f setup ] && [ -x setup ] && . ./setup >> "$stdout_file"
# $2 instead of $indent_level so it doesn't clash
recurse "${test}" $(( $2 + 1 )) "$shell_for_sh_tests"
exit_code=$?
if $exit_on_fail && test $exit_code -ne 0; then
[ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file"
[ -f teardown ] && [ -x teardown ] && . ./teardown >> "$stdout_file"
[ -f teardown_dir ] && [ -x teardown_dir ] && . ./teardown_dir >> "$stdout_file"
return 1
fi
[ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
[ -f teardown ] && [ -x teardown ] && . ./teardown >> "$stdout_file"
done
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> "$stdout_file"
[ -f teardown_dir ] && [ -x teardown_dir ] && . ./teardown_dir >> "$stdout_file"
)
if $tap_format; then
indent $indent_level | sed 's/ /#/g'
@@ -82,7 +89,7 @@ recurse() {
else
if [ -x "$potential_test" ]
then
[ -f setup ] && [ -x setup ] && ./setup >> "$stdout_file"
[ -f setup ] && [ -x setup ] && . ./setup >> "$stdout_file"
# Run the test
if [ -n "$shell_for_sh_tests" ] && has_sh_or_no_shebang_line ./"$potential_test"
@@ -93,11 +100,9 @@ recurse() {
fi
exit_code="$?"
[ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
[ -f teardown ] && [ -x teardown ] && . ./teardown >> "$stdout_file"
if [ $exit_code -eq 0 ]; then
result=success
elif [ $exit_code -eq 3 ]; then
result=skip
else
result=fail
fi
@@ -277,7 +282,7 @@ do
which "$shell_for_sh_tests" > /dev/null || {
echo "Cannot find specified shell: '$shell_for_sh_tests'" >&2
urchin_help >&2
exit 11
exit 2
} ;;
-t) tap_format=true;;
-h|--help) urchin_help
@@ -291,17 +296,21 @@ do
shift
done
# Verify argument for main stuff
if [ "$#" != '1' ] || [ ! -d "$1" ]
then
[ -n "$1" ] && [ ! -d "$1" ] && echo "Not a directory: '$1'" >&2
echo "$USAGE" >&2
exit 2
fi
# Constants
logfile=$(fullpath "$1")/.urchin.log
stdout_file=$(fullpath "$1")/.urchin_stdout
# Run or present the Molly guard.
thetest=$(readlink -f "$1")
if echo "$thetest" | grep -Fi 'test' > /dev/null || $force; then
if test -d "$1"; then
d="$thetest"
else
d=$(echo "$thetest" | sed 's/\/[^\/]\{1,\}$//')
cd "$d"
fi
logfile="$d/.urchin.log"
stdout_file="$d/.urchin_stdout"
if fullpath "$1" | grep -Fi 'test' > /dev/null || $force
then
urchin_go "$1" "$shell_for_sh_tests"
else
urchin_molly_guard