package scripttest

import "cmd/internal/script/scripttest"

Package scripttest adapts the script engine for use in tests.

Package scripttest adapts the script engine for use in tests.

Package scripttest adapts the script engine for use in tests.

Package scripttest adapts the script engine for use in tests.

Index

Functions

func AddToolChainScriptConditions

func AddToolChainScriptConditions(t *testing.T, conds map[string]script.Cond, goHostOS, goHostArch string)

AddToolChainScriptConditions accepts a script.Cond map and adds into it a set of commonly used conditions for doing toolchains testing, including whether the platform supports cgo, a buildmode condition, support for GOEXPERIMENT testing, etc. Callers must also pass in current GOHOSTOOS/GOHOSTARCH settings, since some of the conditions introduced can be influenced by them.

func CachedExec

func CachedExec() script.Cond

CachedExec returns a Condition that reports whether the PATH of the test binary itself (not the script's current environment) contains the named executable.

func DefaultCmds

func DefaultCmds() map[string]script.Cmd

DefaultCmds returns a set of broadly useful script commands.

This set includes all of the commands in script.DefaultCmds, as well as a "skip" command that halts the script and causes the testing.TB passed to Run to be skipped.

func DefaultConds

func DefaultConds() map[string]script.Cond

DefaultConds returns a set of broadly useful script conditions.

This set includes all of the conditions in script.DefaultConds, as well as:

func ReplaceGoToolInTestGoRoot

func ReplaceGoToolInTestGoRoot(t *testing.T, testgoroot, toolname, newtoolpath string)

ReplaceGoToolInTestGoRoot replaces the go tool binary toolname with an alternate executable newtoolpath within a test GOROOT directory previously created by SetupTestGoRoot.

func Run

func Run(t testing.TB, e *script.Engine, s *script.State, filename string, testScript io.Reader)

Run runs the script from the given filename starting at the given initial state. When the script completes, Run closes the state.

func RunTests

func RunTests(t *testing.T, ctx context.Context, engine *script.Engine, env []string, pattern string)

RunTests kicks off one or more script-based tests using the specified engine, running all test files that match pattern. This function adapted from Russ's rsc.io/script/scripttest#Run function, which was in turn forked off cmd/go's runner.

func RunToolScriptTest

func RunToolScriptTest(t *testing.T, repls []ToolReplacement, scriptsdir string, fixReadme bool)

RunToolScriptTest kicks off a set of script tests runs for a tool of some sort (compiler, linker, etc). The expectation is that we'll be called from the top level cmd/X dir for tool X, and that instead of executing the install tool X we'll use the test binary instead.

func SetupTestGoRoot

func SetupTestGoRoot(t *testing.T, tmpdir string, goroot string) string

SetupTestGoRoot sets up a temporary GOROOT for use with script test execution. It copies the existing goroot bin and pkg dirs using symlinks (if possible) or raw copying. Return value is the path to the newly created testgoroot dir.

func Skip

func Skip() script.Cmd

Skip returns a sentinel error that causes Run to mark the test as skipped.

Types

type ToolReplacement

type ToolReplacement struct {
	ToolName        string // e.g. compile, link, addr2line, etc
	ReplacementPath string // path to replacement tool exe
	EnvVar          string // env var setting (e.g. "FOO=BAR")
}

ToolReplacement records the name of a tool to replace within a given GOROOT for script testing purposes.

Source Files

conditions.go doc.go readme.go run.go scripttest.go setup.go

Version
v1.24.0 (latest)
Published
Feb 10, 2025
Platform
linux/amd64
Imports
21 packages
Last checked
43 minutes ago

Tools for package owners.