Documentation
¶
Overview ¶
Package test implements simple test utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Artifact ¶
Artifact implements comparing an artifact against a golden file.
The goldenFile is expected to be relative to the testdata/ folder of the caller of this API. The storage format is JSON for readability of the output.
If the tests are run with -golden flag, the output is not compared but instead the output files are generated.
Example Usage:
test.File(t.Fatal, "golden_xyz.json", func() interface{} { ... do some tests and return any serializable type... })
func File ¶
File implements testing against input/output files
The input and output file names are relative to the testdata/ folder of the caller.
The provided function is one of these two forms:
func (input someType) (output someOtherType) func (input someType) (output someOtherType, err error)
The input file is read and the contents passed through this function. For input arguments of type string, []byte or []rune the contents of the files are passed as is. For other types, the contents are assumed to be JSON encoded. The output is similarly JSON encoded for such types.
The discrepancies are reported using regular diff format via the error function (which sports the same signature as testing.T.Error or testing.T.Fatal)
If the tests are run with -golden flag, the output is not compared but instead the output files are created to match the output provided by the test.
Example Usage:
test.File(t.Fatal, "input.txt", "output.txt", func(input string) string { .... }, )
func Markdown ¶
Markdown generates test code by compiling together snippets in the provided markdown file names. The output is written to the provided output file name.
Fenced blocks can also specify the test/example name in the info string. The first word of the infostring must be go or golang
A fenced block can "import" other modules by simply placing a comment of the form `// import path`.
See https://github.com/tvastar/test/blob/master/testdata/markdown.md for a sample markdown and https://github.com/tvastar/test/blob/master/testdata/markdown_test.go for example generated tests.
Types ¶
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
testmd
Command testmd generates test files out of markdown snippets $ go get github.com/tvastar/test/cmd/testmd This is useful when writing tutorials in markdown and making sure all the tutorials remain valid as the code underneath changes If no output file is specified (via -o), a temporary go file is generated and it is immediately run via `go test`.
|
Command testmd generates test files out of markdown snippets $ go get github.com/tvastar/test/cmd/testmd This is useful when writing tutorials in markdown and making sure all the tutorials remain valid as the code underneath changes If no output file is specified (via -o), a temporary go file is generated and it is immediately run via `go test`. |