Skip to content

Commit

Permalink
fix: variable scope in delete command
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Doster <[email protected]>
  • Loading branch information
vladdoster committed Dec 24, 2023
1 parent 358ef03 commit 1ec0670
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 30 deletions.
1 change: 0 additions & 1 deletion doc/zsdoc/zinit-autoload.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion doc/zsdoc/zinit-side.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/_support/annex_test_assertions
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
65 changes: 40 additions & 25 deletions tests/_support/bootstrap
Original file line number Diff line number Diff line change
@@ -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; }
Expand All @@ -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
Expand All @@ -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
19 changes: 17 additions & 2 deletions tests/gh-r.zunit
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -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 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
Expand Down
2 changes: 1 addition & 1 deletion zinit-autoload.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1ec0670

Please sign in to comment.