Skip to content

Commit

Permalink
Merge branch 'master' into extras
Browse files Browse the repository at this point in the history
* master:
  tests: Update documentation to reflect recent changes.
  tests: add testshell.sh and port old testsuite.txt
  tests: adding testshell.sh and porting old testsuite.txt
  tests: Explicitly control the date for todo.sh.
  tests: Make test writing simpler and add two new tests.
  Bugfix: support commands combination for TODOTXT_SORT_COMMAND
  Bugfix: pri accepted priorities of more than a single letter
  • Loading branch information
doegox committed Apr 12, 2009
2 parents 599dd54 + 048c72a commit 61291f1
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 163 deletions.
41 changes: 40 additions & 1 deletion tests/README
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ Test harness library
There are a handful helper functions defined in the test harness
library for your script to use.

- test_todo_session <message> < transcript

This takes a single string as a parameter, which is treated
as a base description of what is being tested, and then
reads from standard input a transcript of todo.sh commands
and expected output. Each command is run in the current
test environment and the output is compared with the
expected output. (See below for how to generate transcripts
easily.)

- test_tick [interval]

The test harness has an internal view of time which is
implemented by wrapping the date command. This takes a single
optional positive integer parameter which indicates how much
to advance the internal time. The default value is one day.

- test_expect_success <message> <script>

This takes two strings as parameter, and evaluates the
Expand Down Expand Up @@ -211,9 +228,31 @@ library for your script to use.
exit with an appropriate error code.


Generating test transcripts
---------------------------

You can generate test scripts from screenshots as following:

$ ./testshell.sh

You'll be in a special test environment with an empty todo.txt
and the dates and timestamps will be artificially fixed.

Then the session can be used to make a unit test thanks to
test_todo_session, see the existing tests as examples.

Be careful to replace all occurences of the full path to the test
directory by $HOME as testshell.sh will explain you when you execute it
otherwise the tests will work properly only on your own computer.

Don't use "script" as this would log every keystroke, not only what's
visible!!


Credits
-------

This test framework was derived from the framework used by
git itself, written originally by Junio Hamano and licensed
for use under the GPL.
for use under the GPL. It was specialized for todo.txt-cli
by Emil Sit and Philippe Teuwen.
46 changes: 0 additions & 46 deletions tests/README_generate-test

This file was deleted.

57 changes: 0 additions & 57 deletions tests/generate-test.awk

This file was deleted.

69 changes: 69 additions & 0 deletions tests/t1010-add-date.sh
Original file line number Diff line number Diff line change
@@ -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' <<EOF
>>> 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' <<EOF
>>> 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' <<EOF
>>> 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' <<EOF
>>> 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
Loading

0 comments on commit 61291f1

Please sign in to comment.