File: t6050-completion-addons.sh

package info (click to toggle)
todotxt-cli 2.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,312 kB
  • sloc: sh: 5,393; makefile: 67
file content (92 lines) | stat: -rwxr-xr-x 2,759 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
#

test_description='Bash add-on action completion functionality

This test checks todo_completion of custom actions in .todo.actions.d
'
. ./test-lib.sh

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 OPTIONS='-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x'

readonly ADDONS='bar baz foobar'

readonly CONTAINED='xeno zoolander'
makeCustomActions()
{
    set -e
    mkdir "${1:?}"
    for addon in $ADDONS
    do
        addonFile="${1}/$addon"
        > "$addonFile"
        chmod +x "$addonFile"
    done

    # Also create a subdirectory, to test that it is skipped.
    mkdir "${1}/subdir"

    # Also create a non-executable file, to test that it is skipped.
    datafile="${1:?}/datafile"
    > "$datafile"
    chmod -x "$datafile"
    [ -x "$datafile" ] && rm "$datafile"    # Some file systems may always make files executable; then, skip this check.

    # Add an executable file in a folder with the same name as the file,
    # in order to ensure completion
    for contained in $CONTAINED
    do
        mkdir "${1}/$contained"
        > "${1}/$contained/$contained"
        chmod u+x "${1}/$contained/$contained"
    done

    set +e
}
removeCustomActions()
{
    set -e
    rmdir "${1}/subdir"

    for contained in $CONTAINED
    do
        rm "${1}/$contained/$contained"
        rmdir "${1}/$contained"
    done

    rm "${1:?}/"*
    rmdir "$1"
    set +e
}

#
# Test resolution of the default TODO_ACTIONS_DIR.
#
makeCustomActions "$HOME/.todo.actions.d"
test_todo_completion 'all arguments' 'todo-txt ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS"
test_todo_completion 'all arguments after option' 'todo-txt -a ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS"
test_todo_completion 'all arguments beginning with b' 'todo-txt b' 'bar baz'
test_todo_completion 'all arguments beginning with f after options' 'todo-txt -a -v f' 'foobar'
test_todo_completion 'nothing after addon action' 'todo-txt foobar ' ''
removeCustomActions "$HOME/.todo.actions.d"

#
# Test resolution of an alternative TODO_ACTIONS_DIR.
#
mkdir  "$HOME/.todo"
makeCustomActions "$HOME/.todo/actions"
test_todo_completion 'all arguments with actions from .todo/actions/' 'todo-txt ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS"
removeCustomActions "$HOME/.todo/actions"

#
# Test resolution of a configured TODO_ACTIONS_DIR.
#
makeCustomActions "$HOME/addons"
cat >> todo.cfg <<'EOF'
export TODO_ACTIONS_DIR="$HOME/addons"
EOF
test_todo_completion 'all arguments with actions from addons/' 'todo-txt ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS"
removeCustomActions "$HOME/addons"

test_done