| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | shellcheck "$cliScript" |
| 5 | shellcheck "$bashCompletion" |
| 6 | # The linter cannot read zsh; a bare parse is the cheap check. |
| 7 | zsh -n "$zshCompletion" |
| 8 | # The completion turns the handle cache into candidates, ready changes |
| 9 | # first, with the title as the description, and then the branches. _describe |
| 10 | # and compadd are stubbed to print what they are given. |
| 11 | repo="$PWD/completion-repo" |
| 12 | git init --quiet "$repo" |
| 13 | mkdir "$repo/.git/valley" |
| 14 | printf 'mxrr\tready\tbump-the-valley-8770343e\tflake: bump the-valley\nhttp:abcd\tdraft\t\tno branch\n' > "$repo/.git/valley/handles" |
| 15 | git -C "$repo" update-ref refs/remotes/origin/topic HEAD 2>/dev/null || true |
| 16 | cat > complete.zsh <<'ZSH' |
| 17 | _describe() { print -r -- "describe $*"; print -rl -- "${(P@)${@[-1]}}" | sed 's/^/ /'; } |
| 18 | compadd() { print -r -- "compadd $*"; } |
| 19 | words=(valley review '') |
| 20 | CURRENT=3 |
| 21 | source "$1" |
| 22 | ZSH |
| 23 | (cd "$repo" && zsh "$OLDPWD/complete.zsh" "$zshCompletion") > complete.out |
| 24 | grep -q '^ mxrr:flake: bump the-valley$' complete.out |
| 25 | grep -q '^ http\\:abcd:no branch$' complete.out |
| 26 | # With no cache, the branches alone. |
| 27 | rm "$repo/.git/valley/handles" |
| 28 | (cd "$repo" && zsh "$OLDPWD/complete.zsh" "$zshCompletion") > complete.out |
| 29 | if grep -q describe complete.out; then exit 1; fi |
| 30 | valley help > help.txt |
| 31 | grep -q '^usage: valley' help.txt |
| 32 | test "$(wc -l < help.txt)" -le 50 |
| 33 | expected_verbs="ready |
| 34 | unready |
| 35 | withdraw |
| 36 | rebase |
| 37 | checks |
| 38 | pending |
| 39 | review |
| 40 | approve |
| 41 | status |
| 42 | changes |
| 43 | plan |
| 44 | knot |
| 45 | tail |
| 46 | replay |
| 47 | self-update |
| 48 | telemetry" |
| 49 | verbs="$(awk '/^ [a-z]/ { print $1 }' help.txt)" |
| 50 | test "$verbs" = "$expected_verbs" |
| 51 | for v in $verbs; do |
| 52 | valley help "$v" > "help-$v.txt" |
| 53 | grep -q "^usage: valley $v" "help-$v.txt" |
| 54 | valley "$v" --help > "help-$v-flag.txt" |
| 55 | cmp -s "help-$v.txt" "help-$v-flag.txt" |
| 56 | valley "$v" -h > "help-$v-short.txt" |
| 57 | cmp -s "help-$v.txt" "help-$v-short.txt" |
| 58 | done |
| 59 | if valley help unknown-verb > /dev/null 2> err.txt; then exit 1; fi |
| 60 | grep -q 'unknown help topic: unknown-verb' err.txt |
| 61 | # Both zsh and bash completions complete all 16 verbs after `valley help`. |
| 62 | cat > complete-help.zsh <<'ZSH' |
| 63 | _describe() { print -r -- "describe $*"; print -rl -- "${(P@)${@[-1]}}" | sed 's/^/ /'; } |
| 64 | compadd() { print -r -- "compadd $*"; } |
| 65 | words=(valley help '') |
| 66 | CURRENT=3 |
| 67 | source "$1" |
| 68 | ZSH |
| 69 | zsh "$PWD/complete-help.zsh" "$zshCompletion" > complete-help.out |
| 70 | for v in $verbs; do |
| 71 | grep -q "^ $v:" complete-help.out |
| 72 | done |
| 73 | complete() { :; } |
| 74 | # shellcheck disable=SC2086 |
| 75 | compgen() { printf '%s\n' $2; } |
| 76 | # shellcheck disable=SC1090 |
| 77 | source "$bashCompletion" |
| 78 | COMP_WORDS=(valley help '') |
| 79 | COMP_CWORD=2 |
| 80 | _valley |
| 81 | for v in $verbs; do |
| 82 | printf '%s\n' "${COMPREPLY[@]}" | grep -qx "$v" |
| 83 | done |
| 84 | test -f "$valley/share/bash-completion/completions/valley" |
| 85 | test -f "$valley/share/zsh/site-functions/_valley" |
| 86 | touch "$out" |