test/: Add default values for configuration variables

Add a small helper script called "test-init.sh" that is sourced in each
test case and initializes the CALCURSE and DATA_DIR environment
variables.

Update the test suite README to point out that setting these environment
variables is no longer required.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2013-02-26 23:34:29 +01:00
parent 5501dae328
commit ba2c5c14f6
50 changed files with 102 additions and 7 deletions

View File

@ -16,13 +16,8 @@ when all tests are finished.
You can also run tests manually. Test cases are usually shell scripts or
binaries. To run an individual test, just invoke the corresponding executable.
Note that some tests require the `CALCURSE` and `DATA_DIR` environment
variables to be set, where `CALCURSE` should point to a valid calcurse binary
and `DATA_DIR` should point to a valid data directory. We usually use the data
directory `data/`, which is contained in the `test/` directory, for test cases:
$ CALCURSE=../src/calcurse DATA_DIR=data/ ./next-001.sh
Running ./next-001.sh... ok
The `CALCURSE` and `DATA_DIR` environment variables can be used to specify an
alternative calcurse binary and data directory.
Passing another data directory might cause some failures since many tests are
adapted for the `test/` directory provided by the test suite:

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-002" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-003" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-004" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-005" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-006" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-007" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-008" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in the item date' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-009" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-010" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'no event nor appointment found' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-011" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-012" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-013" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-014" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-015" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-016" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-017" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-018" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item time or duration' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-019" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-020" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item repetition' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-021" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-appointment-022" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in appointment' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-bug-002" \
-d05/03/2012

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -d02/25/2011
elif [ "$1" = 'expected' ]; then

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-001" \
-d02/23/2013

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-002" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in the item date' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-003" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'date error in event' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-004" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'no event nor appointment found' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-005" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item identifier' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-event-006" \
-d02/23/2013 2>errors && exit 1
grep -Fq 'syntax error in item identifier' errors

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-recur" \
-s01/01/2000 -r8 --format-recur-apt=''

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-recur" \
-d02/01/2000 --format-recur-apt=''

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-recur" \
-d01/01/2001 --format-recur-apt=''

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-recur" \
-d01/01/2000 --format-recur-event=''

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -c "$DATA_DIR/apts-recur" \
-d01/10/2000 --format-recur-event=''

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' -o "$1" = 'expected' ]; then
echo 42
else

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
echo 23
elif [ "$1" = 'expected' ]; then

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ ! -x "$(command -v faketime)" ]; then
echo "libfaketime not found - skipping $0..."
exit 0

4
test/test-init.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
CALCURSE=${CALCURSE:-../src/calcurse}
DATA_DIR=${DATA_DIR:-data/}

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -t | sort
elif [ "$1" = 'expected' ]; then

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -t3
elif [ "$1" = 'expected' ]; then

View File

@ -1,5 +1,7 @@
#!/bin/sh
. ./test-init.sh
if [ "$1" = 'actual' ]; then
"$CALCURSE" --read-only -D "$DATA_DIR"/ -t0 | sort -n
elif [ "$1" = 'expected' ]; then

View File

@ -1,3 +1,5 @@
#!/bin/sh
. ./test-init.sh
true