codegentest

package
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Golden

func Golden(t testing.TB, results []*Result, update bool)

Golden compares the results with golden files. Golden creates read a golden file which name is codegen.Generator.Name + ".golden". The golden file is stored in same directory of the package. If Golden cannot find a golden file or the result of Generator test is not same with the golden, Golden reports error via *testing.T. If update is true, golden files would be updated.

var flagUpdate bool

func TestMain(m *testing.M) {
	flag.BoolVar(&flagUpdate, "update", false, "update the golden files")
	flag.Parse()
	os.Exit(m.Run())
}

func TestGenerator(t *testing.T) {
	rs := codegentest.Run(t, codegentest.TestData(), example.Generator, "example")
	codegentest.Golden(t, rs, flagUpdate)
}

Types

type Result

type Result struct {
	Dir    string
	Pass   *codegen.Pass
	Err    error
	Output *bytes.Buffer
}

A Result holds the result of applying a generator to a package.

func Run

func Run(t testing.TB, testdata string, g *codegen.Generator, dirs ...string) []*Result

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL