| 1 |
# Function stub |
| 2 |
compopt() { return 0; } |
| 3 |
|
| 4 |
initcli() { |
| 5 |
COMP_WORDS=( "beet" "$@" ) |
| 6 |
let COMP_CWORD=${#COMP_WORDS[@]}-1 |
| 7 |
COMP_LINE="${COMP_WORDS[@]}" |
| 8 |
let COMP_POINT=${#COMP_LINE} |
| 9 |
_beet |
| 10 |
} |
| 11 |
|
| 12 |
completes() { |
| 13 |
for word in "$@"; do |
| 14 |
[[ " ${COMPREPLY[@]} " == *[[:space:]]$word[[:space:]]* ]] || return 1 |
| 15 |
done |
| 16 |
} |
| 17 |
|
| 18 |
COMMANDS='fields import list update remove |
| 19 |
stats version modify move write |
| 20 |
help' |
| 21 |
|
| 22 |
HELP_OPTS='-h --help' |
| 23 |
|
| 24 |
|
| 25 |
test_commands() { |
| 26 |
initcli '' && |
| 27 |
completes $COMMANDS && |
| 28 |
|
| 29 |
initcli -v '' && |
| 30 |
completes $COMMANDS && |
| 31 |
|
| 32 |
initcli -l help '' && |
| 33 |
completes $COMMANDS && |
| 34 |
|
| 35 |
initcli -d list '' && |
| 36 |
completes $COMMANDS && |
| 37 |
|
| 38 |
initcli -h '' && |
| 39 |
completes $COMMANDS && |
| 40 |
true |
| 41 |
} |
| 42 |
|
| 43 |
test_command_aliases() { |
| 44 |
initcli ls && |
| 45 |
completes list && |
| 46 |
|
| 47 |
initcli l && |
| 48 |
! completes ls && |
| 49 |
|
| 50 |
initcli im && |
| 51 |
completes import && |
| 52 |
true |
| 53 |
} |
| 54 |
|
| 55 |
test_global_opts() { |
| 56 |
initcli - && |
| 57 |
completes \ |
| 58 |
-l --library \ |
| 59 |
-d --directory \ |
| 60 |
-h --help \ |
| 61 |
-c --config \ |
| 62 |
-v --verbose && |
| 63 |
true |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
test_global_file_opts() { |
| 68 |
# FIXME somehow file completion only works when the completion |
| 69 |
# function is called by the shell completion utilities. So we can't |
| 70 |
# test it here |
| 71 |
initcli --library '' && |
| 72 |
completes $(compgen -d) && |
| 73 |
|
| 74 |
initcli -l '' && |
| 75 |
completes $(compgen -d) && |
| 76 |
|
| 77 |
initcli --config '' && |
| 78 |
completes $(compgen -d) && |
| 79 |
|
| 80 |
initcli -c '' && |
| 81 |
completes $(compgen -d) && |
| 82 |
true |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
test_global_dir_opts() { |
| 87 |
initcli --directory '' && |
| 88 |
completes $(compgen -d) && |
| 89 |
|
| 90 |
initcli -d '' && |
| 91 |
completes $(compgen -d) && |
| 92 |
true |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
test_fields_command() { |
| 97 |
initcli fields - && |
| 98 |
completes -h --help && |
| 99 |
|
| 100 |
initcli fields '' && |
| 101 |
completes $(compgen -d) && |
| 102 |
true |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
test_import_files() { |
| 107 |
initcli import '' && |
| 108 |
completes $(compgen -d) && |
| 109 |
|
| 110 |
initcli import --copy -P '' && |
| 111 |
completes $(compgen -d) && |
| 112 |
|
| 113 |
initcli import --log '' && |
| 114 |
completes $(compgen -d) && |
| 115 |
true |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
test_import_options() { |
| 120 |
initcli imp - |
| 121 |
completes \ |
| 122 |
-h --help \ |
| 123 |
-c --copy -C --nocopy \ |
| 124 |
-w --write -W --nowrite \ |
| 125 |
-a --autotag -A --noautotag \ |
| 126 |
-p --resume -P --noresume \ |
| 127 |
-l --log --flat |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
test_list_options() { |
| 132 |
initcli list - |
| 133 |
completes \ |
| 134 |
-h --help \ |
| 135 |
-a --album \ |
| 136 |
-p --path |
| 137 |
} |
| 138 |
|
| 139 |
test_list_query() { |
| 140 |
initcli list 'x' && |
| 141 |
[[ -z "${COMPREPLY[@]}" ]] && |
| 142 |
|
| 143 |
initcli list 'art' && |
| 144 |
completes \ |
| 145 |
'artist:' \ |
| 146 |
'artpath:' && |
| 147 |
|
| 148 |
initcli list 'artits:x' && |
| 149 |
[[ -z "${COMPREPLY[@]}" ]] && |
| 150 |
true |
| 151 |
} |
| 152 |
|
| 153 |
test_help_command() { |
| 154 |
initcli help '' && |
| 155 |
completes $COMMANDS && |
| 156 |
true |
| 157 |
} |
| 158 |
|
| 159 |
test_plugin_command() { |
| 160 |
initcli te && |
| 161 |
completes test && |
| 162 |
|
| 163 |
initcli test - && |
| 164 |
completes -o --option && |
| 165 |
true |
| 166 |
} |
| 167 |
|
| 168 |
run_tests() { |
| 169 |
local tests=$(set | \ |
| 170 |
grep --extended-regexp --only-matching '^test_[a-zA-Z_]* \(\) $' |\ |
| 171 |
grep --extended-regexp --only-matching '[a-zA-Z_]*' |
| 172 |
) |
| 173 |
local fail=0 |
| 174 |
|
| 175 |
if [[ -n $@ ]]; then |
| 176 |
tests="$@" |
| 177 |
fi |
| 178 |
|
| 179 |
for t in $tests; do |
| 180 |
$t || { fail=1 && echo "$t failed" >&2; } |
| 181 |
done |
| 182 |
return $fail |
| 183 |
} |
| 184 |
|
| 185 |
run_tests "$@" && echo "completion tests passed" |