// Setup sets up the given test environment for tests that use the go
// command. It adds support for go tags to p.Condition and adds the go
// command to p.Cmds. It also wraps p.Setup to set up the environment
// variables for running the go command appropriately.
//
// It checks go command can run, but not that it can build or run
// binaries.
Setup sets up the given test environment for tests that use the go
command. It adds support for go tags to p.Condition and adds the go
command to p.Cmds. It also wraps p.Setup to set up the environment
variables for running the go command appropriately.

It checks go command can run, but not that it can build or run
binaries.
// Setup sets up the given test environment for tests that use the go // command . It adds support for go tags to p . Condition and adds the go // command to p . Cmds . It also wraps p . Setup to set up the environment // variables for running the go command appropriately . // // It checks go command can run but not that it can build or run // binaries .
func Setup(p *testscript.Params) error {
	var c testContext
	if err := c.init(); err != nil {
		return err
	}
	origSetup := p.Setup
	p.Setup = func(e *testscript.Env) error {
		e.Vars = c.goEnviron(e.Vars)
		if origSetup != nil {
			return origSetup(e)
		}
		return nil
	}
	if p.Cmds == nil {
		p.Cmds = make(map[string]func(ts *testscript.TestScript, neg bool, args []string))
	}
	p.Cmds["go"] = cmdGo
	origCondition := p.Condition
	p.Condition = func(cond string) (bool, error) {
		switch cond {
		case runtime.GOOS, runtime.GOARCH, runtime.Compiler:
			return true, nil
		default:
			if imports.KnownArch[cond] || imports.KnownOS[cond] || cond == "gc" || cond == "gccgo" {
				return false, nil
			}
		}
		if origCondition == nil {
			return false, fmt.Errorf("unknown condition %q", cond)
		}
		return origCondition(cond)
	}
	return nil
}
func Setup ( p * testscript . Params ) error { var c testContext if err := c . init ( ) ; err != nil { return err } origSetup := p . Setup p . Setup = func ( e * testscript . Env ) error { e . Vars = c . goEnviron ( e . Vars ) if origSetup != nil { return origSetup ( e ) } return nil } if p . Cmds == nil { p . Cmds = make ( map [ string ] func ( ts * testscript . TestScript , neg bool , args [ ] string ) ) } p . Cmds [ " " ] = cmdGo origCondition := p . Condition p . Condition = func ( cond string ) ( bool , error ) { switch cond { case runtime . GOOS , runtime . GOARCH , runtime . Compiler : return true , nil default : if imports . KnownArch [ cond ] || imports . KnownOS [ cond ] || cond == " " || cond == " " { return false , nil } } if origCondition == nil { return false , fmt . Errorf ( " " , cond ) } return origCondition ( cond ) } return nil }
Setup sets up the given test environment for tests that use the go
command.
Setup sets up the given test environment for tests that use the go command .