Compare commits
3 Commits
archive/in
...
archive/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a3ddad787 | ||
|
|
35f9c4276c | ||
|
|
661dac0cfb |
@@ -1,18 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
make_action()
|
|
||||||
{
|
|
||||||
unset TODO_ACTIONS_DIR
|
|
||||||
[ -d .todo.actions.d ] || mkdir .todo.actions.d
|
|
||||||
cat > ".todo.actions.d/$1" <<EOF
|
|
||||||
#!/bin/bash
|
|
||||||
[ "\$1" = "usage" ] && {
|
|
||||||
echo " $1 ITEM#[, ITEM#, ...] [TERM...]"
|
|
||||||
echo " This custom action does $1."
|
|
||||||
echo ""
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
echo "custom action $1"
|
|
||||||
EOF
|
|
||||||
chmod +x ".todo.actions.d/$1"
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
|
|
||||||
test_description='help functionality
|
|
||||||
|
|
||||||
This test covers the help output.
|
|
||||||
'
|
|
||||||
. ./actions-test-lib.sh
|
|
||||||
. ./test-lib.sh
|
|
||||||
|
|
||||||
# Note: To avoid having to adapt the test whenever the help documentation
|
|
||||||
# slightly changes, only check for the section headers.
|
|
||||||
test_todo_session 'help output' <<EOF
|
|
||||||
>>> todo.sh help | sed '/^ [A-Z]/!d'
|
|
||||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
|
||||||
Options:
|
|
||||||
Built-in Actions:
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'verbose help output' <<EOF
|
|
||||||
>>> todo.sh -v help | sed '/^ [A-Z]/!d'
|
|
||||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
|
||||||
Options:
|
|
||||||
Built-in Actions:
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'very verbose help output' <<EOF
|
|
||||||
>>> todo.sh -vv help | sed '/^ [A-Z]/!d'
|
|
||||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
|
||||||
Options:
|
|
||||||
Environment variables:
|
|
||||||
Built-in Actions:
|
|
||||||
EOF
|
|
||||||
|
|
||||||
make_action "foo"
|
|
||||||
test_todo_session 'help output with custom action' <<EOF
|
|
||||||
>>> todo.sh -v help | sed '/^ [A-Z]/!d'
|
|
||||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
|
||||||
Options:
|
|
||||||
Built-in Actions:
|
|
||||||
Add-on Actions:
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_done
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
test_description='built-in actions help functionality
|
|
||||||
|
|
||||||
This test checks listing the usage help of a built-in action.
|
|
||||||
'
|
|
||||||
. ./test-lib.sh
|
|
||||||
|
|
||||||
test_todo_session 'nonexisting action help' <<'EOF'
|
|
||||||
>>> todo.sh help doesnotexist
|
|
||||||
TODO: No action "doesnotexist" exists.
|
|
||||||
=== 1
|
|
||||||
|
|
||||||
>>> todo.sh help hel
|
|
||||||
TODO: No action "hel" exists.
|
|
||||||
=== 1
|
|
||||||
|
|
||||||
>>> todo.sh help h
|
|
||||||
TODO: No action "h" exists.
|
|
||||||
=== 1
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'single action help' <<'EOF'
|
|
||||||
>>> todo.sh help shorthelp
|
|
||||||
shorthelp
|
|
||||||
List the one-line usage of all built-in and add-on actions.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'multiple actions help' <<'EOF'
|
|
||||||
>>> todo.sh help shorthelp append
|
|
||||||
shorthelp
|
|
||||||
List the one-line usage of all built-in and add-on actions.
|
|
||||||
\
|
|
||||||
append ITEM# "TEXT TO APPEND"
|
|
||||||
app ITEM# "TEXT TO APPEND"
|
|
||||||
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
|
||||||
Quotes optional.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'short and long form of action help' <<'EOF'
|
|
||||||
>>> todo.sh help append
|
|
||||||
append ITEM# "TEXT TO APPEND"
|
|
||||||
app ITEM# "TEXT TO APPEND"
|
|
||||||
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
|
||||||
Quotes optional.
|
|
||||||
\
|
|
||||||
|
|
||||||
>>> todo.sh help app
|
|
||||||
app ITEM# "TEXT TO APPEND"
|
|
||||||
Adds TEXT TO APPEND to the end of the task on line ITEM#.
|
|
||||||
Quotes optional.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'mixed existing and nonexisting action help' <<'EOF'
|
|
||||||
>>> todo.sh help shorthelp doesnotexist list
|
|
||||||
shorthelp
|
|
||||||
List the one-line usage of all built-in and add-on actions.
|
|
||||||
\
|
|
||||||
TODO: No action "doesnotexist" exists.
|
|
||||||
=== 1
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_done
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
|
|
||||||
test_description='Bash help completion functionality
|
|
||||||
|
|
||||||
This test checks todo_completion of actions for usage help.
|
|
||||||
'
|
|
||||||
. ./actions-test-lib.sh
|
|
||||||
. ./test-lib.sh
|
|
||||||
make_action "zany"
|
|
||||||
make_action "aardvark"
|
|
||||||
|
|
||||||
readonly ACTIONS='add a addto addm append app archive command del rm depri dp do help list ls listaddons listall lsa listcon lsc listfile lf listpri lsp listproj lsprj move mv prepend prep pri p replace report shorthelp'
|
|
||||||
readonly ADDONS='aardvark zany'
|
|
||||||
|
|
||||||
test_todo_completion 'all actions after help' 'todo.sh help ' "$ACTIONS $ADDONS"
|
|
||||||
test_todo_completion 'all actions after command help' 'todo.sh command help ' "$ACTIONS $ADDONS"
|
|
||||||
test_todo_completion 'actions beginning with a' 'todo.sh help a' 'add a addto addm append app archive aardvark'
|
|
||||||
|
|
||||||
test_done
|
|
||||||
@@ -4,9 +4,19 @@ test_description='custom actions functionality
|
|||||||
|
|
||||||
This test covers the contract between todo.sh and custom actions.
|
This test covers the contract between todo.sh and custom actions.
|
||||||
'
|
'
|
||||||
. ./actions-test-lib.sh
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
unset TODO_ACTIONS_DIR
|
||||||
|
mkdir .todo.actions.d
|
||||||
|
make_action()
|
||||||
|
{
|
||||||
|
cat > ".todo.actions.d/$1" <<- EOF
|
||||||
|
#!/bin/bash
|
||||||
|
echo "custom action $1"
|
||||||
|
EOF
|
||||||
|
chmod +x ".todo.actions.d/$1"
|
||||||
|
}
|
||||||
|
|
||||||
make_action "foo"
|
make_action "foo"
|
||||||
test_todo_session 'executable action' <<EOF
|
test_todo_session 'executable action' <<EOF
|
||||||
>>> todo.sh foo
|
>>> todo.sh foo
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
test_description='listaddons functionality
|
|
||||||
|
|
||||||
This test checks listing of custom actions.
|
|
||||||
'
|
|
||||||
. ./actions-test-lib.sh
|
|
||||||
. ./test-lib.sh
|
|
||||||
|
|
||||||
test_todo_session 'no custom actions' <<EOF
|
|
||||||
>>> todo.sh listaddons
|
|
||||||
EOF
|
|
||||||
|
|
||||||
make_action "foo"
|
|
||||||
test_todo_session 'one custom action' <<EOF
|
|
||||||
>>> todo.sh listaddons
|
|
||||||
foo
|
|
||||||
EOF
|
|
||||||
|
|
||||||
make_action "bar"
|
|
||||||
make_action "ls"
|
|
||||||
make_action "quux"
|
|
||||||
test_todo_session 'multiple custom actions' <<EOF
|
|
||||||
>>> todo.sh listaddons
|
|
||||||
bar
|
|
||||||
foo
|
|
||||||
ls
|
|
||||||
quux
|
|
||||||
EOF
|
|
||||||
|
|
||||||
chmod -x .todo.actions.d/foo
|
|
||||||
# On Cygwin, clearing the executable flag may have no effect, as the Windows ACL
|
|
||||||
# may still grant execution rights. In this case, we skip the test.
|
|
||||||
if [ -x .todo.actions.d/foo ]; then
|
|
||||||
SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8010.4"
|
|
||||||
fi
|
|
||||||
test_todo_session 'nonexecutable action' <<EOF
|
|
||||||
>>> todo.sh listaddons
|
|
||||||
bar
|
|
||||||
ls
|
|
||||||
quux
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_done
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
test_description='custom actions help functionality
|
|
||||||
|
|
||||||
This test checks listing the usage help of a custom action.
|
|
||||||
'
|
|
||||||
. ./actions-test-lib.sh
|
|
||||||
. ./test-lib.sh
|
|
||||||
|
|
||||||
test_todo_session 'custom action help with no custom action directory' <<'EOF'
|
|
||||||
>>> todo.sh help foo
|
|
||||||
TODO: No action "foo" exists.
|
|
||||||
=== 1
|
|
||||||
EOF
|
|
||||||
|
|
||||||
make_action "foo"
|
|
||||||
make_action "bar"
|
|
||||||
make_action "ls"
|
|
||||||
make_action "quux"
|
|
||||||
|
|
||||||
test_todo_session 'custom action help' <<'EOF'
|
|
||||||
>>> todo.sh help foo
|
|
||||||
foo ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does foo.
|
|
||||||
\
|
|
||||||
|
|
||||||
>>> todo.sh help bar
|
|
||||||
bar ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does bar.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'multiple custom actions help' <<'EOF'
|
|
||||||
>>> todo.sh help foo bar
|
|
||||||
foo ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does foo.
|
|
||||||
\
|
|
||||||
bar ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does bar.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'nonexisting action help' <<'EOF'
|
|
||||||
>>> todo.sh help doesnotexist
|
|
||||||
TODO: No action "doesnotexist" exists.
|
|
||||||
=== 1
|
|
||||||
|
|
||||||
>>> todo.sh help foo doesnotexist bar
|
|
||||||
foo ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does foo.
|
|
||||||
\
|
|
||||||
TODO: No action "doesnotexist" exists.
|
|
||||||
=== 1
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'mixed built-in and custom actions help' <<'EOF'
|
|
||||||
>>> todo.sh help foo shorthelp bar
|
|
||||||
foo ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does foo.
|
|
||||||
\
|
|
||||||
shorthelp
|
|
||||||
List the one-line usage of all built-in and add-on actions.
|
|
||||||
\
|
|
||||||
bar ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does bar.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_todo_session 'custom override of built-in action help' <<'EOF'
|
|
||||||
>>> todo.sh help ls
|
|
||||||
ls ITEM#[, ITEM#, ...] [TERM...]
|
|
||||||
This custom action does ls.
|
|
||||||
\
|
|
||||||
EOF
|
|
||||||
|
|
||||||
test_done
|
|
||||||
@@ -264,25 +264,7 @@ test_expect_success () {
|
|||||||
test_expect_output () {
|
test_expect_output () {
|
||||||
test "$#" = 2 ||
|
test "$#" = 2 ||
|
||||||
error "bug in the test script: not 2 parameters to test-expect-output"
|
error "bug in the test script: not 2 parameters to test-expect-output"
|
||||||
if ! test_skip "$@"
|
test_expect_code_and_output 0 "$@"
|
||||||
then
|
|
||||||
say >&3 "expecting success and output: $2"
|
|
||||||
test_run_ "$2"
|
|
||||||
if [ "$?" = 0 -a "$eval_ret" = 0 ]
|
|
||||||
then
|
|
||||||
cmp_output=$(test_cmp expect output)
|
|
||||||
if [ "$?" = 0 ]
|
|
||||||
then
|
|
||||||
test_ok_ "$1"
|
|
||||||
else
|
|
||||||
test_failure_ "$@" "
|
|
||||||
$cmp_output"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
test_failure_ "$@"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo >&3 ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_expect_code_and_output () {
|
test_expect_code_and_output () {
|
||||||
@@ -290,7 +272,11 @@ test_expect_code_and_output () {
|
|||||||
error "bug in the test script: not 3 parameters to test-expect-code-and-output"
|
error "bug in the test script: not 3 parameters to test-expect-code-and-output"
|
||||||
if ! test_skip "$@"
|
if ! test_skip "$@"
|
||||||
then
|
then
|
||||||
|
if [ "$1" = 0 ]; then
|
||||||
|
say >&3 "expecting success and output: $3"
|
||||||
|
else
|
||||||
say >&3 "expecting exit code $1 and output: $3"
|
say >&3 "expecting exit code $1 and output: $3"
|
||||||
|
fi
|
||||||
test_run_ "$3"
|
test_run_ "$3"
|
||||||
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
|
if [ "$?" = 0 -a "$eval_ret" = "$1" ]
|
||||||
then
|
then
|
||||||
@@ -566,14 +552,16 @@ test_tick () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Generate and run a series of tests based on a transcript.
|
# Generate and run a series of tests based on a transcript.
|
||||||
# Usage: test_todo_session "description" <<EOF
|
# Usage: test_todo_session "description" <<'EOF'
|
||||||
# >>> command
|
# >>> command
|
||||||
# output1
|
# output1
|
||||||
# output2
|
# output2
|
||||||
|
#
|
||||||
# >>> command
|
# >>> command
|
||||||
# === exit status
|
# === exit status
|
||||||
# output3
|
# output3 with empty line (must be escaped here)
|
||||||
# output4
|
# \
|
||||||
|
# output5
|
||||||
# EOF
|
# EOF
|
||||||
test_todo_session () {
|
test_todo_session () {
|
||||||
test "$#" = 1 ||
|
test "$#" = 1 ||
|
||||||
@@ -582,7 +570,7 @@ test_todo_session () {
|
|||||||
cmd=""
|
cmd=""
|
||||||
status=0
|
status=0
|
||||||
> expect
|
> expect
|
||||||
while read -r line
|
while IFS= read -r line
|
||||||
do
|
do
|
||||||
case $line in
|
case $line in
|
||||||
">>> "*)
|
">>> "*)
|
||||||
@@ -606,6 +594,9 @@ test_todo_session () {
|
|||||||
> expect
|
> expect
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
\\)
|
||||||
|
echo "" >> expect
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "$line" >> expect
|
echo "$line" >> expect
|
||||||
;;
|
;;
|
||||||
|
|||||||
41
todo.sh
41
todo.sh
@@ -54,7 +54,7 @@ shorthelp()
|
|||||||
del|rm ITEM# [TERM]
|
del|rm ITEM# [TERM]
|
||||||
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
depri|dp ITEM#[, ITEM#, ITEM#, ...]
|
||||||
do ITEM#[, ITEM#, ITEM#, ...]
|
do ITEM#[, ITEM#, ITEM#, ...]
|
||||||
help [ACTION...]
|
help
|
||||||
list|ls [TERM...]
|
list|ls [TERM...]
|
||||||
listall|lsa [TERM...]
|
listall|lsa [TERM...]
|
||||||
listaddons
|
listaddons
|
||||||
@@ -154,12 +154,6 @@ help()
|
|||||||
|
|
||||||
|
|
||||||
EndVerboseHelp
|
EndVerboseHelp
|
||||||
actionsHelp
|
|
||||||
addonHelp
|
|
||||||
}
|
|
||||||
|
|
||||||
actionsHelp()
|
|
||||||
{
|
|
||||||
cat <<-EndActionsHelp
|
cat <<-EndActionsHelp
|
||||||
Built-in Actions:
|
Built-in Actions:
|
||||||
add "THING I NEED TO DO +project @context"
|
add "THING I NEED TO DO +project @context"
|
||||||
@@ -206,9 +200,8 @@ actionsHelp()
|
|||||||
do ITEM#[, ITEM#, ITEM#, ...]
|
do ITEM#[, ITEM#, ITEM#, ...]
|
||||||
Marks task(s) on line ITEM# as done in todo.txt.
|
Marks task(s) on line ITEM# as done in todo.txt.
|
||||||
|
|
||||||
help [ACTION...]
|
help
|
||||||
Display help about usage, options, built-in and add-on actions,
|
Display this help message.
|
||||||
or just the usage help for the passed ACTION(s).
|
|
||||||
|
|
||||||
list [TERM...]
|
list [TERM...]
|
||||||
ls [TERM...]
|
ls [TERM...]
|
||||||
@@ -285,6 +278,9 @@ actionsHelp()
|
|||||||
List the one-line usage of all built-in and add-on actions.
|
List the one-line usage of all built-in and add-on actions.
|
||||||
|
|
||||||
EndActionsHelp
|
EndActionsHelp
|
||||||
|
|
||||||
|
addonHelp
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
addonHelp()
|
addonHelp()
|
||||||
@@ -306,25 +302,6 @@ addonHelp()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
actionUsage()
|
|
||||||
{
|
|
||||||
for actionName
|
|
||||||
do
|
|
||||||
action="${TODO_ACTIONS_DIR}/${actionName}"
|
|
||||||
if [ -f "$action" -a -x "$action" ]; then
|
|
||||||
"$action" usage
|
|
||||||
else
|
|
||||||
builtinActionUsage=$(actionsHelp | sed -n -e "/^ ${actionName//\//\\/} /,/^\$/p" -e "/^ ${actionName//\//\\/}$/,/^\$/p")
|
|
||||||
if [ "$builtinActionUsage" ]; then
|
|
||||||
echo "$builtinActionUsage"
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
die "TODO: No action \"${actionName}\" exists."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
die()
|
die()
|
||||||
{
|
{
|
||||||
echo "$*"
|
echo "$*"
|
||||||
@@ -1098,11 +1075,6 @@ case $action in
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"help" )
|
"help" )
|
||||||
shift ## Was help; new $1 is first help topic / action name
|
|
||||||
if [ $# -gt 0 ]; then
|
|
||||||
# Don't use PAGER here; we don't expect much usage output from one / few actions.
|
|
||||||
actionUsage "$@"
|
|
||||||
else
|
|
||||||
if [ -t 1 ] ; then # STDOUT is a TTY
|
if [ -t 1 ] ; then # STDOUT is a TTY
|
||||||
if which "${PAGER:-less}" >/dev/null 2>&1; then
|
if which "${PAGER:-less}" >/dev/null 2>&1; then
|
||||||
# we have a working PAGER (or less as a default)
|
# we have a working PAGER (or less as a default)
|
||||||
@@ -1110,7 +1082,6 @@ case $action in
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
help # just in case something failed above, we go ahead and just spew to STDOUT
|
help # just in case something failed above, we go ahead and just spew to STDOUT
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"shorthelp" )
|
"shorthelp" )
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ _todo()
|
|||||||
case "$prev" in
|
case "$prev" in
|
||||||
command)
|
command)
|
||||||
completions=$COMMANDS;;
|
completions=$COMMANDS;;
|
||||||
help)
|
|
||||||
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons)";;
|
|
||||||
addto|listfile|lf)
|
addto|listfile|lf)
|
||||||
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile);;
|
completions=$(eval TODOTXT_VERBOSE=0 $_todo_sh command listfile);;
|
||||||
-*) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS";;
|
-*) completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons) $OPTS";;
|
||||||
|
|||||||
Reference in New Issue
Block a user