diff --git a/tests/t0002-actions.sh b/tests/t0002-actions.sh new file mode 100755 index 0000000..d3b31ed --- /dev/null +++ b/tests/t0002-actions.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +test_description='todo.sh actions.d + +This test just makes sure that todo.sh can locate custom actions. +' +. ./test-lib.sh + +# All the below tests will output the custom action message +cat > expect << EOF +TODO: foo +EOF + +cat > foo << EOF +echo "TODO: foo" +EOF +chmod +x foo + +test_expect_success 'custom action (default location 1)' ' + mkdir .todo.actions.d + cp foo .todo.actions.d/ + todo.sh foo > output; + test_cmp expect output && rm -rf .todo.actions.d +' + +test_expect_success 'custom action (default location 2)' ' + mkdir -p .todo/actions + cp foo .todo/actions/ + todo.sh foo > output; + test_cmp expect output && rm -rf .todo/actions +' + +test_expect_success 'custom action (env variable)' ' + mkdir myactions + cp foo myactions/ + TODO_ACTIONS_DIR=myactions todo.sh foo > output; + test_cmp expect output && rm -rf myactions +' + +test_done diff --git a/tests/t8000-actions.sh b/tests/t8000-actions.sh new file mode 100755 index 0000000..3d92248 --- /dev/null +++ b/tests/t8000-actions.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='custom actions functionality + +This test covers the contract between todo.sh and custom actions. +' +. ./test-lib.sh + +unset TODO_ACTIONS_DIR +mkdir .todo.actions.d +cat > .todo.actions.d/foo << EOF +echo "TODO: foo" +EOF + +test_todo_session 'nonexecutable action' <>> todo.sh foo +Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description] +Try 'todo.sh -h' for more information. +=== 1 +EOF + +chmod +x .todo.actions.d/foo +test_todo_session 'executable action' <>> todo.sh foo +TODO: foo +EOF + +cat > .todo.actions.d/ls << EOF +echo "TODO: my ls" +EOF +chmod +x .todo.actions.d/ls +test_todo_session 'overriding built-in action' <>> todo.sh ls +TODO: my ls + +>>> todo.sh command ls +-- +TODO: 0 of 0 tasks shown +EOF + +cat > .todo.actions.d/bad << EOF +echo "TODO: bad" +exit 42 +EOF +chmod +x .todo.actions.d/bad +test_todo_session 'failing action' <>> todo.sh bad +TODO: bad +=== 42 +EOF + +test_done