From 9e13dfd2907d92bf6b400afb5edcbd65c4eb3c44 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Feb 2012 12:11:45 +0100 Subject: [PATCH 1/8] ENH: TODOTXT_SOURCEVAR enables different source file for listcon. To be used by todo_completion (to offer candidates from done.txt when there are no matches in todo.txt), and maybe by custom addons. --- tests/t1310-listcon.sh | 19 +++++++++++++++++++ todo.sh | 7 +++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/t1310-listcon.sh b/tests/t1310-listcon.sh index 4ea6756..c96ea27 100755 --- a/tests/t1310-listcon.sh +++ b/tests/t1310-listcon.sh @@ -55,4 +55,23 @@ test_todo_session 'listcon e-mail address test' < todo.txt < done.txt <>> TODOTXT_SOURCEVAR=\$DONE_FILE todo.sh listcon +@done01 +@done02 +EOF +test_todo_session 'listcon from combined open + done tasks' <<'EOF' +>>> TODOTXT_SOURCEVAR='("$TODO_FILE" "$DONE_FILE")' todo.sh listcon +@con01 +@done01 +@done02 +EOF + test_done diff --git a/todo.sh b/todo.sh index 070f865..d93c619 100755 --- a/todo.sh +++ b/todo.sh @@ -136,7 +136,7 @@ help() EndOptionsHelp - [ $TODOTXT_VERBOSE -gt 1 ] && cat <<-EndVerboseHelp + [ $TODOTXT_VERBOSE -gt 1 ] && cat <<-'EndVerboseHelp' Environment variables: TODOTXT_AUTO_ARCHIVE is same as option -a (0)/-A (1) TODOTXT_CFG_FILE=CONFIG_FILE is same as option -d CONFIG_FILE @@ -149,6 +149,7 @@ help() TODOTXT_DEFAULT_ACTION="" run this when called with no arguments TODOTXT_SORT_COMMAND="sort ..." customize list output TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding + TODOTXT_SOURCEVAR=\$DONE_FILE use another source for listcon EndVerboseHelp @@ -1128,7 +1129,9 @@ case $action in ;; "listcon" | "lsc" ) - grep -o '[^ ]*@[^ ]\+' "$TODO_FILE" | grep '^@' | sort -u + FILE=$TODO_FILE + [ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR" + grep -ho '[^ ]*@[^ ]\+' "${FILE[@]}" | grep '^@' | sort -u ;; "listproj" | "lsprj" ) From 46afb7f46ac1163b471e824934f7900e740d431c Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Feb 2012 12:30:01 +0100 Subject: [PATCH 2/8] ENH: TODOTXT_SOURCEVAR enables different source file for listproj. --- tests/t1320-listproj.sh | 23 +++++++++++++++++++++++ todo.sh | 6 ++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/t1320-listproj.sh b/tests/t1320-listproj.sh index 79b8bcf..454d245 100755 --- a/tests/t1320-listproj.sh +++ b/tests/t1320-listproj.sh @@ -55,4 +55,27 @@ test_todo_session 'listproj embedded + test' < todo.txt < done.txt <>> TODOTXT_SOURCEVAR=\$DONE_FILE todo.sh listproj ++done01 ++done02 +EOF +test_todo_session 'listproj from done tasks with filtering' <<'EOF' +>>> TODOTXT_SOURCEVAR=\$DONE_FILE todo.sh listproj Special ++done01 +EOF +test_todo_session 'listproj from combined open + done tasks' <<'EOF' +>>> TODOTXT_SOURCEVAR='("$TODO_FILE" "$DONE_FILE")' todo.sh listproj ++done01 ++done02 ++prj01 +EOF + test_done diff --git a/todo.sh b/todo.sh index d93c619..4c2a4d9 100755 --- a/todo.sh +++ b/todo.sh @@ -149,7 +149,7 @@ help() TODOTXT_DEFAULT_ACTION="" run this when called with no arguments TODOTXT_SORT_COMMAND="sort ..." customize list output TODOTXT_FINAL_FILTER="sed ..." customize list after color, P@+ hiding - TODOTXT_SOURCEVAR=\$DONE_FILE use another source for listcon + TODOTXT_SOURCEVAR=\$DONE_FILE use another source for listcon, listproj EndVerboseHelp @@ -1135,8 +1135,10 @@ case $action in ;; "listproj" | "lsprj" ) + FILE=$TODO_FILE + [ "$TODOTXT_SOURCEVAR" ] && eval "FILE=$TODOTXT_SOURCEVAR" shift - eval "$(filtercommand 'cat "$TODO_FILE"' '' "$@")" | grep -o '[^ ]*+[^ ]\+' | grep '^+' | sort -u + eval "$(filtercommand 'cat "${FILE[@]}"' '' "$@")" | grep -o '[^ ]*+[^ ]\+' | grep '^+' | sort -u ;; "listpri" | "lsp" ) From 3b90d09b27aeeaf325331b9db5d77e265ead4676 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Feb 2012 14:16:23 +0100 Subject: [PATCH 3/8] 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 From 296bad334ddeb0fb84176461453b1670841e145b Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 21 Feb 2012 15:11:08 +0100 Subject: [PATCH 4/8] Add tests for project and context completion. --- tests/t6010-completion-contexts.sh | 20 ++++++++++++++++++++ tests/t6020-completion-projects.sh | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 tests/t6010-completion-contexts.sh create mode 100755 tests/t6020-completion-projects.sh diff --git a/tests/t6010-completion-contexts.sh b/tests/t6010-completion-contexts.sh new file mode 100755 index 0000000..f6a0d9d --- /dev/null +++ b/tests/t6010-completion-contexts.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# + +test_description='Bash context completion functionality + +This test checks todo_completion of contexts +' +. ./test-lib.sh + +cat > todo.txt < todo.txt < Date: Tue, 21 Feb 2012 16:52:58 +0100 Subject: [PATCH 5/8] ENH: completion offers projects and contexts from done.txt. This is useful when there are no open projects/contexts any more, but one wants to re-use an existing name. --- tests/t6010-completion-contexts.sh | 7 +++++++ tests/t6020-completion-projects.sh | 7 +++++++ todo_completion | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/t6010-completion-contexts.sh b/tests/t6010-completion-contexts.sh index f6a0d9d..5059d17 100755 --- a/tests/t6010-completion-contexts.sh +++ b/tests/t6010-completion-contexts.sh @@ -12,9 +12,16 @@ cat > todo.txt < done.txt < todo.txt < done.txt < Date: Tue, 21 Feb 2012 17:05:52 +0100 Subject: [PATCH 6/8] Merge duplicate test files for listproj. t1260-listprj.sh was accidentally created; the tests should be in t1320-listproj.sh. --- tests/t1260-listprj.sh | 42 ----------------------------------------- tests/t1320-listproj.sh | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 42 deletions(-) delete mode 100755 tests/t1260-listprj.sh diff --git a/tests/t1260-listprj.sh b/tests/t1260-listprj.sh deleted file mode 100755 index 2406755..0000000 --- a/tests/t1260-listprj.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -test_description='list project functionality -' -. ./test-lib.sh - -cat > todo.txt <>> todo.sh listproj -+landscape -+roses -+shared -+sunflowers -EOF - -test_todo_session 'listproj with context' <>> todo.sh listproj @garden -+landscape -+shared -+sunflowers -EOF - -TEST_TODO_CUSTOM=todo-custom.cfg -cat todo.cfg > "$TEST_TODO_CUSTOM" -cat >> "$TEST_TODO_CUSTOM" <<'EOF' -export DEFAULT='' -export PRI_B='' -export PRI_C='' -export TODOTXT_FINAL_FILTER='grep -i roses' -EOF -test_todo_session 'listproj with context special cases' <>> todo.sh -+ -d "$TEST_TODO_CUSTOM" listproj @garden -+landscape -+shared -+sunflowers -EOF - -test_done diff --git a/tests/t1320-listproj.sh b/tests/t1320-listproj.sh index 81e477c..6037511 100755 --- a/tests/t1320-listproj.sh +++ b/tests/t1320-listproj.sh @@ -55,6 +55,42 @@ test_todo_session 'listproj embedded + test' < todo.txt <>> todo.sh listproj ++landscape ++roses ++shared ++sunflowers +EOF + +test_todo_session 'listproj with context' <>> todo.sh listproj @garden ++landscape ++shared ++sunflowers +EOF + +TEST_TODO_CUSTOM=todo-custom.cfg +cat todo.cfg > "$TEST_TODO_CUSTOM" +cat >> "$TEST_TODO_CUSTOM" <<'EOF' +export DEFAULT='' +export PRI_B='' +export PRI_C='' +export TODOTXT_FINAL_FILTER='grep -i roses' +EOF +test_todo_session 'listproj with context special cases' <>> todo.sh -+ -d "$TEST_TODO_CUSTOM" listproj @garden ++landscape ++shared ++sunflowers +EOF + + cat > todo.txt < Date: Wed, 22 Feb 2012 08:43:47 +0100 Subject: [PATCH 7/8] test-lib: Avoid empty line in diff when no completion. There should be a trailing newline when there are completions (to avoid diff complaining about "no trailing newline", but not when there are no completions at all. --- tests/test-lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index fefab5b..8947e38 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -660,8 +660,8 @@ test_todo_completion () { _todo IFS=$'\n' - printf '%s\n' "${EXPECT[*]}" > expect - printf '%s\n' "${COMPREPLY[*]}" > output + printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect + printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > output IFS=$SAVEIFS if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] From c1dcd0ed7860c45c4d205f4a7bdbaadf86d543a9 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 22 Feb 2012 09:19:04 +0100 Subject: [PATCH 8/8] test-lib: Also check completion exit code. The completion may unexpectedly abort somewhere. Additionally, reformat the failure messages (don't prepend a "*", this should be reserved to mark the individual test runs) and use "compreply" instead of "output", so that it's already clear from the diff output that the completion is being tested. --- tests/test-lib.sh | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 8947e38..3e56af3 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -305,7 +305,7 @@ $cmp_output" else cmp_output=$(test_cmp expect output) test_failure_ "$2" "$3" " -* expected exit code $1, actual ${eval_ret}${cmp_output:+ +expected exit code $1, actual ${eval_ret}${cmp_output:+ }${cmp_output}" fi fi @@ -324,7 +324,7 @@ test_expect_code () { test_ok_ "$2" else test_failure_ "$2" "$3" " -* expected exit code $1, actual ${eval_ret}" +expected exit code $1, actual ${eval_ret}" fi fi echo >&3 "" @@ -658,24 +658,28 @@ test_todo_completion () { source "$TEST_DIRECTORY/../todo_completion" _todo - - IFS=$'\n' - printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect - printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > output - IFS=$SAVEIFS - - if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] + ret=$? + if [ "$ret" = 0 ] then - if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + IFS=$'\n' + printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect + printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > compreply + IFS=$SAVEIFS + + if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] then - test_ok_ "$description" + if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + then + test_ok_ "$description" + else + test_failure_ "$description" "$(test_cmp expect compreply)" + fi else - test_failure_ "$description" "Differing completion(s): -$(test_cmp expect output)" + test_failure_ "$description" "expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: +$(test_cmp expect compreply)" fi else - test_failure_ "$description" "Expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: -$(test_cmp expect output)" + test_failure_ "$description" "expected completions, actual exit code $ret" fi fi echo >&3 ""