testcase

package
v0.170.1-fips1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 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) ([]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.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 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

Jump to

Keyboard shortcuts

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