mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-04-08 23:58:48 +02:00
Add test cases and test runner improvements for testing #69
This commit is contained in:
parent
033c879ae6
commit
68098e4480
10
test/122_no_config_file_dir.txt
Normal file
10
test/122_no_config_file_dir.txt
Normal file
@ -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
|
17
test/123_config_file_xdg1.txt
Normal file
17
test/123_config_file_xdg1.txt
Normal file
@ -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
|
27
test/123_data/.config/boxes/boxes-config
Normal file
27
test/123_data/.config/boxes/boxes-config
Normal file
@ -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:
|
18
test/124_config_file_xdg2.txt
Normal file
18
test/124_config_file_xdg2.txt
Normal file
@ -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
|
23
test/124_data/home/.config/boxes/boxes-config
Normal file
23
test/124_data/home/.config/boxes/boxes-config
Normal file
@ -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
|
24
test/124_data/xdg/boxes/boxes-config
Normal file
24
test/124_data/xdg/boxes/boxes-config
Normal file
@ -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
|
11
test/125_config_file_wrong_BOXES_var.txt
Normal file
11
test/125_config_file_wrong_BOXES_var.txt
Normal file
@ -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
|
15
test/126_config_file_xdg3.txt
Normal file
15
test/126_config_file_xdg3.txt
Normal file
@ -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
|
27
test/126_data/home/boxes-config
Normal file
27
test/126_data/home/boxes-config
Normal file
@ -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
|
23
test/126_data/xdg/boxes/boxes-config
Normal file
23
test/126_data/xdg/boxes/boxes-config
Normal file
@ -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
|
@ -2,86 +2,10 @@
|
|||||||
# Currently unused.
|
# Currently unused.
|
||||||
|
|
||||||
|
|
||||||
BOX test1
|
|
||||||
|
|
||||||
author "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
|
||||||
|
|
||||||
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 <boxes(at)thomasjensen(dot)com>"
|
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
|
||||||
|
|
||||||
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 <boxes(at)thomasjensen(dot)com>"
|
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
|
||||||
|
|
||||||
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
|
BOX test4
|
||||||
|
|
||||||
author "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
author "Thomas Jensen"
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
designer "Thomas Jensen"
|
||||||
|
|
||||||
sample test4
|
sample test4
|
||||||
ends
|
ends
|
||||||
@ -103,8 +27,8 @@ END test4
|
|||||||
|
|
||||||
BOX test5
|
BOX test5
|
||||||
|
|
||||||
author "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
author "Thomas Jensen"
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
designer "Thomas Jensen"
|
||||||
|
|
||||||
sample test5
|
sample test5
|
||||||
ends
|
ends
|
||||||
@ -128,8 +52,8 @@ END test5
|
|||||||
|
|
||||||
BOX test6
|
BOX test6
|
||||||
|
|
||||||
author "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
author "Thomas Jensen"
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
designer "Thomas Jensen"
|
||||||
|
|
||||||
sample test6
|
sample test6
|
||||||
ends
|
ends
|
||||||
@ -155,8 +79,8 @@ END test6
|
|||||||
|
|
||||||
BOX retest
|
BOX retest
|
||||||
|
|
||||||
author "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
author "Thomas Jensen"
|
||||||
designer "Thomas Jensen <boxes(at)thomasjensen(dot)com>"
|
designer "Thomas Jensen"
|
||||||
revision "1.1"
|
revision "1.1"
|
||||||
revdate "August 18, 1999 (Wednesday, 17:07h)"
|
revdate "August 18, 1999 (Wednesday, 17:07h)"
|
||||||
created "April 04, 1999 (Sunday, 18:00h)"
|
created "April 04, 1999 (Sunday, 18:00h)"
|
||||||
@ -175,7 +99,7 @@ shapes { nw ("*") ne ("*") sw ("*") se ("*")
|
|||||||
elastic (n,e,s,W)
|
elastic (n,e,s,W)
|
||||||
|
|
||||||
replace once "bar" with "raba-raba"
|
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 "++++"
|
replace "--" with "++++"
|
||||||
|
|
||||||
END retest
|
END retest
|
||||||
|
@ -59,6 +59,24 @@ for sectionName in :ARGS :INPUT :OUTPUT-FILTER :EXPECTED :EOF; do
|
|||||||
fi
|
fi
|
||||||
done
|
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
|
declare -i expectedReturnCode=0
|
||||||
if [ $(grep -c "^:EXPECTED-ERROR " $testCaseFile) -eq 1 ]; then
|
if [ $(grep -c "^:EXPECTED-ERROR " $testCaseFile) -eq 1 ]; then
|
||||||
expectedReturnCode=$(grep "^:EXPECTED-ERROR " $testCaseFile | sed -e 's/:EXPECTED-ERROR //')
|
expectedReturnCode=$(grep "^:EXPECTED-ERROR " $testCaseFile | sed -e 's/:EXPECTED-ERROR //')
|
||||||
@ -79,9 +97,14 @@ if [ ! -x $boxesBinary ]; then
|
|||||||
boxesBinary=../src/boxes
|
boxesBinary=../src/boxes
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo " Invoking: $(basename $boxesBinary) $boxesArgs"
|
if [ ! -z "$boxesEnv" ]; then
|
||||||
export BOXES=../boxes-config
|
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
|
cat $testInputFile | $boxesBinary $boxesArgs >$testOutputFile 2>&1
|
||||||
declare -ir actualReturnCode=$?
|
declare -ir actualReturnCode=$?
|
||||||
cat $testOutputFile | tr -d '\r' | sed -E -f $testFilterFile | diff - $testExpectationFile
|
cat $testOutputFile | tr -d '\r' | sed -E -f $testFilterFile | diff - $testExpectationFile
|
||||||
|
Loading…
Reference in New Issue
Block a user