test-complete
This file
Path
ci/test-complete
88 lines · 2.8 KiB
Last changed by
test-complete: misc. improvementsdanabefore adoption2394f72
History of this fileTake it
The walk stopped after 200 commits: lines older than 5f5da48 point at it.
globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 1–2why, one step back1#!/usr/bin/env zsh2test-complete: misc. improvementsdanabefore adoption2394f72
line 3why, one step back3emulate zsh -o extended_glob -o no_unset -o warn_create_globalglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 4–20why, one step back45##6# Compares options in `rg --help` output to options in zsh completion function78get_comp_args() {9 # Technically there are many options that the completion system sets that10 # our function may rely on, but we'll trust that we've got it mostly right11 setopt local_options unset1213 # Our completion function recognises a special variable which tells it to14 # dump the _arguments specs and then just return. But do this in a sub-shell15 # anyway to avoid any weirdness16 ( _RG_COMPLETE_LIST_ARGS=1 source $1 )17}1819main() {20 local difftest-complete: misc. improvementsdanabefore adoption2394f72
lines 21–22why, one step back21 local rg=${ZSH_ARGZERO:a:h}/../${TARGET_DIR:-target}/release/rg22 local _rg=${ZSH_ARGZERO:a:h}/../crates/core/flags/complete/rg.zshglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 23–30why, one step back23 local -a help_args comp_args2425 [[ -e $rg ]] || rg=${rg/%\/release\/rg/\/debug\/rg}2627 rg=${rg:a}28 _rg=${_rg:a}2930 [[ -e $rg ]] || {test-complete: misc. improvementsdanabefore adoption2394f72
line 31why, one step back31 print -ru2 - "${ZSH_ARGZERO:t}: rg not found: $rg"globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 32–34why, one step back32 return 133 }34 [[ -e $_rg ]] || {test-complete: misc. improvementsdanabefore adoption2394f72
line 35why, one step back35 print -ru2 - "${ZSH_ARGZERO:t}: _rg not found: $_rg"globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 36–48why, one step back36 return 137 }3839 print -rl - 'Comparing options:' "-$rg" "+$_rg"4041 # 'Parse' options out of the `--help` output. To prevent false positives we42 # only look at lines where the first non-white-space character is `-`, or43 # where a long option starting with certain letters (see `_rg`) is found.44 # Occasionally we may have to handle some manually, however45 help_args=( ${(f)"$(46 $rg --help |47 $rg -i -- '^\s+--?[a-z0-9.]|--[a-z]' |48 $rg -ior '$1' -- $'[\t /\"\'`.,](-[a-z0-9.]|--[a-z0-9-]+)(,|\\b)' |test-complete: misc. improvementsdanabefore adoption2394f72
line 49why, one step back49 $rg -vw -- --print0 # False positivesglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
line 50why, one step back50 )"} )test-complete: misc. improvementsdanabefore adoption2394f72
line 51why, one step back51 help_args=( ${(ou)help_args} )globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 52–54why, one step back5253 # 'Parse' options out of the completion function54 comp_args=( ${(f)"$( get_comp_args $_rg )"} )test-complete: misc. improvementsdanabefore adoption2394f72
line 55why, one step back55 comp_args=( ${comp_args#\!} ) # Strip hidden indicatorglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 56–60why, one step back56 comp_args=( ${comp_args#\(*\)} ) # Strip excluded options57 comp_args=( ${comp_args#\*} ) # Strip repetition indicator58 comp_args=( ${comp_args%%-[:[]*} ) # Strip everything after -optname-59 comp_args=( ${comp_args%%[:+=[]*} ) # Strip everything after other optspecs60 comp_args=( ${comp_args##[^-]*} ) # Remove non-optionstest-complete: misc. improvementsdanabefore adoption2394f72
line 61why, one step back61 comp_args=( ${(ou)comp_args} )globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 62–63why, one step back6263 (( $#help_args )) || {test-complete: misc. improvementsdanabefore adoption2394f72
line 64why, one step back64 print -ru2 - "${ZSH_ARGZERO:t}: Failed to get help_args"globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 65–67why, one step back65 return 166 }67 (( $#comp_args )) || {test-complete: misc. improvementsdanabefore adoption2394f72
line 68why, one step back68 print -ru2 - "${ZSH_ARGZERO:t}: Failed to get comp_args"globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 69–71why, one step back69 return 170 }71test-complete: misc. improvementsdanabefore adoption2394f72
lines 72–77why, one step back72 diff=$(73 diff -U2 \74 -L 'rg --help' \75 -L '_rg' \76 =( print -rl - $help_args ) =( print -rl - $comp_args )77 )globset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 78–79why, one step back7879 (( $#diff )) && {test-complete: misc. improvementsdanabefore adoption2394f72
lines 80–81why, one step back80 print -ru2 - "${ZSH_ARGZERO:t}: zsh completion options differ from --help options:"81 print -rlu2 - $diffglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 82–83why, one step back82 return 183 }test-complete: misc. improvementsdanabefore adoption2394f72
line 84why, one step back84 print -r - OKglobset: support nested alternatesLuke Sandbergbefore adoption5f5da48
lines 85–88why, one step back85 return 086}8788main "$@"