Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/zsh-n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- "zi.zsh"
- "lib/**"
- "tests/annex-unregister.zsh"
- "tests/atinit-deferred-marker.zsh"
- "tests/archive-extraction.zsh"
- "tests/completion-refresh.zsh"
- "tests/hook-ownership.zsh"
Expand All @@ -36,6 +37,7 @@ on:
- "zi.zsh"
- "lib/**"
- "tests/annex-unregister.zsh"
- "tests/atinit-deferred-marker.zsh"
- "tests/archive-extraction.zsh"
- "tests/completion-refresh.zsh"
- "tests/hook-ownership.zsh"
Expand Down Expand Up @@ -256,6 +258,17 @@ jobs:
- name: Test annex unregister
run: zsh -f tests/annex-unregister.zsh

atinit-deferred-marker:
name: Atinit Deferred Marker
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Zsh
run: sudo apt update && sudo apt-get install -yq zsh
- name: Test atinit deferred marker
run: zsh -f tests/atinit-deferred-marker.zsh

archive-extraction:
name: Archive extraction
runs-on: ubuntu-latest
Expand Down
73 changes: 73 additions & 0 deletions tests/atinit-deferred-marker.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env zsh
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et

builtin emulate -R zsh
setopt pipe_fail

fail() {
builtin print -u2 -r -- "not ok - $1"
exit 1
}

typeset project_root="${ZI_TEST_CHECKOUT:-${0:A:h:h}}"
typeset temp_root
temp_root="$(command mktemp -d "${TMPDIR:-/tmp}/zi-atinit-marker-test.XXXXXXXX")" ||
fail "create temporary directory"
trap 'command rm -rf -- "$temp_root"' EXIT INT TERM

command mkdir -p \
"${temp_root}/home" \
"${temp_root}/cache" \
"${temp_root}/config" \
"${temp_root}/data" \
"${temp_root}/zdotdir" \
"${temp_root}/cmdplug" \
"${temp_root}/normplug" || fail "create isolated environment"

builtin print -rl -- '#!/bin/sh' 'echo tool' \
> "${temp_root}/cmdplug/mytool" || fail "write the command plug-in payload"
command chmod +x "${temp_root}/cmdplug/mytool" || fail "make the payload executable"
builtin print -r -- ':' \
> "${temp_root}/normplug/normplug.plugin.zsh" || fail "write the normal plug-in"

env \
HOME="${temp_root}/home" \
XDG_CACHE_HOME="${temp_root}/cache" \
XDG_CONFIG_HOME="${temp_root}/config" \
XDG_DATA_HOME="${temp_root}/data" \
ZDOTDIR="${temp_root}/zdotdir" \
ZI_TEST_CHECKOUT="$project_root" \
ZI_TEST_ROOT="$temp_root" \
zsh -f <<'ZSH' || fail "a deferred atinit hook did not run"
builtin emulate -R zsh
setopt pipe_fail

builtin source "${ZI_TEST_CHECKOUT}/zi.zsh" || return 1
.zi-prepare-home || return 1

# The `!' prefix defers the hook, and the prefix has to be stripped before the
# body is evaluated. Two branches strip it, and each had its own defect:
# the command branch wrote the strip inside the subscript, `${ICE[atinit#!]}',
# which looks up a key that does not exist and silently evaluated nothing; the
# nocd branch of the source path stripped `1' instead of `!', leaving the body
# to fail as a command called `!typeset'.

# Command branch, without nocd.
zi ice as"command" pick"mytool" atinit'!typeset -g ZI_TEST_MARK_CMD=ran'
zi load "${ZI_TEST_ROOT}/cmdplug" >/dev/null 2>&1
[[ ${ZI_TEST_MARK_CMD:-unset} == ran ]] || {
builtin print -u2 -r -- "as\"command\" deferred atinit did not run: ${ZI_TEST_MARK_CMD:-unset}"
return 1
}

