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 deleted file mode 100755 index 547cc95..0000000 --- a/tests/t1260-listprj.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -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/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 4ea6756..b3d8d8a 100755 --- a/tests/t1310-listcon.sh +++ b/tests/t1310-listcon.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='listcon functionality @@ -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/tests/t1320-listproj.sh b/tests/t1320-listproj.sh index 79b8bcf..6037511 100755 --- a/tests/t1320-listproj.sh +++ b/tests/t1320-listproj.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # test_description='listproj functionality @@ -55,4 +55,63 @@ 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 < 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/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/t6010-completion-contexts.sh b/tests/t6010-completion-contexts.sh new file mode 100755 index 0000000..5059d17 --- /dev/null +++ b/tests/t6010-completion-contexts.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# + +test_description='Bash context completion functionality + +This test checks todo_completion of contexts +' +. ./test-lib.sh + +cat > todo.txt < done.txt < todo.txt < done.txt <&3 "" @@ -632,6 +632,59 @@ 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 + ret=$? + if [ "$ret" = 0 ] + then + IFS=$'\n' + printf "%s${EXPECT:+\\n}" "${EXPECT[*]}" > expect + printf "%s${COMPREPLY:+\\n}" "${COMPREPLY[*]}" > compreply + IFS=$SAVEIFS + + if [ ${#COMPREPLY[@]} -eq ${#EXPECT[@]} ] + then + if [ "${COMPREPLY[*]}" = "${EXPECT[*]}" ] + then + test_ok_ "$description" + else + test_failure_ "$description" "$(test_cmp expect compreply)" + fi + else + test_failure_ "$description" "expected ${#EXPECT[@]} completion(s), got ${#COMPREPLY[@]}: +$(test_cmp expect compreply)" + fi + else + test_failure_ "$description" "expected completions, actual exit code $ret" + 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 diff --git a/todo.sh b/todo.sh index 070f865..4c2a4d9 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, listproj EndVerboseHelp @@ -1128,12 +1129,16 @@ 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" ) + 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" ) diff --git a/todo_completion b/todo_completion index faf91a7..df1fd07 100644 --- a/todo_completion +++ b/todo_completion @@ -35,8 +35,18 @@ _todo() completions=$(TODOTXT_VERBOSE=0 todo.sh command listfile);; -*) completions="$allCommands $OPTS";; *) case "$cur" in - +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj);; - @*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon);; + +*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listproj) + COMPREPLY=( $( compgen -W "$completions" -- $cur )) + [ ${#COMPREPLY[@]} -gt 0 ] && return 0 + # Fall back to projects extracted from done tasks. + completions=$(TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE todo.sh command listproj) + ;; + @*) completions=$(TODOTXT_VERBOSE=0 todo.sh command listcon) + COMPREPLY=( $( compgen -W "$completions" -- $cur )) + [ ${#COMPREPLY[@]} -gt 0 ] && return 0 + # Fall back to contexts extracted from done tasks. + completions=$(TODOTXT_VERBOSE=0 TODOTXT_SOURCEVAR=\$DONE_FILE todo.sh command listcon) + ;; *) if [[ "$cur" =~ ^[0-9]+$ ]]; then # Remove the (padded) task number; we prepend the # user-provided $cur instead.