Various bug fixes and cleanup.

* bug fixes:
  * fixed directory-existence argument check
  * fixed how `.urchin_stdout` files are cleaned up
  * fixed instances of error/warning messages outputting to stdout instead of stderr
* documentation, help and error-message improvements:
  * added specific error message if the (non-option) argument is not a directory
  * improved wording of CLI help
  * readme.md: replaced obsolete URL http://www.urchin.sh with https://github.com/scraperwiki/urchin
  * readme.md: made the fact clearer that `./cross-shell-tests` only tests urchin's _own_ cross-shell compatibility
  * HISTORY: fixed typo
* formatting and logging improvements:
  * added timestamp to the beginning of log files (`.urchin.log`)
  * captured output from failed tests is now printed in *red* to draw attention
  * test summary now prints the number of failed tests in the appropriate color for instant feedback (green, if none failed; red, otherwise)
* cleanup
  * removed unused test files, simplified some tests
This commit is contained in:
Michael Klement 2014-10-16 16:37:51 -04:00
parent f12636e029
commit deb77cb5de
14 changed files with 40 additions and 49 deletions

1
.gitignore vendored
View File

@ -1 +0,0 @@
.urchin_stdout

View File

@ -13,6 +13,6 @@ We added flags for verbosity and for Molly guards
Done
-----
We adjusted the input parameters so it is harder to accidentally run all executible files in your home directory.
We adjusted the input parameters so it is harder to accidentally run all executable files in your home directory.
We added directory-based indents.

View File

@ -6,7 +6,7 @@ for shell in dash bash ksh zsh; do
if which $shell > /dev/null 2> /dev/null; then
echo
echo Running urchin tests in $shell
$shell urchin tests | tail -n 2
$shell urchin tests | tail -n 3
else
echo
echo Skipping $shell because it is not in the PATH

View File

@ -21,7 +21,7 @@ Run the tests
The above command will run the tests in your systems default
shell, /bin/sh (on recent Ubuntu this is dash, but it could be
ksh or bash on other systems); to test cross-shell compatibility,
ksh or bash on other systems); to test urchin's cross-shell compatibility,
run this:
cd urchin

1
tests/.gitignore vendored
View File

@ -1 +1,2 @@
.urchin.log
.urchin_stdout

View File

@ -1,3 +0,0 @@
#!/bin/sh
../../urchin -h|grep -i xsd

View File

@ -1,3 +0,0 @@
#!/bin/sh
exit 1

View File

@ -1,3 +0,0 @@
#!/bin/sh
exit

View File

@ -1,3 +0,0 @@
#!/bin/sh
../../urchin .fixture | grep 'http://www.w3.org/2001/XMLSchema'

View File

@ -1,3 +0,0 @@
#!/bin/sh
export variable_set_in_setup='value'

View File

63
urchin
View File

@ -21,7 +21,7 @@ recurse() {
[ "$potential_test" = 'setup' ] && return
[ "$potential_test" = 'teardown' ] && return
echo > "$stdout_file"
[ $indent_level -eq 0 ] && : > "$stdout_file"
if [ -d "$potential_test" ]
then
@ -54,9 +54,9 @@ recurse() {
[ -f teardown ] && [ -x teardown ] && ./teardown >> "$stdout_file"
indent $indent_level
if [ "$exit_code" = '0' ]
if [ $exit_code -eq 0 ]
then
# On success, print a '✓'
# On success, print a green '✓'
printf '\033[32m✓ \033[0m'
printf '%s\n' "${potential_test}"
printf '%s\n' "${potential_test} passed" >> "$logfile"
@ -65,10 +65,12 @@ recurse() {
printf '\033[31m✗ \033[0m'
printf '%s\n' "${potential_test}"
printf '%s\n' "${potential_test} failed" >> "$logfile"
printf '\033[31m' # Print output captured from failed test in red.
cat "$stdout_file"
printf '\033[0m'
fi
rm "$stdout_file"
fi
[ $indent_level -eq 0 ] && rm "$stdout_file"
}
USAGE="usage: $0 <test directory>"
@ -77,12 +79,13 @@ urchin_help() {
echo
echo "$USAGE"
echo
echo '-f Force urchin to run on directories not named "test".'
echo '-f Force urchin to run on directories whose name does not contain'
echo ' the word "test".'
echo '-h This help'
# echo
# echo '--xsd Output xUnit XML schema for an integration server.'
echo
echo '--xsd Output xUnit XML schema for an integration server.'
echo
echo 'Go to http://www.urchin.sh for documentation on writing tests.'
echo 'Go to https://github.com/scraperwiki/urchin for documentation on writing tests.'
echo
}
@ -99,36 +102,39 @@ plural () {
}
urchin_go() {
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S)
echo Running tests at $(date +%Y-%m-%dT%H:%M:%S) | tee "$logfile"
start=$(date +%s)
echo > "$logfile"
recurse "$1" 0
recurse "$1" 0 # test folder, indentation level
finish=$(date +%s)
elapsed=$(($finish - $start))
echo Done, took $elapsed $(plural second $elapsed)
echo "Done, took $elapsed $(plural second $elapsed)."
set -- $(grep -e 'passed$' "$logfile"|wc -l) $(grep -e 'failed$' "$logfile"|wc -l)
printf '%s\n' "$1 $(plural test "$1") passed."
[ $2 -gt 0 ] && printf '\033[31m' || printf '\033[32m' # If tests failed, print the message in red, otherwise in green.
printf '%s\n' "$2 $(plural test "$2") failed."
printf '\033[m'
return "$2"
}
urchin_molly_guard() {
echo
echo 'The directory on which you are running urchin is not'
echo 'called "test", so I am not running in case that'
echo 'was an accident. Use the -f flag if you really want'
echo 'to run urchin on that directory.'
echo
{
echo
echo 'The name of the directory on which you are running urchin'
echo 'does not contain the word "test", so I am not running,'
echo 'in case that was an accident. Use the -f flag if you really'
echo 'want to run urchin on that directory.'
echo
} >&2
exit 1
}
FORCE=false
force=false
while [ $# -gt 0 ]
do
case "$1" in
-f) FORCE=true;;
-f) force=true;;
-h|--help) urchin_help
exit 0;;
# --xsd) action=testsuite;;
@ -140,19 +146,20 @@ do
shift
done
# Verify argument for main stuff
if [ "$#" != '1' ] || [ ! -d "$1" ]
then
[ -d "$1" ] || echo "Not a directory: '$1'" >&2
echo "$USAGE" >&2
exit 1
fi
# Constants
logfile=$(fullpath "$1")/.urchin.log
stdout_file=$(fullpath "$1")/.urchin_stdout
# Verify argument for main stuff
if [ "$#" != '1' ] && [ ! -d "$1" ]
then
echo "$USAGE"
exit 1
fi
# Run or present the Molly guard.
if basename "$(fullpath "$1")" | grep test > /dev/null || $FORCE
if basename "$(fullpath "$1")" | grep -Fi 'test' > /dev/null || $force
then
urchin_go "$1"
else