Repository navigation
Expand file tree
/
Copy pathbashunit.bash
More file actions
135 lines (124 loc) · 5.89 KB
/
Copy pathbashunit.bash
File metadata and controls
135 lines (124 loc) · 5.89 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# bash completion for bashunit -*- shell-script -*-
#
# Install (bash-completion):
# cp completions/bashunit.bash /usr/local/etc/bash_completion.d/bashunit
# or source it from your ~/.bashrc:
# source /path/to/bashunit/completions/bashunit.bash
#
# Kept in sync with src/main/test.sh and src/main/subcommands.sh by
# tests/unit/main/completions_test.sh (anti-drift).
# Works on bash 3.0+ (plain compgen -W, no bash-completion helpers required).
_BASHUNIT_COMPLETIONS_SUBCOMMANDS="test bench doc init upgrade assert watch"
# Flags accepted by the doc subcommand.
_BASHUNIT_COMPLETIONS_DOC_OPTS="--custom -e --env --boot -h --help"
_BASHUNIT_COMPLETIONS_TEST_OPTS="--assert --boot --changed --coverage --coverage-exclude \
--coverage-diff --coverage-min --coverage-paths --coverage-report --coverage-report-cobertura --coverage-report-html \
--debug --detailed --dry-run --env --exclude-filter --exclude-tag --fail-on-flaky --fail-on-risky --failures-only \
--filter --gha-annotations --help --id --jobs --list --list-format --list-suites --list-tags \
--log-gha --log-junit --login --no-color \
--no-coverage-report --no-output --no-output-on-failure --no-parallel \
--no-progress --no-snapshot-create --order-by --output --parallel --profile \
--random-order --repeat --report-html \
--report-json --report-junit --report-md --report-tap --rerun-failed --retry --run-all \
--sandbox --sandbox-allow \
--seed --shard --show-incomplete --show-output --show-skipped --simple \
--skip-env-file --snapshot-prune --snapshot-report-unused --snapshot-update -u \
--pass-with-no-tests --stop-on-failure --strict --suite --tag \
--test-timeout --verbose \
--watch -R -S -a -e -f -h -j -l -p -r -s -vvv -w"
_BASHUNIT_COMPLETIONS_ASSERT_FNS="assert_array_contains assert_array_length \
assert_array_not_contains assert_arrays_equal assert_assertion_fails \
assert_assertion_fails_with assert_assertion_passes assert_between assert_command_available assert_command_not_found \
assert_contains assert_contains_ignore_case assert_date_after \
assert_date_before assert_date_equals assert_date_within_delta \
assert_date_within_range assert_directory_exists assert_directory_not_exists \
assert_duration assert_duration_greater_than assert_duration_less_than \
assert_empty assert_equals assert_exec assert_exit_code assert_false \
assert_file_contains assert_file_exists assert_file_not_contains \
assert_file_not_exists assert_file_permissions assert_files_equals \
assert_files_not_equals assert_general_error assert_greater_or_equal_than \
assert_greater_than assert_is_directory assert_is_directory_empty \
assert_is_directory_not_empty assert_is_directory_not_readable \
assert_is_directory_not_writable assert_is_directory_readable \
assert_is_directory_writable assert_is_file assert_is_file_empty assert_is_file_executable \
assert_is_file_not_empty assert_is_file_not_executable assert_is_file_not_readable \
assert_is_file_not_writable assert_is_file_readable assert_is_file_writable \
assert_is_not_symlink assert_is_symlink \
assert_json_contains assert_json_equals assert_json_key_exists assert_json_key_not_exists assert_json_length \
assert_less_or_equal_than assert_less_than assert_line_count \
assert_match_named_snapshot assert_match_named_snapshot_ignore_colors \
assert_match_snapshot assert_match_snapshot_ignore_colors assert_matches \
assert_not_between assert_not_contains assert_not_empty assert_not_equals assert_not_matches \
assert_not_same assert_same assert_string_ends_with \
assert_string_matches_format assert_string_not_ends_with \
assert_string_not_matches_format assert_string_not_starts_with \
assert_string_starts_with assert_successful_code assert_symlink_to assert_true \
assert_unsuccessful_code assert_within_delta"
# compgen output is split into COMPREPLY words on purpose; mapfile/read -a would need bash 4+.
# shellcheck disable=SC2207
_bashunit_completions() {
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"
# Value hints for options that take an argument.
case "$prev" in
--output)
COMPREPLY=($(compgen -W "text tap json junit" -- "$cur"))
return 0
;;
-j | --jobs)
COMPREPLY=($(compgen -W "auto" -- "$cur"))
return 0
;;
-e | --env | --boot)
COMPREPLY=($(compgen -f -- "$cur"))
return 0
;;
--list-format)
COMPREPLY=($(compgen -W "text json" -- "$cur"))
return 0
;;
--order-by)
COMPREPLY=($(compgen -W "defined defects random" -- "$cur"))
return 0
;;
--gha-annotations)
COMPREPLY=($(compgen -W "auto always never" -- "$cur"))
return 0
;;
-f | --filter | --id | --exclude-filter | --sandbox-allow | --suite | --tag | --exclude-tag | --repeat | --retry | --seed | --shard | --test-timeout)
return 0
;;
esac
# `bashunit assert <fn>` completes the public assertion names.
if [ "$COMP_CWORD" -ge 2 ] && [ "${COMP_WORDS[1]}" = "assert" ]; then
COMPREPLY=($(compgen -W "$_BASHUNIT_COMPLETIONS_ASSERT_FNS" -- "$cur"))
return 0
fi
# `bashunit doc <filter>` completes assertion names, plus its own flags.
if [ "$COMP_CWORD" -ge 2 ] && [ "${COMP_WORDS[1]}" = "doc" ]; then
case "$cur" in
-*) COMPREPLY=($(compgen -W "$_BASHUNIT_COMPLETIONS_DOC_OPTS" -- "$cur")) ;;
*) COMPREPLY=($(compgen -W "$_BASHUNIT_COMPLETIONS_ASSERT_FNS" -- "$cur")) ;;
esac
return 0
fi
# First word: subcommands (plus flags, since `test` is the default command).
if [ "$COMP_CWORD" -eq 1 ] && [ "${cur#-}" = "$cur" ]; then
COMPREPLY=($(compgen -W "$_BASHUNIT_COMPLETIONS_SUBCOMMANDS" -- "$cur"))
# Also offer test files/dirs, as `bashunit tests/` is the common shorthand.
COMPREPLY+=($(compgen -f -- "$cur"))
return 0
fi
case "$cur" in
-*)
COMPREPLY=($(compgen -W "$_BASHUNIT_COMPLETIONS_TEST_OPTS" -- "$cur"))
;;
*)
COMPREPLY=($(compgen -f -- "$cur"))
;;
esac
return 0
}
complete -o filenames -F _bashunit_completions bashunit 2>/dev/null || true