testkit/pstest
import "github.com/barevoidco/zelk/core/testkit/pstest"Package pstest runs a test against each PowerShell edition.
Windows PowerShell 5.1 and PowerShell 7 differ in what zelk depends on: the syntax their parsers accept, their default output encoding, their error formatting and their ANSI output. A test that exercises PowerShell takes both through Each, so one run covers both, and a host that lacks one fails with what to install. Production code never imports this package.
Constants
Section titled “Constants”const ArchiveEnv = "ZELK_POWERSHELL_TEST_ARCHIVE"ArchiveEnv names the environment variable that holds the absolute path of a local copy of PowerShell-7.7.0-win-x64.zip. A host without PowerShell 7 installed runs the tests that need it from that archive, so the suite needs no network and no installer.
func Each(t *testing.T, environ []string, fn func(t *testing.T, ps Edition))Each runs fn as a subtest for Windows PowerShell 5.1 and for PowerShell 7, each named after its version. environ is the environment discovery searches, as a host would give it: tests pass os.Environ(). Both editions are required, so a missing one fails its subtest and says what to install: 5.1 ships with Windows, and PowerShell 7 is the installed copy discovery finds or else the pinned archive that ArchiveEnv names in environ. fn runs in parallel with its siblings.
Unpack
Section titled “Unpack”func Unpack(t testing.TB, archive string) stringUnpack unpacks the pinned PowerShell 7 zip at archive into a fresh test directory and returns where. It fails the test when archive is not an absolute path, is not the pinned file, or can’t be unpacked.
Edition
Section titled “Edition”type Edition struct { // Name is how the subtest is named: the edition and its version, such as // "pwsh-7.7.0". Name string // Path is the executable zelk's own discovery vouches for. Path string // Modern is PowerShell 7 and later (pwsh.exe); false is Windows // PowerShell 5.1. Modern bool}Edition is one installed PowerShell.