Documentation ¶
Index ¶
- Constants
- func ObjectsMap(objects ...ast.Object) *orderedmap.Map[string, ast.Object]
- func TrimSpacesDiffComparator(t *testing.T, expectedContent []byte, gotContent []byte, filename string)
- type FileComparator
- type GoldenFilesTestSuite
- type Test
- func (t *Test[GoldenFileType]) OpenInput(inputFile string) io.Reader
- func (t *Test[GoldenFileType]) ReadInput(inputFile string) []byte
- func (t *Test[GoldenFileType]) UnmarshalJSONInput(filename string) GoldenFileType
- func (t *Test[GoldenFileType]) WriteFile(f *codejen.File)
- func (t *Test[GoldenFileType]) WriteFiles(files codejen.Files)
- func (t *Test[GoldenFileType]) WriteJSON(filename string, input any)
Constants ¶
const BuildersContextInputFile = "builders_context.json"
const GeneratorOutputFile = "ir.json"
const RawTypesIRInputFile = "ir.json"
Variables ¶
This section is empty.
Functions ¶
func ObjectsMap ¶
Types ¶
type FileComparator ¶
type GoldenFilesTestSuite ¶
type GoldenFilesTestSuite[GoldenFileType any] struct { // Run the test suite on this directory. TestDataRoot string // Name is a unique name for this test. The golden files for this test are // expected to live under `${TestDataRoot}/[test]/${Name}`. Name string // Skip is a map of tests to skip; the key is the test name; the value is the // skip message. Skip map[string]string // FileComparator is called to compare a golden file with its test-generated equivalent. // TrimSpacesDiffComparator is used if no comparator is provided. FileComparator FileComparator }
A GoldenFilesTestSuite represents a test run that processes inputs from a given directory and compares results against "golden files". See the Test documentation for more details.
type Test ¶
type Test[GoldenFileType any] struct { // Allow Test to be used as a T. *testing.T // RootDir is the path of the current test directory. RootDir string // OutputDir is the path where golden files live for this test. OutputDir string // contains filtered or unexported fields }
A Test represents a single test.
A Test embeds *testing.T and should be used to report errors.
When the test function has returned, output written with [Test.Write], [Test.Writer], Test.WriteFile and friends is checked against the expected output files.
If the output differs and $COG_UPDATE_GOLDEN is non-empty, the txtar file will be updated and written to disk with the actual output data replacing the out files.
func (*Test[GoldenFileType]) OpenInput ¶
OpenInput opens the specified input file and returns an io.Reader to it.
func (*Test[GoldenFileType]) UnmarshalJSONInput ¶
UnmarshalJSONInput reads and unmarshals the specified input file.
func (*Test[GoldenFileType]) WriteFile ¶
WriteFile writes a codejen.File to the main output.
func (*Test[GoldenFileType]) WriteFiles ¶
WriteFiles writes a list of codejen.File to the main output.