testcase

package
v0.194.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 9 Imported by: 1

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) ([]*ast.Identifier, []*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.addition" {
    option math.enable_v2 = true
    super()
}

The extending test case is then transformed into a single file combining both the parent statements and the current statements.

import "testing/assert"
import "math"

option math.enable_v2 = true

myVar = 4
assert.equal(want: 2 + 2, got: myVar)

The call to `super()` is replaced with the body of the parent test case.

It is an error to 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 TestModule added in v0.174.0

type TestModule struct {
	filesystem.Service
	// Tags is the set of valid tags tests in this module may contain
	Tags []string
}

TestModule represents a single fluxtest root

type TestModules

type TestModules map[string]TestModule

func (*TestModules) Add

func (m *TestModules) Add(name string, mod TestModule) error

func (*TestModules) Merge

func (m *TestModules) Merge(other TestModules) error

func (*TestModules) Open added in v0.174.0

func (m *TestModules) Open(fpath string) (string, filesystem.File, error)

Open returns a File for the testcase path

A test case path has the following format:

<module_name>/<filesystem_path>/<testfile_path>.<testcase_name>

where `filesystem_path` may contain multiple path elements.

func (*TestModules) Tags added in v0.174.0

func (m *TestModules) Tags(name string) []string

Jump to

Keyboard shortcuts

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