Documentation
¶
Overview ¶
Package testenv holds small helpers that keep tests portable across operating systems. It is only imported from _test.go files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FakeBinary ¶
FakeBinary writes a do-nothing executable named name into dir and returns its path.
On Windows the file gets a .bat suffix, because exec.LookPath there resolves only the suffixes listed in %PATHEXT% -- an extensionless file is invisible to it, however executable its mode bits claim to be.
func RequireShell ¶
RequireShell skips the test unless a POSIX shell is on PATH.
The GitHub Windows runners ship Git for Windows, so "bash" and "sh" resolve there; a bare Windows box has neither. Tests that drive shell commands call this instead of hardcoding /bin/sh, which never exists on Windows.
func SetHome ¶
SetHome points the user's home directory at dir for the duration of the test.
os.UserHomeDir reads $HOME on Unix but %USERPROFILE% on Windows, so a test that sets only HOME still resolves to the real profile directory there -- which makes the test read and write the developer's (or CI runner's) actual ~/.pi-go instead of its sandbox.
func SetUnwritableHome ¶
SetUnwritableHome points the home directory at a regular file for the duration of the test, so anything the code under test tries to create below ~ fails. It returns that path.
Tests used to spell this as HOME=/nonexistent/..., which does not travel: on Windows a leading slash is drive-relative, so os.MkdirAll cheerfully creates the directory and the expected failure never happens.
Types ¶
This section is empty.