Documentation
¶
Index ¶
Constants ¶
View Source
const ( TitleDelimiter = "### TITLE ###" DescriptionDelimiter = "### DESCRIPTION ###" SkipDelimiter = "### SKIP ###" InputDelimiter = "### INPUT ###" ArgsDelimiter = "### ARGS ###" RawArgsDelimiter = "### RAW_ARGS ###" StdoutDelimiter = "### STDOUT ###" StderrDelimiter = "### STDERR ###" ExitDelimiter = "### EXIT ###" )
Variables ¶
View Source
var UpdateSnapshots = flag.Bool("update", false, "update snapshot expected outputs")
UpdateSnapshots is set by the -update flag to regenerate expected outputs
Functions ¶
func CompareSnapshotResult ¶ added in v0.9.0
func CompareSnapshotResult(t *testing.T, tc *SnapshotCase, actual SnapshotResult) bool
CompareSnapshotResult compares actual output against expected. Returns true if the snapshot needs updating. In update mode, it does not fail the test on mismatch.
func WriteSnapshotFile ¶ added in v0.9.0
func WriteSnapshotFile(path string, cases []SnapshotCase) error
WriteSnapshotFile writes test cases back to a .snap file.
Types ¶
type ErrorOrExit ¶
type ErrorOrExit struct {
// contains filtered or unexported fields
}
type SnapshotCase ¶ added in v0.9.0
type SnapshotCase struct {
Title string
Description string // Optional documentation/comments about the test
Input string
Args []string // Command-line arguments to pass to the script
// Skip support - if SkipReason is non-empty, the test is skipped
SkipReason string
// RawArgs suppresses automatic flag additions (like --color=never).
// Use ### RAW_ARGS ### instead of ### ARGS ### to enable this.
RawArgs bool
Stdout string
Stderr string
ExitCode int
}
SnapshotCase holds one test case from a snapshot file.
func ParseSnapshotFile ¶ added in v0.9.0
func ParseSnapshotFile(path string) ([]SnapshotCase, error)
ParseSnapshotFile reads a .snap file and extracts test cases.
Format:
### TITLE ### <test name> ### DESCRIPTION ### <optional documentation, can be multi-line> ### SKIP ### <optional skip reason - if section present, test is skipped> ### INPUT ### <code to run> ### ARGS ### (or ### RAW_ARGS ### to suppress auto --color=never) <args, one per line> (optional) ### STDOUT ### <expected stdout> (optional, omit section for empty) ### STDERR ### <expected stderr> (optional, omit section for empty) ### EXIT ### <exit code> (optional, defaults to 0)
Multiple test cases can be included by repeating the pattern.
type SnapshotResult ¶ added in v0.9.0
SnapshotResult holds the actual output from running a test case.
type TestParams ¶
type TestParams struct {
// contains filtered or unexported fields
}
func NewTestParams ¶
func NewTestParams(script string, args ...string) *TestParams
func (*TestParams) StdinInput ¶
func (tp *TestParams) StdinInput(stdinInput string) *TestParams
Click to show internal directories.
Click to hide internal directories.