Back to godoc.org
github.com/tvastar/test

Package test

v0.0.0 (84aa581)
Latest Go to latest
Published: Sep 23, 2019 | License: MIT | Module: github.com/tvastar/test

Overview

Package test implements simple test utilities.

Index

Package Files

func Artifact

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

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

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

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

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier