Как написать автоматические тесты для завершения zsh?

Нет необходимости в chroot. Достаточно установить ESP перед запуском grub-install. grub-installдолжен подхватить его автоматически. Используйте --no-nvram, чтобы оставить переменные EFI нетронутыми.

grub-install --target=x86_64-efi --bootloader-id="Void Linux [GRUB]" --no-nvram /dev/sdb

/etc/default/grubне используется при установке grub -. Это актуально только для grub-mkconfig. Вы не упомянули grub-mkconfig, поэтому я предполагаю, что вы просите ненастроенную установку GRUB2.

3
11.09.2021, 20:22
1 ответ

Тестирование дополнений в Zsh требует немного больше усилий. Это связано с тем, что команды завершения Zsh могут запускаться только из виджета завершения, который, в свою очередь, может быть вызван только тогда, когда активен редактор строк Zsh. Чтобы иметь возможность выполнять завершение внутри скрипта, нам потребуется использовать так -называемый псевдотерминал , в котором у нас может быть активная командная строка для активации виджета завершения :

.
# Set up your completions as you would normally.
compdef _my-command my-command
_my-command () {
        _arguments '--help[display help text]'  # Just an example.
}

# Define our test function.
comptest () {
        # Add markup to make the output easier to parse.
        zstyle ':completion:*:default' list-colors \
                'no=<COMPLETION>' 'lc=' 'rc=' 'ec=</COMPLETION>'
        zstyle ':completion:*' group-name ''
        zstyle ':completion:*:messages' format \
                '<MESSAGE>%d</MESSAGE>'
        zstyle ':completion:*:descriptions' format \
                '<HEADER>%d</HEADER>'

        # Bind a custom widget to TAB.
        bindkey '^I' complete-word
        zle -C {,,}complete-word
        complete-word () {
                # Make the completion system believe we're on a 
                # normal command line, not in vared.
                unset 'compstate[vared]'

                # Add a delimiter before and after the completions.
                # Use of ^B and ^C as delimiters here is arbitrary.
                # Just use something that won't normally be printed.
                compadd -x $'\C-B'
                _main_complete "$@"
                compadd -J -last- -x $'\C-C'

                exit
        }

        vared -c tmp
}

zmodload zsh/zpty  # Load the pseudo terminal module.
zpty {,}comptest   # Create a new pty and run our function in it.

# Simulate a command being typed, ending with TAB to get completions.
zpty -w comptest $'my-command --h\t'

# Read up to the first delimiter. Discard all of this.
zpty -r comptest REPLY $'*\C-B'

zpty -r comptest REPLY $'*\C-C'  # Read up to the second delimiter.

# Print out the results.
print -r -- "${REPLY%$'\C-C'}"   # Trim off the ^C, just in case.

zpty -d comptest  # Delete the pty.

Запуск приведенного выше примера распечатает:


<HEADER>option</HEADER>
<COMPLETION>--help    display help text</COMPLETION>

Если вы не хотите тестировать весь вывод завершения, а просто хотите протестировать строки, которые будут вставлены в командную строку, см.https://stackoverflow.com/questions/65386043/unit-testing-zsh-completion-script/69164362#69164362

1
13.09.2021, 14:21

Теги

Похожие вопросы