diff --git a/test/122_no_config_file_dir.txt b/test/122_no_config_file_dir.txt new file mode 100644 index 0000000..f79791b --- /dev/null +++ b/test/122_no_config_file_dir.txt @@ -0,0 +1,10 @@ +:DESC +Like 003, but the argument to -f exists and is a directory, but does not contain the config. + +:ARGS +-f . +:INPUT +:OUTPUT-FILTER +:EXPECTED-ERROR 1 +boxes: Couldn't find config file in directory '.' +:EOF diff --git a/test/123_config_file_xdg1.txt b/test/123_config_file_xdg1.txt new file mode 100644 index 0000000..edb17ee --- /dev/null +++ b/test/123_config_file_xdg1.txt @@ -0,0 +1,17 @@ +:DESC +Tests that the config file is found by looking in $HOME/.config/boxes. +Also tests a shape length problem, where the least common multiple must be found (here: 3 x 5 = 15). + +:SKIP-IF +Msys +:ENV +export HOME="`pwd`/123_data" +:ARGS +:INPUT +foo +:OUTPUT-FILTER +:EXPECTED +#123123123123123# +#foo # +#123451234512345# +:EOF diff --git a/test/123_data/.config/boxes/boxes-config b/test/123_data/.config/boxes/boxes-config new file mode 100644 index 0000000..f6d8dbc --- /dev/null +++ b/test/123_data/.config/boxes/boxes-config @@ -0,0 +1,27 @@ +# Config file with a design that requires the least common multiple of shape lengths (3 and 5 cols). + +BOX test1 + +author "Thomas Jensen" +designer "Thomas Jensen" + +sample + #123123123123123# + #sample # + #123451234512345# +ends + +shapes { + nw ("#") + n ("123") + s ("12345") + + se ("#") e ("#") sw ("#") ne ("#") w ("#") +} + +elastic (n,s,e, w) + +END test1 + + +#EOF vim: set ai sw=4: diff --git a/test/124_config_file_xdg2.txt b/test/124_config_file_xdg2.txt new file mode 100644 index 0000000..3263257 --- /dev/null +++ b/test/124_config_file_xdg2.txt @@ -0,0 +1,18 @@ +:DESC +Tests that the config file is found by looking in $XDG_CONFIG_HOME/boxes with higher precedence +than $HOME/.config/boxes. Also tests a particular shape length problem. + +:SKIP-IF +Msys +:ENV +export HOME="`pwd`/124_data/home" +export XDG_CONFIG_HOME="`pwd`/124_data/xdg" +:ARGS +:INPUT +foo +:OUTPUT-FILTER +:EXPECTED +#--123123# +#foo # +#12345---# +:EOF diff --git a/test/124_data/home/.config/boxes/boxes-config b/test/124_data/home/.config/boxes/boxes-config new file mode 100644 index 0000000..41c5653 --- /dev/null +++ b/test/124_data/home/.config/boxes/boxes-config @@ -0,0 +1,23 @@ +# This file should NOT be used! + +BOX wrong + +author "Thomas Jensen" +designer "Thomas Jensen" + +sample + #-WRONG-# + #sample # + #-WRONG-# +ends + +shapes { + nw ("#") + n ("-WRONG-") + s ("-WRONG-") + se ("#") e ("#") sw ("#") ne ("#") w ("#") +} + +elastic (n, s, e, w) + +END wrong diff --git a/test/124_data/xdg/boxes/boxes-config b/test/124_data/xdg/boxes/boxes-config new file mode 100644 index 0000000..bf062dd --- /dev/null +++ b/test/124_data/xdg/boxes/boxes-config @@ -0,0 +1,24 @@ +# A design that offsets the least common multiple effect by nnw/sse shapes. + +BOX test2 + +author "Thomas Jensen" +designer "Thomas Jensen" + +sample #--123123# + #sample # + #12345---# +ends + +shapes { + nw ("#") + nnw ("--") sse ("---") + n ("123") + s ("12345") + + se ("#") e ("#") sw ("#") ne ("#") w ("#") +} + +elastic (n,s,e, w) + +END test2 diff --git a/test/125_config_file_wrong_BOXES_var.txt b/test/125_config_file_wrong_BOXES_var.txt new file mode 100644 index 0000000..bb1b7e7 --- /dev/null +++ b/test/125_config_file_wrong_BOXES_var.txt @@ -0,0 +1,11 @@ +:DESC +When $BOXES points to the wrong place, that's always an error. + +:ENV +export BOXES=non-existent +:ARGS +:INPUT +:OUTPUT-FILTER +:EXPECTED-ERROR 1 +boxes: Couldn't find config file at 'non-existent' from BOXES environment variable +:EOF diff --git a/test/126_config_file_xdg3.txt b/test/126_config_file_xdg3.txt new file mode 100644 index 0000000..bc7a9a2 --- /dev/null +++ b/test/126_config_file_xdg3.txt @@ -0,0 +1,15 @@ +:DESC +Because of historic boxes behavior, a config file in $HOME has precedence over one in $XDG_CONFIG_HOME/boxes. + +:ENV +export HOME="`pwd`/126_data/home" +export XDG_CONFIG_HOME="`pwd`/126_data/xdg" +:ARGS +:INPUT +foo +:OUTPUT-FILTER +:EXPECTED +#123123---456# +#foo # +#12345<>67890# +:EOF diff --git a/test/126_data/home/boxes-config b/test/126_data/home/boxes-config new file mode 100644 index 0000000..f4d3893 --- /dev/null +++ b/test/126_data/home/boxes-config @@ -0,0 +1,27 @@ +# A design with particular shape lengths. + +BOX test3 + +author "Thomas Jensen" +designer "Thomas Jensen" + +sample + #123123---456# + #sample # + #12345<>67890# +ends + +shapes { + nnw ("123") + nne ("456") + n ("---") + s ("<>") + ssw ("12345") + sse ("67890") + + nw ("#") se ("#") e ("#") sw ("#") ne ("#") w ("#") +} + +elastic (nne, nnw, ssw, sse, e, w) + +END test3 diff --git a/test/126_data/xdg/boxes/boxes-config b/test/126_data/xdg/boxes/boxes-config new file mode 100644 index 0000000..41c5653 --- /dev/null +++ b/test/126_data/xdg/boxes/boxes-config @@ -0,0 +1,23 @@ +# This file should NOT be used! + +BOX wrong + +author "Thomas Jensen" +designer "Thomas Jensen" + +sample + #-WRONG-# + #sample # + #-WRONG-# +ends + +shapes { + nw ("#") + n ("-WRONG-") + s ("-WRONG-") + se ("#") e ("#") sw ("#") ne ("#") w ("#") +} + +elastic (n, s, e, w) + +END wrong diff --git a/test/test-config-unused.cfg b/test/test-config-unused.cfg index 76043f8..50252c1 100644 --- a/test/test-config-unused.cfg +++ b/test/test-config-unused.cfg @@ -2,86 +2,10 @@ # Currently unused. -BOX test1 - -author "Thomas Jensen " -designer "Thomas Jensen " - -sample test1 -ends - -shapes { - nw ("#") - n ("123") - s ("12345") - - se ("#") e ("#") sw ("#") ne ("#") w ("#") -} - -elastic (n,s,e, w) - -END test1 - - -# ============================================================================ - - -BOX test2 - -author "Thomas Jensen " -designer "Thomas Jensen " - -sample test2 -ends - -shapes { - nw ("#") - nnw ("--") sse ("---") - n ("123") - s ("12345") - - se ("#") e ("#") sw ("#") ne ("#") w ("#") -} - -elastic (n,s,e, w) - -END test2 - - -# ============================================================================ - - -BOX test3 - -author "Thomas Jensen " -designer "Thomas Jensen " - -sample test3 -ends - -shapes { - nnw ("123") - nne ("456") - n ("---") - s ("<>") - ssw ("12345") - sse ("67890") - - nw ("#") se ("#") e ("#") sw ("#") ne ("#") w ("#") -} - -elastic (nne,nnw,ssw,sse,e, w) - -END test3 - - -# ============================================================================ - - BOX test4 -author "Thomas Jensen " -designer "Thomas Jensen " +author "Thomas Jensen" +designer "Thomas Jensen" sample test4 ends @@ -103,8 +27,8 @@ END test4 BOX test5 -author "Thomas Jensen " -designer "Thomas Jensen " +author "Thomas Jensen" +designer "Thomas Jensen" sample test5 ends @@ -128,8 +52,8 @@ END test5 BOX test6 -author "Thomas Jensen " -designer "Thomas Jensen " +author "Thomas Jensen" +designer "Thomas Jensen" sample test6 ends @@ -155,8 +79,8 @@ END test6 BOX retest -author "Thomas Jensen " -designer "Thomas Jensen " +author "Thomas Jensen" +designer "Thomas Jensen" revision "1.1" revdate "August 18, 1999 (Wednesday, 17:07h)" created "April 04, 1999 (Sunday, 18:00h)" @@ -175,7 +99,7 @@ shapes { nw ("*") ne ("*") sw ("*") se ("*") elastic (n,e,s,W) replace once "bar" with "raba-raba" -replace global "f(o)o" with "fu\1\1\1\1\1\1" +replace global "f(o)o" with "fu$1$1$1$1$1$1" replace "--" with "++++" END retest diff --git a/test/testrunner.sh b/test/testrunner.sh index 702ccf9..674d396 100755 --- a/test/testrunner.sh +++ b/test/testrunner.sh @@ -59,6 +59,24 @@ for sectionName in :ARGS :INPUT :OUTPUT-FILTER :EXPECTED :EOF; do fi done +declare boxesSkipIf="" +declare -r boxesCurrentOs=`uname -o` +if [ $(grep -c "^:SKIP-IF" $testCaseFile) -eq 1 ]; then + boxesSkipIf=$(cat $testCaseFile | sed -n '/^:SKIP-IF/,/^:ARGS/p;' | sed '1d;$d' | tr -d '\r') + if [[ $boxesSkipIf == *":ENV"* ]]; then + boxesSkipIf=$(echo ${boxesSkipIf%:ENV*} | head -c -1 | tr -d '\r') + fi +fi +if [ $(echo $boxesSkipIf | xargs -n1 echo | grep -e "^$boxesCurrentOs$" | wc -l) -eq 1 ]; then + echo " Skipping test because operating system is \"$boxesCurrentOs\"." + exit 0 +fi + +declare boxesEnv="" +if [ $(grep -c "^:ENV" $testCaseFile) -eq 1 ]; then + boxesEnv=$(cat $testCaseFile | sed -n '/^:ENV/,/^:ARGS/p;' | sed '1d;$d' | tr -d '\r') +fi + declare -i expectedReturnCode=0 if [ $(grep -c "^:EXPECTED-ERROR " $testCaseFile) -eq 1 ]; then expectedReturnCode=$(grep "^:EXPECTED-ERROR " $testCaseFile | sed -e 's/:EXPECTED-ERROR //') @@ -79,9 +97,14 @@ if [ ! -x $boxesBinary ]; then boxesBinary=../src/boxes fi -echo " Invoking: $(basename $boxesBinary) $boxesArgs" -export BOXES=../boxes-config +if [ ! -z "$boxesEnv" ]; then + echo $boxesEnv | sed -e 's/export/\n export/g' | sed '1d' + eval $boxesEnv +else + export BOXES=../boxes-config +fi +echo " Invoking: $(basename $boxesBinary) $boxesArgs" cat $testInputFile | $boxesBinary $boxesArgs >$testOutputFile 2>&1 declare -ir actualReturnCode=$? cat $testOutputFile | tr -d '\r' | sed -E -f $testFilterFile | diff - $testExpectationFile