test: github.com/tvastar/test Index | Files | Directories

package test

import "github.com/tvastar/test"

Package test implements simple test utilities.

Index

Package Files

artifact.go file.go markdown.go

func Artifact Uses

func Artifact(errorf Errorf, outputFile string, value interface{})

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 Uses

func File(errorf Errorf, inputFile string, outputFile string, fn interface{})

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 Uses

func Markdown(src []string, dest, pkg string) (err error)

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.

type Errorf Uses

type Errorf func(args ...interface{})

Errorf is the type of the function used for reporting errors.

This is typically testing.T.Error or testing.T.Fatal

Directories

PathSynopsis
cmd/testmdCommand testmd generates test files out of markdown snippets

Package test imports 16 packages (graph) and is imported by 1 packages. Updated 2019-09-29. Refresh now. Tools for package owners.