testutil

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const EnvRepoDirOverride = "ENCORE_REPO_DIR"

EnvRepoDirOverride is the name of the environment variable to override the resolution of the path to this repository. It exists because we have some tests that run in a temporary directory (such as when using testscript in process execution mode, like compiler/build/build_test.go), in which case the normal approach of invoking `git rev-parse --show-toplevel` doesn't work.

Variables

View Source
var (
	EncoreRepoDir = repoDir()
	RuntimeDir    = filepath.Join(EncoreRepoDir, "runtimes")
)
View Source
var ResourceDeepEquals = qt.CmpEquals(
	cmp.AllowUnexported(option.Option[*pkginfo.File]{}),
)

ResourceDeepEquals is a quicktest comparator for resource.Resource and resource.Bind that forces the comparison to include unexported fields

Functions

func FindNodes

func FindNodes[T ast.Node](root ast.Node) []T

FindNodes finds all nodes of the type T in the given AST.

func GetTestC

func GetTestC(ts *testscript.TestScript) *qt.C

GetTestC returns the *qt.C for the current testscript test.

This should only be called from within a testscript test which has had TestScriptSetupFunc called during the TestScript.Setup function.

func ParseTxtar

func ParseTxtar(s string) *txtar.Archive

func TestScriptSetupFunc

func TestScriptSetupFunc(env *testscript.Env) error

TestScriptSetupFunc is a testscript setup function which sets up the testscript environment for testing with testutil.

func UpdateArchiveFile

func UpdateArchiveFile(ts *testscript.TestScript, sourceDir string, filename string, content string)

func WriteTxtar

func WriteTxtar(c *qt.C, a *txtar.Archive) (dir string)

WriteTxtar writes the given txtar archive to a temporary directory and returns the directory path.

Types

type Context

type Context struct {
	*parsectx.Context
	TestC *qt.C
}

func NewContext

func NewContext(c *qt.C, parseTests bool, archive *txtar.Archive) *Context

NewContext constructs a new Context for testing. It defaults the build info to the host system.

func NewContextForTestScript

func NewContextForTestScript(ts *testscript.TestScript, parseTests bool) *Context

NewContextForTestScript constructs a new Context for testing when using testscript

Your testscript test should call this TestScriptSetupFunc in the TestScript.Setup function.

func (*Context) DeferExpectError

func (c *Context) DeferExpectError(matches ...string)

DeferExpectError is a defer function that expects errors to be present. Each argument is matched with the corresponding error. If the number of errors differs from the number of matches the test fails.

func (*Context) FailTestOnBailout

func (c *Context) FailTestOnBailout()

FailTestOnBailout is a defer function that fails the test if a bailout was triggered. It must be called as "defer c.FailTestOnBailout()".

func (*Context) FailTestOnErrors

func (c *Context) FailTestOnErrors()

FailTestOnErrors is function that fails the test if an errors are encountered when running fn.

func (*Context) GoModDownload

func (c *Context) GoModDownload()

GoModDownload runs "go mod download all" on the main module.

func (*Context) GoModTidy

func (c *Context) GoModTidy()

GoModTidy runs "go mod tidy" on the main module.

type PackageList

type PackageList []*pkginfo.Package

A PackageList is a list of packages that knows how to collect itself, by passing (*PackageList).Collector() to the scan.ProcessModule function. It's primarily a helper function for testing purposes.

func (*PackageList) Collector

func (l *PackageList) Collector() func(pkg *pkginfo.Package)

Jump to

Keyboard shortcuts

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