diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-22 21:57:23 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-22 21:57:23 -0400 |
commit | 8ced9df08fdfc293023b9ef624d7b5bb8c4fb3c9 (patch) | |
tree | ec68b71a6759bc4d082f32748c84c7a219be82cd /test | |
parent | e8e28c794bfb12fe1c9562c5bd124688ce45fc8e (diff) | |
download | fork-ledger-8ced9df08fdfc293023b9ef624d7b5bb8c4fb3c9.tar.gz fork-ledger-8ced9df08fdfc293023b9ef624d7b5bb8c4fb3c9.tar.bz2 fork-ledger-8ced9df08fdfc293023b9ef624d7b5bb8c4fb3c9.zip |
Added a command-line test runner named test/run
Diffstat (limited to 'test')
-rwxr-xr-x | test/run | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/run b/test/run new file mode 100755 index 00000000..b0da1b6e --- /dev/null +++ b/test/run @@ -0,0 +1,45 @@ +#!/bin/bash + +LEDGER=ledger +ARGS="--args-only --no-color --columns=80" + +output_only=false +update_test=false +if [[ "$1" == "-v" ]]; then + output_only=true + shift 1 +elif [[ "$1" == "-u" ]]; then + update_test=true + shift 1 +fi + +COMMAND=$(perl -ne 'print unless /^<<</ .. eof();' $1) + +if [[ $output_only == false && $update_test == false ]]; then + perl -ne 'print unless 1 .. /^>>>/ or /^(===|>>>2)/ .. eof();' $1 > /tmp/expected.$$ +fi + +perl -ne 'print unless 1 .. /^<<</ or /^>>>/ .. eof();' $1 \ + | eval "$LEDGER -f - -o /tmp/received.$$ $ARGS $COMMAND" + +if [[ $update_test == true ]]; then + if [[ -f /tmp/received.$$ ]]; then + perl -ne 'print if 1 .. /^>>>/;' $1 > /tmp/command.$$ + perl -ne 'print if /^(===|>>>2)/ .. eof();' $1 > /tmp/epilog.$$ + cat /tmp/command.$$ /tmp/received.$$ /tmp/epilog.$$ > replace.$$ + mv replace.$$ $1 + /bin/rm -f /tmp/command.$$ /tmp/received.$$ /tmp/epilog.$$ + echo Test updated. + fi + +elif [[ $output_only == false ]]; then + if [[ -f /tmp/expected.$$ && -f /tmp/received.$$ ]]; then + diff -w -U3 /tmp/expected.$$ /tmp/received.$$ && echo Test passed. + fi +else + if [[ -f /tmp/received.$$ ]]; then + cat /tmp/received.$$ + fi +fi + +/bin/rm -f /tmp/expected.$$ /tmp/received.$$ |