From 3b90d09b27aeeaf325331b9db5d77e265ead4676 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Feb 2012 14:16:23 +0100 Subject: [PATCH] Add testing of todo_completion. Before adding any more features to todo_completion, I feel like I need test coverage, so this is a first stab at testing the completion results, via a new test function test_todo_completion. Some basic tests showcase the capabilities. Note: test-lib.sh now uses arrays, therefore all tests must use /bin/bash, not /bin/sh to avoid errors when sourcing test-lib. For consistency with todo.sh, we should have used Bash everywhere, anyway. Also note that t2000-multiline.sh needs some more quoting to avoid "Bash: ambiguous redirect" errors. --- tests/README | 15 ++++++++-- tests/t0000-config.sh | 2 +- tests/t0001-null.sh | 2 +- tests/t0002-actions.sh | 2 +- tests/t0100-code-nobacktick.sh | 2 +- tests/t1000-addlist.sh | 2 +- tests/t1010-add-date.sh | 2 +- tests/t1020-addtolistfile.sh | 2 +- tests/t1030-addto-date.sh | 2 +- tests/t1100-replace.sh | 2 +- tests/t1200-pri.sh | 2 +- tests/t1250-listpri.sh | 2 +- tests/t1260-listprj.sh | 2 +- tests/t1300-ls.sh | 2 +- tests/t1310-listcon.sh | 2 +- tests/t1320-listproj.sh | 2 +- tests/t1330-ls-highlighting.sh | 2 +- tests/t1350-listall.sh | 2 +- tests/t1400-prepend.sh | 2 +- tests/t1500-do.sh | 2 +- tests/t1600-append.sh | 2 +- tests/t1700-depri.sh | 2 +- tests/t1800-del.sh | 2 +- tests/t1900-archive.sh | 2 +- tests/t1910-deduplicate.sh | 2 +- tests/t1950-report.sh | 2 +- tests/t2000-multiline.sh | 34 ++++++++++----------- tests/t6000-completion.sh | 18 +++++++++++ tests/t8000-actions.sh | 2 +- tests/t9999-testsuite_example.sh | 2 +- tests/test-lib.sh | 51 +++++++++++++++++++++++++++++++- tests/testshell.sh | 2 +- 32 files changed, 126 insertions(+), 48 deletions(-) create mode 100755 tests/t6000-completion.sh diff --git a/tests/README b/tests/README index e09c874..971c94c 100644 --- a/tests/README +++ b/tests/README @@ -125,10 +125,10 @@ Writing Tests ------------- The test script is written as a shell script. It should start -with the standard "#!/bin/sh" with copyright notices, and an +with the standard "#!/bin/bash" with copyright notices, and an assignment to variable 'test_description', like this: - #!/bin/sh + #!/bin/bash # # Copyright (c) 2005 Junio C Hamano # @@ -186,6 +186,17 @@ library for your script to use. expected output. (See below for how to generate transcripts easily.) + - test_todo_completion + + This takes three strings as parameter. Based on , + the todo_completion script is triggered in the current test + environment and completions are compared with , + which should be a space-separated list. Include a trailing + space in when you want to check new argument + completion; otherwise, completion is triggered with the + context of the last argument. should state what it + is testing. + - test_tick [interval] The test harness has an internal view of time which is diff --git a/tests/t0000-config.sh b/tests/t0000-config.sh index 4275d90..88cb345 100755 --- a/tests/t0000-config.sh +++ b/tests/t0000-config.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='todo.sh configuration file location diff --git a/tests/t0001-null.sh b/tests/t0001-null.sh index 2362135..f2b66b0 100755 --- a/tests/t0001-null.sh +++ b/tests/t0001-null.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='todo.sh basic null functionality test. diff --git a/tests/t0002-actions.sh b/tests/t0002-actions.sh index d3b31ed..533a3e0 100755 --- a/tests/t0002-actions.sh +++ b/tests/t0002-actions.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='todo.sh actions.d diff --git a/tests/t0100-code-nobacktick.sh b/tests/t0100-code-nobacktick.sh index 023c2a9..1b827b3 100755 --- a/tests/t0100-code-nobacktick.sh +++ b/tests/t0100-code-nobacktick.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='no old-style backtick command substitution diff --git a/tests/t1000-addlist.sh b/tests/t1000-addlist.sh index 83680c5..fad3f23 100755 --- a/tests/t1000-addlist.sh +++ b/tests/t1000-addlist.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic add and list functionality diff --git a/tests/t1010-add-date.sh b/tests/t1010-add-date.sh index abb345d..f53080d 100755 --- a/tests/t1010-add-date.sh +++ b/tests/t1010-add-date.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='test the date on add feature diff --git a/tests/t1020-addtolistfile.sh b/tests/t1020-addtolistfile.sh index 4ddea44..0f2b98c 100755 --- a/tests/t1020-addtolistfile.sh +++ b/tests/t1020-addtolistfile.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic addto and list functionality diff --git a/tests/t1030-addto-date.sh b/tests/t1030-addto-date.sh index 5365102..2cb7400 100755 --- a/tests/t1030-addto-date.sh +++ b/tests/t1030-addto-date.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='test the date on addto feature diff --git a/tests/t1100-replace.sh b/tests/t1100-replace.sh index 068ab5c..9336304 100755 --- a/tests/t1100-replace.sh +++ b/tests/t1100-replace.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic replace functionality diff --git a/tests/t1200-pri.sh b/tests/t1200-pri.sh index 7c6fe0c..62b479c 100755 --- a/tests/t1200-pri.sh +++ b/tests/t1200-pri.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic priority functionality ' diff --git a/tests/t1250-listpri.sh b/tests/t1250-listpri.sh index bab2ee3..ff374e2 100755 --- a/tests/t1250-listpri.sh +++ b/tests/t1250-listpri.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='list priority functionality ' diff --git a/tests/t1260-listprj.sh b/tests/t1260-listprj.sh index 547cc95..2406755 100755 --- a/tests/t1260-listprj.sh +++ b/tests/t1260-listprj.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='list project functionality ' diff --git a/tests/t1300-ls.sh b/tests/t1300-ls.sh index 1a69249..c6a7fdf 100755 --- a/tests/t1300-ls.sh +++ b/tests/t1300-ls.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='list functionality diff --git a/tests/t1310-listcon.sh b/tests/t1310-listcon.sh index c96ea27..b3d8d8a 100755 --- a/tests/t1310-listcon.sh +++ b/tests/t1310-listcon.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='listcon functionality diff --git a/tests/t1320-listproj.sh b/tests/t1320-listproj.sh index 454d245..81e477c 100755 --- a/tests/t1320-listproj.sh +++ b/tests/t1320-listproj.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='listproj functionality diff --git a/tests/t1330-ls-highlighting.sh b/tests/t1330-ls-highlighting.sh index d5d0f0e..6862851 100755 --- a/tests/t1330-ls-highlighting.sh +++ b/tests/t1330-ls-highlighting.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='list highlighting diff --git a/tests/t1350-listall.sh b/tests/t1350-listall.sh index 7f55aa5..72af135 100755 --- a/tests/t1350-listall.sh +++ b/tests/t1350-listall.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='listall functionality ' diff --git a/tests/t1400-prepend.sh b/tests/t1400-prepend.sh index 48619b6..44d8f0e 100755 --- a/tests/t1400-prepend.sh +++ b/tests/t1400-prepend.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic prepend functionality ' diff --git a/tests/t1500-do.sh b/tests/t1500-do.sh index 8bae9b6..36242fe 100755 --- a/tests/t1500-do.sh +++ b/tests/t1500-do.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='do functionality ' diff --git a/tests/t1600-append.sh b/tests/t1600-append.sh index a04ce85..980c02b 100755 --- a/tests/t1600-append.sh +++ b/tests/t1600-append.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic append functionality diff --git a/tests/t1700-depri.sh b/tests/t1700-depri.sh index 9fcbf8d..7ec7e7f 100755 --- a/tests/t1700-depri.sh +++ b/tests/t1700-depri.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic depriority functionality ' diff --git a/tests/t1800-del.sh b/tests/t1800-del.sh index 3f70eb2..c9fc744 100755 --- a/tests/t1800-del.sh +++ b/tests/t1800-del.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic del functionality ' diff --git a/tests/t1900-archive.sh b/tests/t1900-archive.sh index 9cc3ae6..f8baca5 100755 --- a/tests/t1900-archive.sh +++ b/tests/t1900-archive.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='archive functionality diff --git a/tests/t1910-deduplicate.sh b/tests/t1910-deduplicate.sh index be225e8..3617807 100755 --- a/tests/t1910-deduplicate.sh +++ b/tests/t1910-deduplicate.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='deduplicate functionality diff --git a/tests/t1950-report.sh b/tests/t1950-report.sh index 46bbf97..5e762e7 100755 --- a/tests/t1950-report.sh +++ b/tests/t1950-report.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='report functionality diff --git a/tests/t2000-multiline.sh b/tests/t2000-multiline.sh index 9a2764f..fe35100 100755 --- a/tests/t2000-multiline.sh +++ b/tests/t2000-multiline.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='Multi-line functionality' @@ -8,18 +8,18 @@ test_description='Multi-line functionality' # Create the expected file echo "1 smell the cheese TODO: Replaced task with: -1 eat apples eat oranges drink milk">$HOME/expect.multi +1 eat apples eat oranges drink milk">"$HOME/expect.multi" test_expect_success 'multiline squash item replace' ' ( # Prepare single line todo file -cat /dev/null > $HOME/todo.txt +cat /dev/null > "$HOME/todo.txt" "$HOME/bin/todo.sh" add smell the cheese # Run replace "$HOME/bin/todo.sh" replace 1 "eat apples eat oranges -drink milk" > $HOME/output.multi +drink milk" > "$HOME/output.multi" # Test output against expected diff "$HOME/output.multi" "$HOME/expect.multi" @@ -34,18 +34,18 @@ fi ## Add test # Create the expected file echo "2 eat apples eat oranges drink milk -TODO: 2 added.">$HOME/expect.multi +TODO: 2 added.">"$HOME/expect.multi" test_expect_success 'multiline squash item add' ' ( # Prepare single line todo file -cat /dev/null > $HOME/todo.txt +cat /dev/null > "$HOME/todo.txt" "$HOME/bin/todo.sh" add smell the cheese # Run add "$HOME/bin/todo.sh" add "eat apples eat oranges -drink milk" > $HOME/output.multi +drink milk" > "$HOME/output.multi" # Test output against expected diff "$HOME/output.multi" "$HOME/expect.multi" @@ -59,18 +59,18 @@ fi ## Append test # Create the expected file -echo "1 smell the cheese eat apples eat oranges drink milk">$HOME/expect.multi +echo "1 smell the cheese eat apples eat oranges drink milk">"$HOME/expect.multi" test_expect_success 'multiline squash item append' ' ( # Prepare single line todo file -cat /dev/null > $HOME/todo.txt +cat /dev/null > "$HOME/todo.txt" "$HOME/bin/todo.sh" add smell the cheese # Run append "$HOME/bin/todo.sh" append 1 "eat apples eat oranges -drink milk" > $HOME/output.multi +drink milk" > "$HOME/output.multi" # Test output against expected diff "$HOME/output.multi" "$HOME/expect.multi" @@ -84,18 +84,18 @@ fi ## Prepend test # Create the expected file -echo "1 eat apples eat oranges drink milk smell the cheese">$HOME/expect.multi +echo "1 eat apples eat oranges drink milk smell the cheese">"$HOME/expect.multi" test_expect_success 'multiline squash item prepend' ' ( # Prepare single line todo file -cat /dev/null > $HOME/todo.txt +cat /dev/null > "$HOME/todo.txt" "$HOME/bin/todo.sh" add smell the cheese # Run prepend "$HOME/bin/todo.sh" prepend 1 "eat apples eat oranges -drink milk" > $HOME/output.multi +drink milk" > "$HOME/output.multi" # Test output against expected diff "$HOME/output.multi" "$HOME/expect.multi" @@ -110,18 +110,18 @@ fi ## Multiple line addition # Create the expected file echo "2 eat apples -TODO: 2 added." > $HOME/expect.multi +TODO: 2 added." > "$HOME/expect.multi" echo "3 eat oranges -TODO: 3 added." >>$HOME/expect.multi +TODO: 3 added." >>"$HOME/expect.multi" echo "4 drink milk -TODO: 4 added." >> $HOME/expect.multi +TODO: 4 added." >>"$HOME/expect.multi" test_expect_success 'actual multiline add' ' ( # Run addm "$HOME/bin/todo.sh" addm "eat apples eat oranges -drink milk" > $HOME/output.multi +drink milk" > "$HOME/output.multi" # Test output against expected diff "$HOME/output.multi" "$HOME/expect.multi" diff --git a/tests/t6000-completion.sh b/tests/t6000-completion.sh new file mode 100755 index 0000000..cb1eccf --- /dev/null +++ b/tests/t6000-completion.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# + +test_description='Bash completion functionality + +This test checks basic todo_completion of actions and options +' +. ./test-lib.sh + +readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp' +readonly OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x' + +test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $OPTIONS" +test_todo_completion 'arguments beginning with a' 'todo.sh a' 'add a addto addm append app archive' +test_todo_completion 'all options' 'todo.sh -' "$OPTIONS" +test_todo_completion 'all actions after command action' 'todo.sh command ' "$ACTIONS" + +test_done diff --git a/tests/t8000-actions.sh b/tests/t8000-actions.sh index 03a1fbe..5c8b7d5 100755 --- a/tests/t8000-actions.sh +++ b/tests/t8000-actions.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='custom actions functionality diff --git a/tests/t9999-testsuite_example.sh b/tests/t9999-testsuite_example.sh index 0c7efbe..ef25884 100755 --- a/tests/t9999-testsuite_example.sh +++ b/tests/t9999-testsuite_example.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='basic tests imported from previous framework ' diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 431231d..fefab5b 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Copyright (c) 2005 Junio C Hamano # @@ -632,6 +632,55 @@ EOF exit 0 } +test_todo_completion () { + test "$#" = 3 || + error "bug in the test script: not 3 parameters to test_todo_completion" + if ! test_skip "$@" + then + description=$1 + expected=$3 + + if [ "${2: -1}" = ' ' ] + then + offset=0 + say >&3 "expecting completions after: '$2'" + else + offset=1 + say >&3 "expecting context completions for: '$2'" + fi + + SAVEIFS=$IFS + IFS=' ' set -- $2 + COMP_WORDS=("$@") + COMP_CWORD=$(($# - $offset)) + IFS=' ' set -- $expected + EXPECT=("$@") + + source "$TEST_DIRECTORY/../todo_completion" + _todo + + IFS=$'\n' + printf '%s\n' "${EXPECT[*]}" > expect + printf '%s\n' "${COMPREPLY[*]}" > output + IFS=$SAVEIFS + + if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] + then + if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + then + test_ok_ "$description" + else + test_failure_ "$description" "Differing completion(s): +$(test_cmp expect output)" + fi + else + test_failure_ "$description" "Expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: +$(test_cmp expect output)" + fi + fi + echo >&3 "" +} + test_init_todo "$test" # Use -P to resolve symlinks in our working directory so that the pwd # in subprocesses equals our $PWD (for pathname comparisons). diff --git a/tests/testshell.sh b/tests/testshell.sh index aae7caa..83abeaa 100755 --- a/tests/testshell.sh +++ b/tests/testshell.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash test_description='Providing an interactive shell in the proper environment' . ./test-lib.sh