diff --git a/tests/t1010-add-date.sh b/tests/t1010-add-date.sh new file mode 100755 index 0000000..910ba51 --- /dev/null +++ b/tests/t1010-add-date.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +test_description='test the date on add feature + +Tests paths by which we might automatically add +a date to each item. +' +. ./test-lib.sh + +# +# Add and list +# +test_todo_session 'cmd line first day' <>> todo.sh -t add notice the daisies +TODO: '2009-02-13 notice the daisies' added on line 1. + +>>> todo.sh list +1 2009-02-13 notice the daisies +-- +TODO: 1 of 1 tasks shown from $HOME/todo.txt +EOF + +test_tick + +test_todo_session 'cmd line second day' <>> todo.sh -t add smell the roses +TODO: '2009-02-14 smell the roses' added on line 2. + +>>> todo.sh list +1 2009-02-13 notice the daisies +2 2009-02-14 smell the roses +-- +TODO: 2 of 2 tasks shown from $HOME/todo.txt +EOF + +test_tick + +test_todo_session 'cmd line third day' <>> todo.sh -t add mow the lawn +TODO: '2009-02-15 mow the lawn' added on line 3. + +>>> todo.sh list +1 2009-02-13 notice the daisies +2 2009-02-14 smell the roses +3 2009-02-15 mow the lawn +-- +TODO: 3 of 3 tasks shown from $HOME/todo.txt +EOF + +# Switch to config file +echo "export TODOTXT_DATE_ON_ADD=1" >> todo.cfg + +# Bump the clock, for good measure. +test_tick 3600 + +test_todo_session 'config file third day' <>> todo.sh add take out the trash +TODO: '2009-02-15 take out the trash' added on line 4. + +>>> todo.sh list +1 2009-02-13 notice the daisies +2 2009-02-14 smell the roses +3 2009-02-15 mow the lawn +4 2009-02-15 take out the trash +-- +TODO: 4 of 4 tasks shown from $HOME/todo.txt +EOF + +test_done diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 300f1e5..3767c9e 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -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" <>> command