Documentation ¶
Index ¶
- Constants
- func IgnoreMissedCoverage()
- func Run(t *testing.T, p Params)
- func RunMain(m TestingM, commands map[string]func() int) (exitCode int)
- func RunT(t T, p Params)
- type Config
- type Env
- type Params
- type Phase
- type Runner
- type Script
- func (ts *Script) BackgroundCmds() []*exec.Cmd
- func (ts *Script) Check(err error)
- func (ts *Script) CmdCall(neg int, args []string)
- func (ts *Script) CmdCd(neg int, args []string)
- func (ts *Script) CmdChmod(neg int, args []string)
- func (ts *Script) CmdCmp(neg int, args []string)
- func (ts *Script) CmdCmpenv(neg int, args []string)
- func (ts *Script) CmdCp(neg int, args []string)
- func (ts *Script) CmdEnv(neg int, args []string)
- func (ts *Script) CmdEnvsub(neg int, args []string)
- func (ts *Script) CmdExec(neg int, args []string)
- func (ts *Script) CmdExists(neg int, args []string)
- func (ts *Script) CmdGrep(neg int, args []string)
- func (ts *Script) CmdHttp(neg int, args []string)
- func (ts *Script) CmdLog(neg int, args []string)
- func (ts *Script) CmdMkdir(neg int, args []string)
- func (ts *Script) CmdRegexp(neg int, args []string)
- func (ts *Script) CmdRm(neg int, args []string)
- func (ts *Script) CmdSed(neg int, args []string)
- func (ts *Script) CmdSkip(neg int, args []string)
- func (ts *Script) CmdStatus(neg int, args []string)
- func (ts *Script) CmdStderr(neg int, args []string)
- func (ts *Script) CmdStdin(neg int, args []string)
- func (ts *Script) CmdStdout(neg int, args []string)
- func (ts *Script) CmdStop(neg int, args []string)
- func (ts *Script) CmdSymlink(neg int, args []string)
- func (ts *Script) CmdUnquote(neg int, args []string)
- func (ts *Script) CmdWait(neg int, args []string)
- func (ts *Script) Defer(f func())
- func (ts *Script) Exec(command string, args ...string) error
- func (ts *Script) Fatalf(format string, args ...interface{})
- func (ts *Script) Getenv(key string) string
- func (ts *Script) Logf(format string, args ...interface{})
- func (ts *Script) MkAbs(file string) string
- func (ts *Script) ReadFile(file string) string
- func (ts *Script) Setenv(key, value string)
- func (ts *Script) Value(key interface{}) interface{}
- type T
- type TestingM
Constants ¶
const HTTP2_GOAWAY_CHECK = "http2: server sent GOAWAY and closed the connection"
Variables ¶
This section is empty.
Functions ¶
func IgnoreMissedCoverage ¶
func IgnoreMissedCoverage()
IgnoreMissedCoverage causes any missed coverage information (for example when a function passed to RunMain calls os.Exit, for example) to be ignored. This function should be called before calling RunMain.
func Run ¶
RunDir runs the tests in the given directory. All files in dir with a ".hls" are considered to be test files.
func RunMain ¶
RunMain should be called within a TestMain function to allow subcommands to be run in the testscript context.
The commands map holds the set of command names, each with an associated run function which should return the code to pass to os.Exit. It's OK for a command function to exit itself, but this may result in loss of coverage information.
When Run is called, these commands will be available as testscript commands; note that these commands behave like commands run with the "exec" command: they set stdout and stderr, and can be run in the background by passing "&" as a final argument.
This function returns an exit code to pass to os.Exit, after calling m.Run.
Types ¶
type Env ¶
type Env struct { // WorkDir holds the path to the root directory of the // extracted files. WorkDir string // Vars holds the initial set environment variables that will be passed to the // testscript commands. Vars []string // Cd holds the initial current working directory. Cd string // Values holds a map of arbitrary values for use by custom // testscript commands. This enables Setup to pass arbitrary // values (not just strings) through to custom commands. Values map[interface{}]interface{} // contains filtered or unexported fields }
Env holds the environment to use at the start of a test script invocation.
func (*Env) Defer ¶
func (e *Env) Defer(f func())
Defer arranges for f to be called at the end of the test. If Defer is called multiple times, the defers are executed in reverse order (similar to Go's defer statement)
func (*Env) Getenv ¶
Getenv retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.
func (*Env) Setenv ¶
Setenv sets the value of the environment variable named by the key. It panics if key is invalid.
func (*Env) T ¶
T returns the t argument passed to the current test by the T.Run method. Note that if the tests were started by calling Run, the returned value will implement testing.TB. Note that, despite that, the underlying value will not be of type *testing.T because *testing.T does not implement T.
If Cleanup is called on the returned value, the function will run after any functions passed to Env.Defer.
type Params ¶
type Params struct { // Mode is the top level operation mode for script // It can be "test" or "run" to control how scripts are isolated (or not) Mode string // Dir holds the name of the directory holding the scripts. // All files in the directory with a .hls suffix will be considered // as test scripts. By default the current directory is used. // Dir is interpreted relative to the current test directory. Dir string // Glob holds the patter to match, defaults to '*.hls' Glob string // Setup is called, if not nil, to complete any setup required // for a test. The WorkDir and Vars fields will have already // been initialized and all the files extracted into WorkDir, // and Cd will be the same as WorkDir. // The Setup function may modify Vars and Cd as it wishes. Setup func(*Env) error // Condition is called, if not nil, to determine whether a particular // condition is true. It's called only for conditions not in the // standard set, and may be nil. Condition func(cond string) (bool, error) // Cmds holds a map of commands available to the script. // It will only be consulted for commands not part of the standard set. Cmds map[string]func(ts *Script, neg int, args []string) // Funcs holds a map of functions available to the script. // These work like exec and use 'call' instead. // Use these to facilitate code coverage (exec does not capture this). Funcs map[string]func(ts *Script, args []string) error // TestWork specifies that working directories should be // left intact for later inspection. TestWork bool // WorkdirRoot specifies the directory within which scripts' work // directories will be created. Setting WorkdirRoot implies TestWork=true. // If empty, the work directories will be created inside // $GOTMPDIR/go-test-script*, where $GOTMPDIR defaults to os.TempDir(). WorkdirRoot string // IgnoreMissedCoverage specifies that if coverage information // is being generated (with the -test.coverprofile flag) and a subcommand // function passed to RunMain fails to generate coverage information // (for example because the function invoked os.Exit), then the // error will be ignored. IgnoreMissedCoverage bool // UpdateScripts specifies that if a `cmp` command fails and // its first argument is `stdout` or `stderr` and its second argument // refers to a file inside the testscript file, the command will succeed // and the testscript file will be updated to reflect the actual output. // // The content will be quoted with txtar.Quote if needed; // a manual change will be needed if it is not unquoted in the // script. UpdateScripts bool // Line prefix which indicates a new phase // defaults to "#" PhasePrefix string // Comment prefix for a line // defaults to "~" CommentPrefix string }
Params holds parameters for a call to Run.
type Script ¶
type Script struct { Logger *zap.SugaredLogger // contains filtered or unexported fields }
A Script holds execution state for a single test script.
func (*Script) BackgroundCmds ¶
BackgroundCmds returns a slice containing all the commands that have been started in the background since the most recent wait command, or the start of the script if wait has not been called.
func (*Script) CmdGrep ¶
regexp checks that file content matches a regexp. it accepts Go regexp syntax and returns the matches
func (*Script) CmdRegexp ¶
regexp checks that file content matches a regexp. it accepts Go regexp syntax.
func (*Script) CmdSed ¶
sed finds and replaces in text content it accepts Go regexp syntax and returns the replaced content
func (*Script) CmdSymlink ¶
symlink creates a symbolic link.
func (*Script) CmdUnquote ¶
unquote unquotes files.
func (*Script) CmdWait ¶
Tait waits for background commands to exit, setting stderr and stdout to their result.
func (*Script) Defer ¶
func (ts *Script) Defer(f func())
Defer arranges for f to be called at the end of the test. If Defer is called multiple times, the defers are executed in reverse order (similar to Go's defer statement)
func (*Script) Exec ¶
Exec runs the given command and saves its stdout and stderr so they can be inspected by subsequent script commands.
func (*Script) MkAbs ¶
MkAbs interprets file relative to the test script's current directory and returns the corresponding absolute path.
func (*Script) ReadFile ¶
ReadFile returns the contents of the file with the given name, interpreted relative to the test script's current directory. It interprets "stdout" and "stderr" to mean the standard output or standard error from the most recent exec or wait command respectively.
If the file cannot be read, the script fails.
type T ¶
type T interface { Skip(...interface{}) Fatal(...interface{}) Parallel() Log(...interface{}) FailNow() Run(string, func(T)) // Verbose is usually implemented by the testing package // directly rather than on the *testing.T type. Verbose() bool }
T holds all the methods of the *testing.T type that are used by testscript.
Source Files ¶
- cmd_call.go
- cmd_checks.go
- cmd_cmp.go
- cmd_env.go
- cmd_exec.go
- cmd_exit.go
- cmd_fs.go
- cmd_http.go
- cmd_log.go
- cmd_stdio.go
- cmd_str.go
- cmds.go
- env.go
- envvarname.go
- exe.go
- exe_next.go
- go-cover.go
- params.go
- runner.go
- script_args.go
- script_config.go
- script_files.go
- script_flags.go
- script_match.go
- script_parse.go
- script_run.go
- script_setup.go
- script_testing.go
- script_type.go