tests: Explicitly control the date for todo.sh.
Create a custom date view for todo.sh tests -- the time is set in TODO_TEST_TIME as seconds since the Unix epoch and a custom wrapper in the testing directory is put at the front of the path to intercept todo.sh calls to date for date formatting. This will only work as long as todo.sh calls $(date) for date formatting. It also assumes a date command that supports the -d flag (such as the one in GNU coreutils.) Add a test for TODOTXT_DATE_ON_ADD to exercise this functionality. Signed-off-by: Emil Sit <sit@emilsit.net>
This commit is contained in:
@@ -407,9 +407,8 @@ test_done () {
|
||||
esac
|
||||
}
|
||||
|
||||
# Make sure we are testing the latest version.
|
||||
# Record our location for reference.
|
||||
TEST_DIRECTORY=$(pwd)
|
||||
PATH=$TEST_DIRECTORY/..:$PATH
|
||||
|
||||
# Test repository
|
||||
test="trash directory.$(basename "$0" .sh)"
|
||||
@@ -431,9 +430,34 @@ test_init_todo () {
|
||||
cd "$root" || error "Cannot setup todo dir in $root"
|
||||
# Initialize the configuration file. Carefully quoted.
|
||||
sed -e 's|TODO_DIR=.*$|TODO_DIR="'"$TEST_DIRECTORY/$test"'"|' $TEST_DIRECTORY/../todo.cfg > todo.cfg
|
||||
|
||||
# Install latest todo.sh
|
||||
mkdir bin
|
||||
ln -s "$TEST_DIRECTORY/../todo.sh" bin/todo.sh
|
||||
|
||||
# Initialize a hack date script
|
||||
TODO_TEST_REAL_DATE=$(which date)
|
||||
TODO_TEST_TIME=1234500000
|
||||
export PATH TODO_TEST_REAL_DATE TODO_TEST_TIME
|
||||
cat > bin/date <<-EOF
|
||||
#!/bin/sh
|
||||
# Assumes GNU date.
|
||||
exec "$TODO_TEST_REAL_DATE" -d @\$TODO_TEST_TIME \$@
|
||||
EOF
|
||||
chmod 755 bin/date
|
||||
|
||||
# Ensure a correct PATH for testing.
|
||||
PATH=$owd/$root/bin:$PATH
|
||||
export PATH
|
||||
|
||||
cd "$owd"
|
||||
}
|
||||
|
||||
# Usage: test_tick [increment]
|
||||
test_tick () {
|
||||
TODO_TEST_TIME=$(($TODO_TEST_TIME + ${1:-86400}))
|
||||
}
|
||||
|
||||
# Generate and run a series of tests based on a transcript.
|
||||
# Usage: test_todo_session "description" <<EOF
|
||||
# >>> command
|
||||
|
||||
Reference in New Issue
Block a user