# Source path, with nocd active.
zi ice nocd atinit'!typeset -g ZI_TEST_MARK_NOCD=ran'
zi load "${ZI_TEST_ROOT}/normplug" >/dev/null 2>&1
[[ ${ZI_TEST_MARK_NOCD:-unset} == ran ]] || {
builtin print -u2 -r -- "nocd deferred atinit did not run: ${ZI_TEST_MARK_NOCD:-unset}"
return 1
}
ZSH

builtin print -r -- "ok - the deferred atinit marker is stripped on the command and nocd branches"
4 changes: 2 additions & 2 deletions zi.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@ builtin setopt no_aliases
(( ++ ZI[TMP_SUBST_DEPTH] ))
}
local ZERO
[[ $ICE[atinit] = '!'* ]] && { local ___oldcd="$PWD"; (( ${+ICE[nocd]} == 0 )) && { () { builtin setopt local_options no_auto_pushd; builtin cd -q "${${${(M)___user:#%}:+$___plugin}:-${ZI[PLUGINS_DIR]}/${___id_as//\//---}}"; } && eval "${ICE[atinit#!]}"; ((1)); } || eval "${ICE[atinit]#!}"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; }
[[ $ICE[atinit] = '!'* ]] && { local ___oldcd="$PWD"; (( ${+ICE[nocd]} == 0 )) && { () { builtin setopt local_options no_auto_pushd; builtin cd -q "${${${(M)___user:#%}:+$___plugin}:-${ZI[PLUGINS_DIR]}/${___id_as//\//---}}"; } && eval "${ICE[atinit]#!}"; ((1)); } || eval "${ICE[atinit]#!}"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; }
[[ -n ${ICE[src]} ]] && { ZERO="${${(M)ICE[src]##/*}:-$___pdir_orig/${ICE[src]}}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }; }
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___pdir_orig"; }; eval "reply=(${ICE[multisrc]})"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; local ___fname; for ___fname in "${reply[@]}"; do ZERO="${${(M)___fname:#/*}:-$___pdir_orig/$___fname}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }; done; }
# Run the atload hooks right before atload ice.
Expand Down Expand Up @@ -1895,7 +1895,7 @@ builtin setopt no_aliases
(( ${+ICE[blockf]} )) && { local -a fpath_bkp; fpath_bkp=( "${fpath[@]}" ); }
local ZERO="$___pdir_path/$___fname"
(( ${+ICE[aliases]} )) || builtin setopt no_aliases
[[ $ICE[atinit] = '!'* ]] && { local ___oldcd="$PWD"; (( ${+ICE[nocd]} == 0 )) && { () { builtin setopt local_options no_auto_pushd; builtin cd -q "${${${(M)___user:#%}:+$___plugin}:-${ZI[PLUGINS_DIR]}/${___id_as//\//---}}"; } && eval "${ICE[atinit]#!}"; ((1)); } || eval "${ICE[atinit]#1}"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; }
[[ $ICE[atinit] = '!'* ]] && { local ___oldcd="$PWD"; (( ${+ICE[nocd]} == 0 )) && { () { builtin setopt local_options no_auto_pushd; builtin cd -q "${${${(M)___user:#%}:+$___plugin}:-${ZI[PLUGINS_DIR]}/${___id_as//\//---}}"; } && eval "${ICE[atinit]#!}"; ((1)); } || eval "${ICE[atinit]#!}"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; }
(( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }
[[ -n ${ICE[src]} ]] && { ZERO="${${(M)ICE[src]##/*}:-$___pdir_orig/${ICE[src]}}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }; }
[[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___pdir_orig"; }; eval "reply=(${ICE[multisrc]})"; () { builtin setopt local_options no_auto_pushd; builtin cd -q "$___oldcd"; }; for ___fname in "${reply[@]}"; do ZERO="${${(M)___fname:#/*}:-$___pdir_orig/$___fname}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); } done; }
Expand Down
Loading