Refactoring: Extract make_action into actions-test-lib.sh.
This reduces the duplication in the individual test files.
This commit is contained in:
18
tests/actions-test-lib.sh
Executable file
18
tests/actions-test-lib.sh
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/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"
|
||||||
|
}
|
||||||
@@ -5,10 +5,9 @@ test_description='help functionality
|
|||||||
|
|
||||||
This test covers the help output.
|
This test covers the help output.
|
||||||
'
|
'
|
||||||
|
. ./actions-test-lib.sh
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
unset TODO_ACTIONS_DIR
|
|
||||||
|
|
||||||
# Note: To avoid having to adapt the test whenever the help documentation
|
# Note: To avoid having to adapt the test whenever the help documentation
|
||||||
# slightly changes, only check for the section headers.
|
# slightly changes, only check for the section headers.
|
||||||
test_todo_session 'help output' <<EOF
|
test_todo_session 'help output' <<EOF
|
||||||
@@ -33,16 +32,6 @@ test_todo_session 'very verbose help output' <<EOF
|
|||||||
Built-in Actions:
|
Built-in Actions:
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
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 'help output with custom action' <<EOF
|
test_todo_session 'help output with custom action' <<EOF
|
||||||
>>> todo.sh -v help | sed '/^ \w/!d'
|
>>> todo.sh -v help | sed '/^ \w/!d'
|
||||||
|
|||||||
@@ -4,19 +4,9 @@ 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
|
||||||
|
|||||||
@@ -4,19 +4,9 @@ test_description='listaddons functionality
|
|||||||
|
|
||||||
This test checks listing of custom actions.
|
This test checks listing of 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_todo_session 'no custom actions' <<EOF
|
test_todo_session 'no custom actions' <<EOF
|
||||||
>>> todo.sh listaddons
|
>>> todo.sh listaddons
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -4,31 +4,15 @@ test_description='actions help functionality
|
|||||||
|
|
||||||
This test checks listing the usage help of a custom action.
|
This test checks listing the usage help of a custom action.
|
||||||
'
|
'
|
||||||
|
. ./actions-test-lib.sh
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
unset TODO_ACTIONS_DIR
|
|
||||||
test_todo_session 'custom action help with no custom action directory' <<'EOF'
|
test_todo_session 'custom action help with no custom action directory' <<'EOF'
|
||||||
>>> todo.sh help foo
|
>>> todo.sh help foo
|
||||||
TODO: No actions directory exists.
|
TODO: No actions directory exists.
|
||||||
=== 1
|
=== 1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
mkdir .todo.actions.d
|
|
||||||
make_action()
|
|
||||||
{
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
make_action "foo"
|
make_action "foo"
|
||||||
make_action "bar"
|
make_action "bar"
|
||||||
make_action "quux"
|
make_action "quux"
|
||||||
|
|||||||
Reference in New Issue
Block a user