Add a basic test framework, borrowed from the framework used by git.git. A shell script library (tests/test-lib.sh) helps generate the fixtures, and simplifies the process of writing test scripts. Tests can be run as a suite (via 'make test') or individually (sh tests/t0000-config.sh). Results are aggregated upon completion. Includes a detailed README. A basic test of config file processing is part of this commit. Signed-off-by: Emil Sit <sit@emilsit.net>
62 lines
1.6 KiB
Bash
Executable File
62 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='todo.sh configuration file location
|
|
|
|
This test just makes sure that todo.sh can find its
|
|
config files in the default locations and take arguments
|
|
to find it somewhere else.
|
|
'
|
|
. ./test-lib.sh
|
|
|
|
# Remove the pre-created todo.cfg to test behavior in its absence
|
|
rm -f todo.cfg
|
|
echo "Fatal error: Cannot read configuration file $HOME/todo.cfg" > expect
|
|
test_expect_success 'no config file' '
|
|
todo.sh > output 2>&1 || test_cmp expect output
|
|
'
|
|
|
|
# All the below tests will output the usage message.
|
|
cat > expect << EOF
|
|
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
|
Try 'todo.sh -h' for more information.
|
|
EOF
|
|
|
|
cat > test.cfg << EOF
|
|
export TODO_DIR=.
|
|
export TODO_FILE="$TODO_DIR/todo.txt"
|
|
export DONE_FILE="$TODO_DIR/done.txt"
|
|
export REPORT_FILE="$TODO_DIR/report.txt"
|
|
export TMP_FILE="$TODO_DIR/todo.tmp"
|
|
touch used_config
|
|
EOF
|
|
|
|
rm -f used_config
|
|
test_expect_success 'config file (default location 1)' '
|
|
cp test.cfg todo.cfg
|
|
todo.sh > output;
|
|
test_cmp expect output && test -f used_config &&
|
|
rm -f todo.cfg
|
|
'
|
|
|
|
rm -f used_config
|
|
test_expect_success 'config file (default location 2)' '
|
|
cp test.cfg .todo.cfg
|
|
todo.sh > output;
|
|
test_cmp expect output && test -f used_config &&
|
|
rm -f .todo.cfg
|
|
'
|
|
|
|
rm -f used_config
|
|
test_expect_success 'config file (command line)' '
|
|
todo.sh -d test.cfg > output;
|
|
test_cmp expect output && test -f used_config
|
|
'
|
|
|
|
rm -f used_config
|
|
test_expect_success 'config file (env variable)' '
|
|
TODOTXT_CFG_FILE=test.cfg todo.sh > output;
|
|
test_cmp expect output && test -f used_config
|
|
'
|
|
|
|
test_done
|