From deb77cb5de6aeedaa43cfa4e69c870dfae421065 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 16 Oct 2014 16:37:51 -0400 Subject: [PATCH] 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 --- .gitignore | 1 - HISTORY | 2 +- cross-shell-tests | 2 +- readme.md | 2 +- tests/.gitignore | 1 + ...D output (-xsd flag) should be documented. | 3 - ... something that does not look like a test. | 3 +- ... should contain no \"aoeuaoeuaoeu\" file." | 0 tests/XSD output should work./.fixture/fail | 3 - tests/XSD output should work./.fixture/pass | 3 - .../XSD output should produce XML. | 3 - tests/setup | 3 - tests/teardown | 0 urchin | 63 ++++++++++--------- 14 files changed, 40 insertions(+), 49 deletions(-) delete mode 100644 .gitignore delete mode 100755 tests/Command-line help contents/XSD output (-xsd flag) should be documented. rename "tests/Urchin should recognize that the filesystem is sane./The filesystem route should contain no \"aoeuaoeuaoeu\" file." => "tests/Urchin should recognize that the filesystem is sane./The filesystem root should contain no \"aoeuaoeuaoeu\" file." (100%) delete mode 100755 tests/XSD output should work./.fixture/fail delete mode 100755 tests/XSD output should work./.fixture/pass delete mode 100755 tests/XSD output should work./XSD output should produce XML. delete mode 100755 tests/setup delete mode 100755 tests/teardown diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5ca6e37..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.urchin_stdout diff --git a/HISTORY b/HISTORY index 8ba6389..b2a739e 100644 --- a/HISTORY +++ b/HISTORY @@ -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. diff --git a/cross-shell-tests b/cross-shell-tests index 21902a5..5f66f09 100755 --- a/cross-shell-tests +++ b/cross-shell-tests @@ -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 diff --git a/readme.md b/readme.md index 7ff9a12..ac17a37 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/tests/.gitignore b/tests/.gitignore index ea31835..0e4e582 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1 +1,2 @@ .urchin.log +.urchin_stdout diff --git a/tests/Command-line help contents/XSD output (-xsd flag) should be documented. b/tests/Command-line help contents/XSD output (-xsd flag) should be documented. deleted file mode 100755 index e4c5ceb..0000000 --- a/tests/Command-line help contents/XSD output (-xsd flag) should be documented. +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -../../urchin -h|grep -i xsd diff --git a/tests/Urchin should do a sanity check so that directories like the user home are not specified as tests./Urchin should warn if it is run on something that does not look like a test. b/tests/Urchin should do a sanity check so that directories like the user home are not specified as tests./Urchin should warn if it is run on something that does not look like a test. index 9ad7510..f3d5523 100755 --- a/tests/Urchin should do a sanity check so that directories like the user home are not specified as tests./Urchin should warn if it is run on something that does not look like a test. +++ b/tests/Urchin should do a sanity check so that directories like the user home are not specified as tests./Urchin should warn if it is run on something that does not look like a test. @@ -1,4 +1,3 @@ #!/bin/sh -mkdir /tmp/urchintmp -! ../../urchin /tmp/urchintmp +! ../../urchin ./.chainsaw diff --git "a/tests/Urchin should recognize that the filesystem is sane./The filesystem route should contain no \"aoeuaoeuaoeu\" file." "b/tests/Urchin should recognize that the filesystem is sane./The filesystem root should contain no \"aoeuaoeuaoeu\" file." similarity index 100% rename from "tests/Urchin should recognize that the filesystem is sane./The filesystem route should contain no \"aoeuaoeuaoeu\" file." rename to "tests/Urchin should recognize that the filesystem is sane./The filesystem root should contain no \"aoeuaoeuaoeu\" file." diff --git a/tests/XSD output should work./.fixture/fail b/tests/XSD output should work./.fixture/fail deleted file mode 100755 index 2bb8d86..0000000 --- a/tests/XSD output should work./.fixture/fail +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exit 1 diff --git a/tests/XSD output should work./.fixture/pass b/tests/XSD output should work./.fixture/pass deleted file mode 100755 index fa0c85b..0000000 --- a/tests/XSD output should work./.fixture/pass +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -exit diff --git a/tests/XSD output should work./XSD output should produce XML. b/tests/XSD output should work./XSD output should produce XML. deleted file mode 100755 index 7dd4b4e..0000000 --- a/tests/XSD output should work./XSD output should produce XML. +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -../../urchin .fixture | grep 'http://www.w3.org/2001/XMLSchema' diff --git a/tests/setup b/tests/setup deleted file mode 100755 index d03e04a..0000000 --- a/tests/setup +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -export variable_set_in_setup='value' diff --git a/tests/teardown b/tests/teardown deleted file mode 100755 index e69de29..0000000 diff --git a/urchin b/urchin index 4be7c54..1455772 100755 --- a/urchin +++ b/urchin @@ -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 " @@ -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