Functions
AddToolChainScriptConditions
function
#
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 AddToolChainScriptConditions(t *testing.T, conds map[string]script.Cond, goHostOS string, goHostArch string)
CachedExec
function
#
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 CachedExec() script.Cond
DefaultCmds
function
#
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 DefaultCmds() map[string]script.Cmd
DefaultConds
function
#
DefaultConds returns a set of broadly useful script conditions.
This set includes all of the conditions in script.DefaultConds,
as well as:
- Conditions of the form "exec:foo" are active when the executable "foo" is
found in the test process's PATH, and inactive when the executable is
not found.
- "short" is active when testing.Short() is true.
- "verbose" is active when testing.Verbose() is true.
func DefaultConds() map[string]script.Cond
Error
method
#
func (s skipError) Error() string
ReplaceGoToolInTestGoRoot
function
#
ReplaceGoToolInTestGoRoot replaces the go tool binary toolname with
an alternate executable newtoolpath within a test GOROOT directory
previously created by SetupTestGoRoot.
func ReplaceGoToolInTestGoRoot(t *testing.T, testgoroot string, toolname string, newtoolpath string)
Run
function
#
Run runs the script from the given filename starting at the given initial state.
When the script completes, Run closes the state.
func Run(t testing.TB, e *script.Engine, s *script.State, filename string, testScript io.Reader)
RunTests
function
#
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 RunTests(t *testing.T, ctx context.Context, engine *script.Engine, env []string, pattern string)
RunToolScriptTest
function
#
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 RunToolScriptTest(t *testing.T, repls []ToolReplacement, scriptsdir string, fixReadme bool)
SetupTestGoRoot
function
#
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 SetupTestGoRoot(t *testing.T, tmpdir string, goroot string) string
Skip
function
#
Skip returns a sentinel error that causes Run to mark the test as skipped.
func Skip() script.Cmd
cgoLinkExt
function
#
func cgoLinkExt(s *script.State) (bool, error)
checkScriptReadme
function
#
func checkScriptReadme(t *testing.T, engine *script.Engine, env []string, scriptspath string, gotool string, fixReadme bool)
hasBuildmode
function
#
func hasBuildmode(s *script.State, mode string) (bool, error)
hasGodebug
function
#
func hasGodebug(s *script.State, value string) (bool, error)
hasGoexperiment
function
#
func hasGoexperiment(s *script.State, value string) (bool, error)
initScriptDirs
function
#
func initScriptDirs(t testing.TB, s *script.State)
linkOrCopy
function
#
linkOrCopy creates a link to src at dst, or if the symlink fails
(platform doesn't support) then copies src to dst.
func linkOrCopy(t *testing.T, src string, dst string)
mustLinkExt
function
#
func mustLinkExt(s *script.State) (bool, error)
pieLinkExt
function
#
func pieLinkExt(s *script.State) (bool, error)
scriptCC
function
#
scriptCC runs the platform C compiler.
func scriptCC(cmdExec script.Cmd, ccexe string) script.Cmd
sysCondition
function
#
func sysCondition(flag string, f func(goos string, goarch string) bool, needsCgo bool, goHostOS string, goHostArch string) script.Cond
tempEnvName
function
#
func tempEnvName() string