Skip to content

Commit

Permalink
Actually test (and fix) that the default action parameter is received…
Browse files Browse the repository at this point in the history
… by the action

The foo2 action needs to print its parameters (instead of hard-coding "foo" if no parameters are passed (which also is broken because the $# is already expanded in the here-doc)), and the test needs to include "foo" (instead of "bar") to match the (reused) expected output.

The resulting output of "foo2 foo" shows that the code actually had a bug: The first argument needs to be dropped from the action arguments, as it's already used as the action name.
  • Loading branch information
inkarkat committed Mar 6, 2023
1 parent 7b04315 commit 4622dc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions tests/t0002-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ echo "TODO: foo"
EOF
chmod +x foo

cat > foo2 << EOF
if [ "$#" -eq 0 ]; then
echo "TODO: foo"
fi
cat > foo2 << 'EOF'
echo "TODO: $*"
EOF
chmod +x foo2

Expand Down Expand Up @@ -47,7 +45,7 @@ test_expect_success 'custom action (env variable)' '
test_expect_success 'custom action (default action)' '
mkdir .todo.actions.d
cp foo2 .todo.actions.d/
TODOTXT_DEFAULT_ACTION="foo2 bar" todo.sh > output;
TODOTXT_DEFAULT_ACTION="foo2 foo" todo.sh > output;
test_cmp expect output && rm -rf .todo.actions.d
'

Expand Down
2 changes: 1 addition & 1 deletion todo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ else
actionarray=($action)
if [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/${actionarray[0]}" ]
then
"$TODO_ACTIONS_DIR/${actionarray[0]}" $action
"$TODO_ACTIONS_DIR/${actionarray[0]}" "${actionarray[@]:1}"
exit $?
fi
fi
Expand Down

0 comments on commit 4622dc5

Please sign in to comment.