From 1a96865c0b494121313f8be3ca57570c19be213e Mon Sep 17 00:00:00 2001 From: Vladislav Doster Date: Sun, 24 Dec 2023 08:10:44 -0600 Subject: [PATCH] fix: variable scope in delete command Signed-off-by: Vladislav Doster --- doc/zsdoc/zinit-autoload.zsh.adoc | 1 - doc/zsdoc/zinit-side.zsh.adoc | 1 - tests/_support/annex_test_assertions | 5 +++ tests/_support/bootstrap | 65 +++++++++++++++++----------- tests/gh-r.zunit | 19 +++++++- zinit-autoload.zsh | 2 +- 6 files changed, 63 insertions(+), 30 deletions(-) diff --git a/doc/zsdoc/zinit-autoload.zsh.adoc b/doc/zsdoc/zinit-autoload.zsh.adoc index efbc088fd..afcd46283 100644 --- a/doc/zsdoc/zinit-autoload.zsh.adoc +++ b/doc/zsdoc/zinit-autoload.zsh.adoc @@ -471,7 +471,6 @@ Has 111 line(s). Calls functions: |-- .zinit-prompt |-- .zinit-run-delete-hooks |   `-- zinit-side.zsh/.zinit-countdown - |-- zinit-side.zsh/.zinit-compute-ice |-- zinit.zsh/+zi-log |-- zinit.zsh/.zinit-any-to-user-plugin `-- zinit.zsh/zinit diff --git a/doc/zsdoc/zinit-side.zsh.adoc b/doc/zsdoc/zinit-side.zsh.adoc index 70fe0fe88..7f6ecde01 100644 --- a/doc/zsdoc/zinit-side.zsh.adoc +++ b/doc/zsdoc/zinit-side.zsh.adoc @@ -116,7 +116,6 @@ Uses feature(s): _setopt_ Called by: - zinit-autoload.zsh/.zinit-delete zinit-autoload.zsh/.zinit-edit zinit-autoload.zsh/.zinit-recall zinit-autoload.zsh/.zinit-update-or-status-snippet diff --git a/tests/_support/annex_test_assertions b/tests/_support/annex_test_assertions index 1ce82544b..5a3396b26 100644 --- a/tests/_support/annex_test_assertions +++ b/tests/_support/annex_test_assertions @@ -8,3 +8,8 @@ is_annex() { assert ${PWD}/${${annex}//zinit-annex/z-a}.plugin.zsh is_file assert ${PWD}/${${annex}//zinit-annex/z-a}.plugin.zsh is_readable } + +load_bin_gem_node(){ + run zinit load @zdharma-continuum/zinit-annex-bin-gem-node + zinit default-ice --quiet from'gh-r' +} diff --git a/tests/_support/bootstrap b/tests/_support/bootstrap index cb11e9a7c..22dbf8021 100755 --- a/tests/_support/bootstrap +++ b/tests/_support/bootstrap @@ -1,5 +1,5 @@ -#!/usr/bin/env zsh -setopt NO_GLOBAL_RCS NO_GLOBAL_EXPORT NO_RCS +emulate -L zsh +setopt no_global_rcs no_rcs no_aliases extended_glob null_glob # Log functions [[[ function error(){ print -P "%F{red}[ERROR]%f: ${1}" && return 1; } @@ -19,24 +19,31 @@ if [[ ! -d ${TMP_ZUNIT} ]]; then exit 1 fi -typeset -gAH ZINIT; -ZINIT[HOME_DIR]=${TMP_ZUNIT}; -ZINIT[BIN_DIR]=$ZINIT[HOME_DIR]/zinit.git; -ZINIT[COMPLETIONS_DIR]=$ZINIT[HOME_DIR]/completions; -ZINIT[PLUGINS_DIR]=$ZINIT[HOME_DIR]/plugins; -ZINIT[SNIPPETS_DIR]=$ZINIT[HOME_DIR]/snippets; -ZINIT[ZCOMPDUMP_PATH]=$ZINIT[HOME_DIR]/zcompdump; -ZPFX=$ZINIT[HOME_DIR]/polaris; +typeset -gx zi_test_dir="${TMP_ZUNIT}" +typeset -gxAUH ZINIT +# DEBUG 'true' +ZINIT+=( + BIN_DIR ${zi_test_dir}/zinit.git + COMPLETIONS_DIR ${zi_test_dir}/completions SNIPPETS_DIR ${zi_test_dir}/snippets + HOME_DIR ${zi_test_dir} PLUGINS_DIR ${zi_test_dir}/plugins + ZCOMPDUMP_PATH ${zi_test_dir}/zcompdump ZPFX ${zi_test_dir}/polaris + POLARIS ${zi_test_dir}/polaris +) +typeset -gxH ZPFX= +ZPFX="$zi_test_dir"/polaris +# FORK 'vladdoster' REPO 'zinit-t' +# typeset -gxAUH ZINIT=(${(kv)CONFIG}) command git diff > ${ZINIT[HOME_DIR]}/unstaged.diff -info 'creating test env' +# info 'creating test env' git clone \ + --quiet \ --depth=1 \ --dissociate \ --no-hardlinks \ --reference "${GIT_REPO}" \ file://${GIT_REPO:A} \ - "${ZINIT[BIN_DIR]}" + "${ZINIT[BIN_DIR]}" >/dev/null if (( $? != 0 )); then error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2 exit 1 @@ -46,23 +53,31 @@ if [[ -s $ZINIT[HOME_DIR]/unstaged.diff ]]; then ( git -C $ZINIT[BIN_DIR] apply $ZINIT[HOME_DIR]/unstaged.diff && \ chmod g-rwX "${ZINIT[HOME_DIR]}" && \ - zcompile "${ZINIT[BIN_DIR]}/zinit.zsh" - ) + zcompile "${ZINIT[BIN_DIR]}/zinit.zsh" >/dev/null + ) >/dev/null fi (( $? != 0 )) && { error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2; exit 1 } -source $ZINIT[BIN_DIR]/zinit.zsh -(( $? != 0 )) && { error "Unable to copy ${GIT_REPO} to ${TMP_ZUNIT}" >&2; exit 1 } +hash -f +builtin hash -d zinit=$zi_test_dir +builtin hash -d zpfx=$zi_test_dir/polaris +builtin hash -d plugins=$zi_test_dir/plugins +source $zi_test_dir/zinit.git/zinit.zsh +(( $? != 0 )) && { error "Unable to source zinit" >&2; exit 1 } +hash -f +builtin hash -d zinit=$zi_test_dir +builtin hash -d zpfx=$zi_test_dir/polaris +builtin hash -d plugins=$zi_test_dir/plugins # ]]] # Install Annexes [[[ -info 'installing test dependencies' -for annex (binary-symlink default-ice); do - if [[ ! -d ${GIT_REPO}/tests/_support/$annex ]]; then; - git clone https://github.com/zdharma-continuum/zinit-annex-$annex ${GIT_REPO:A}/tests/_support/$annex - fi - zinit light ${GIT_REPO:A}/tests/_support/$annex - info "loaded $annex dependencies" -done +# +zi-log '{m} installing test dependencies' +zinit for \ + @zdharma-continuum/zinit-annex-linkman \ + @zdharma-continuum/zinit-annex-default-ice \ + @zdharma-continuum/zinit-annex-binary-symlink \ + @zdharma-continuum/zinit-annex-bin-gem-node + ++zi-log "{m} loaded $annex dependencies" # ]]] +zinit zstatus -# vim:ft=zsh:sw=2:sts=2:et:foldmarker=[[[,]]]:foldmethod=marker diff --git a/tests/gh-r.zunit b/tests/gh-r.zunit index b2050f331..f82d6b617 100755 --- a/tests/gh-r.zunit +++ b/tests/gh-r.zunit @@ -1,10 +1,13 @@ #!/usr/bin/env zunit + + @setup { HOME="$ZPFX" # Stops programs creating directories in user home export ZBIN="${ZPFX}/bin" export os_type="${OSTYPE//[0-9\.]*/}" + load "${PWD}/tests/_support/annex_test_assertions" zinit default-ice --quiet from'gh-r' lbin } @@ -552,10 +555,22 @@ local mcfly="$ZBIN/mcfly"; assert "$mcfly" is_executable run $mcfly --version; assert $state equals 0 } -@test 'mdbook' { # Create book from markdown files. Like Gitbook but implemented in Rust +@test 'mdbook-lbin' { # Create book from markdown files. Like Gitbook but implemented in Rust run zinit for @rust-lang/mdBook; assert $state equals 0 local mdbook="$ZBIN/mdbook"; assert "$mdbook" is_executable - run $mdbook --version; assert $state equals 0 + run "$mdbook" --version; assert $state equals 0 + run file "$mdbook"; assert $output contains 'executable' + zinit delete --yes rust-lang/mdBook; + run "$mdbook" --version; assert $state equals 127; assert $output contains 'no such file or directory' +} +@test 'mdbook-sbin' { # Create book from markdown files. Like Gitbook but implemented in Rust + load_bin_gem_node + run zinit from'gh-r' sbin"mdbook" for @rust-lang/mdBook; assert $state equals 0 + local mdbook="$ZBIN/mdbook"; assert "$mdbook" is_executable + run "$mdbook" --version; assert $state equals 0 + run file "$mdbook"; assert $output contains 'zsh script'; assert $output contains 'ASCII text' + zinit delete --yes rust-lang/mdBook; assert $state equals 0 + run "$mdbook" --version; assert $state equals 127; assert $output contains 'no such file or directory' } @test 'mdcat' { # cat for markdown run zinit for @swsnr/mdcat; assert $state equals 0 diff --git a/zinit-autoload.zsh b/zinit-autoload.zsh index bed1eccec..7c8079921 100644 --- a/zinit-autoload.zsh +++ b/zinit-autoload.zsh @@ -1279,8 +1279,8 @@ EOF } local i if (( $#o_yes )) || ( .zinit-prompt "Delete ${(j:, :)@}"); then - local -A ICE ICE2 for i in $@; do + local -A ICE=() ICE2=() local the_id="${${i:#(%|/)*}}" filename is_snippet local_dir .zinit-compute-ice "$the_id" "pack" ICE2 local_dir filename is_snippet || return 1 if [[ "$local_dir" != /* ]]; then