zdharma-continuum.zinit/tests/commands.zunit
Vladislav Doster 8197f3215b test(commands): cover self-update pager flags
The fixture leaves the sandbox clone one commit behind a scratch bare
upstream built with git commit-tree from HEAD's own tree, so the
fast-forward pull moves only the branch pointer: the unstaged diff the
bootstrap applies stays intact and nothing needs restoring when an
assertion aborts a test. Works offline and on detached-HEAD checkouts
(CI pull_request) alike; a less() shadow function detects pager
invocation, and ambient pull.rebase/autostash settings are pinned off
in the clone so the pull output is stable across machines.

Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
2026-08-31 15:50:14 -05:00

143 lines
4.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env zunit
# vim:ft=zsh:sw=4:sts=4:et:foldmarker={,}:foldmethod=marker
#
# zdharma-continuum/zinit/tests/commands.zunit
# Copyright (c) 2016-2021 Sebastian Gniazdowski
# Copyright (c) 2021-2024 zdharma-continuum
# Homepage: https://github.com/zdharma-continuum/zinit
# License: MIT License
#
@setup {
typeset -gx HOME="$zi_test_dir"
typeset -gx ZBIN="$zi_test_dir/polaris/bin"
load "${PWD}/tests/_support/self_update_fixtures"
}
@test 'help' {
for cmd in 'help' '-h' '--help'; do
run zinit $cmd
assert $output contains '—— help usage information'
assert $state equals 0
done
run zinit -help
assert $output contains 'Unknown subcommand'
assert $state equals 1
}
@test 'delete --help' {
run zinit delete --help
assert $output contains 'zinit delete [options] [plugins...]'
assert $state equals 0
}
@test 'delete --all' {
run zinit as'completion' is-snippet for @'https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker'
assert $state equals 0
}
@test 'delete a snippet' {
run zinit id-as'git.zsh' is-snippet for @'OMZL::git.zsh'
run zinit delete --yes 'git.zsh'
assert $state equals 0
}
@test 'delete a plugin' {
run zinit from'gh-r' as'program' id-as mv'shfmt* -> shfmt' for @'mvdan/sh'
run zinit delete --yes sh
assert $state equals 0
}
@test 'delete a program' {
run zinit as'program' cp'wd.sh->wd' mv'_wd.sh->_wd' pick'wd' completions for @'mfaerevaag/wd'
assert $state equals 0
run return ${+commands[wd]}; assert $state equals 0
run zinit delete --yes mfaerevaag/wd
}
@test 'plugins' {
run perl -pe 's/\x1b\[[0-9;]*[mG]//g' <(zinit plugins)
assert $state equals 0
assert $output contains "==> 5 Plugins"
assert $output contains 'Loaded: L | Unloaded: U'
}
@test 'plugins with keyword' {
run perl -pe 's/\x1b\[[0-9;]*[mG]//g' <(zinit plugins zdharma)
assert $state equals 0
assert $output contains "==> 4 Plugins matching 'zdharma'"
}
@test 'self-update' {
run zinit self-update
assert $output matches 'Already up to date'; assert $state equals 0
run zinit self-update --help
assert $output matches '.*(HELP).*(self-update).*'; assert $state equals 1
run zinit self-update --quiet
assert $output is_empty; assert $state equals 0
}
@test 'self-update --help / -h shows help and exits 1' {
for flag in '--help' '-h'; do
run zinit self-update $flag
assert $output contains 'self-update'
assert $output contains '--quiet'
assert $output contains '--no-pager'
assert $state equals 1
done
}
@test 'self-update --quiet / -q suppresses output' {
for flag in '--quiet' '-q'; do
run zinit self-update $flag
assert $output is_empty
assert $state equals 0
done
}
@test 'self-update rejects unknown flags' {
run zinit self-update --foo
assert $output contains 'Incorrect options given'
assert $output contains '--foo'
assert $state equals 1
}
@test 'self-update --no-pager / -n accepted when up to date' {
for flag in '--no-pager' '-n'; do
run zinit self-update $flag
assert $output contains 'Already up to date'
assert $state equals 0
done
}
@test 'self-update pages the commit list through less by default' {
less() { command cat > /dev/null; builtin print -- 'PAGER-INVOKED'; }
make_self_update_behind_upstream
run zinit self-update
assert $output contains 'PAGER-INVOKED'
assert $output does_not_contain $SU_FIXTURE_SUBJECT
assert $state equals 0
}
@test 'self-update --no-pager / -n prints the commit list without the pager' {
less() { command cat > /dev/null; builtin print -- 'PAGER-INVOKED'; }
for flag in '--no-pager' '-n'; do
make_self_update_behind_upstream
run zinit self-update $flag
assert $output contains $SU_FIXTURE_SUBJECT
assert $output does_not_contain 'PAGER-INVOKED'
assert $state equals 0
done
}
@test 'self-update --quiet / -q skips the pager when behind upstream' {
less() { command cat > /dev/null; builtin print -- 'PAGER-INVOKED'; }
for flag in '--quiet' '-q'; do
make_self_update_behind_upstream
run zinit self-update $flag
assert $output is_empty
assert $state equals 0
done
restore_self_update_origin
}
@test 'set-debug' {
ZINIT+=(DEBUG 'true')
run +zi-log -n '{dbg} message'
assert $output contains '[debug]'; assert $state equals 0
}
@test 'unset-dbg' {
run +zi-log -n '{dbg} message'; assert $output contains ''
run +zi-log -n '{m} message'
assert $output contains 'message'; assert $state equals 0
}