diff --git a/.github/workflows/zsh-n.yml b/.github/workflows/zsh-n.yml index 3aa32b4..34b59e7 100644 --- a/.github/workflows/zsh-n.yml +++ b/.github/workflows/zsh-n.yml @@ -12,6 +12,7 @@ on: - "tests/archive-extraction.zsh" - "tests/completion-refresh.zsh" - "tests/hook-ownership.zsh" + - "tests/load-object-status.zsh" - "tests/message-formatting.zsh" - "tests/path-resolution.zsh" - "tests/parallel-update.zsh" @@ -33,6 +34,7 @@ on: - "tests/archive-extraction.zsh" - "tests/completion-refresh.zsh" - "tests/hook-ownership.zsh" + - "tests/load-object-status.zsh" - "tests/message-formatting.zsh" - "tests/path-resolution.zsh" - "tests/parallel-update.zsh" @@ -147,6 +149,17 @@ jobs: run: sudo apt update && sudo apt-get install -yq zsh - name: Test autoload ice forms run: zsh -f tests/plugin-autoload-ice.zsh + load-object-status: + name: Load Object Status + 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 load object status + run: zsh -f tests/load-object-status.zsh + nested-load-state: name: Nested Load State runs-on: ubuntu-latest diff --git a/tests/load-object-status.zsh b/tests/load-object-status.zsh new file mode 100644 index 0000000..61e0a4e --- /dev/null +++ b/tests/load-object-status.zsh @@ -0,0 +1,86 @@ +#!/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-load-object-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" || fail "create isolated environment" + +# .zi-load-object is a thin dispatcher over .zi-load and .zi-load-snippet. Stub +# both so the status it reports is unambiguously the one it was given, with no +# dependency on a real plug-in, the network, or the filesystem. +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" \ + zsh -f <<'ZSH' || fail ".zi-load-object does not report the status of the load it performed" +builtin emulate -R zsh +setopt pipe_fail + +builtin source "${ZI_TEST_CHECKOUT}/zi.zsh" || return 1 +.zi-prepare-home || return 1 + +integer stub_status=0 +.zi-load() { return $stub_status; } +.zi-load-snippet() { return $stub_status; } + +check() { # check