Skip to content
Myr

test-complete

This file

Path

ci/test-complete

88 lines · 2.8 KiB

Last changed by

test-complete: misc. improvementsdanabefore adoption2394f72

History of this file

Take it

1#!/usr/bin/env zsh23emulate zsh -o extended_glob -o no_unset -o warn_create_global45##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 diff21    local  rg=${ZSH_ARGZERO:a:h}/../${TARGET_DIR:-target}/release/rg22    local _rg=${ZSH_ARGZERO:a:h}/../crates/core/flags/complete/rg.zsh23    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 ]] || {31        print -ru2 - "${ZSH_ARGZERO:t}: rg not found: $rg"32        return 133    }34    [[ -e $_rg ]] || {35        print -ru2 - "${ZSH_ARGZERO:t}: _rg not found: $_rg"36        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)' |49        $rg -vw -- --print0 # False positives50    )"} )51    help_args=( ${(ou)help_args} )5253    # 'Parse' options out of the completion function54    comp_args=( ${(f)"$( get_comp_args $_rg )"} )55    comp_args=( ${comp_args#\!}       ) # Strip hidden indicator56    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-options61    comp_args=( ${(ou)comp_args} )6263    (( $#help_args )) || {64        print -ru2 - "${ZSH_ARGZERO:t}: Failed to get help_args"65        return 166    }67    (( $#comp_args )) || {68        print -ru2 - "${ZSH_ARGZERO:t}: Failed to get comp_args"69        return 170    }7172    diff=$(73        diff -U2 \74            -L 'rg --help' \75            -L '_rg' \76            =( print -rl - $help_args ) =( print -rl - $comp_args )77    )7879    (( $#diff )) && {80        print -ru2 - "${ZSH_ARGZERO:t}: zsh completion options differ from --help options:"81        print -rlu2 - $diff82        return 183    }84    print -r - OK85    return 086}8788main "$@"