Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transform ¶
func Transform(ctx context.Context, pkg *ast.Package, modules TestModules) ([]string, []*ast.Package, error)
Transform will transform an *ast.Package into a set of *ast.Package values that represent each testcase defined within the original package.
A testcase is defined with the testcase statement such as below.
import "testing/assert" myVar = 4 testcase addition { assert.equal(want: 2 + 2, got: myVar) }
This gets transformed into a package that looks like this:
import "testing/assert" myVar = 4 assert.equal(want: 2 + 2, got: myVar)
It is allowed to include options within the testcase block as they will be extracted to the top level.
In addition to this syntax, testcase blocks may also extend another test file. This will transform the the extended testcase in a slightly different way. The syntax for extending is as such:
import "math" testcase addition_v2 extends "math_test" { option math.enable_v2 = true math_test.test_addition() }
This transforms the `math_test` file with the addition testcase into:
import "testing/assert" math_test = () => { myVar = 4 test_addition = () => { assert.equal(want: 2 + 2, got: myVar) return {} } return {myVar, test_addition} }()
The extended test file will be prepended to the list of files in the package as its own file.
If a testcase extends another testcase, it will be replaced with the given body.
test_invalid_import = () => { die(msg: "cannot extend an extended testcase") }
It is allowed for an imported testcase to have an option, but no attempt is made to remove duplicate options. If there is a duplicate option, this will likely cause an error when the test is actually run.
Types ¶
type TestModules ¶
type TestModules map[string]filesystem.Service
func (*TestModules) Add ¶
func (m *TestModules) Add(name string, fs filesystem.Service) error
func (*TestModules) Merge ¶
func (m *TestModules) Merge(other TestModules) error