# testkit/pstest

> Package pstest runs a test against each PowerShell edition.

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/testkit/pstest (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
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](/reference/go/testkit-pstest/#each), so one run covers both, and a host that lacks one fails with what to install. Production code never imports this package.


## Constants

```go
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.


## Each

```go
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](/reference/go/testkit-pstest/) names in environ. fn runs in parallel with its siblings.


## Unpack

```go
func Unpack(t testing.TB, archive string) string
```

Unpack 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

```go
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.
