gocuelang.org/go/internal/cuetest Index | Files

package cuetest

import "cuelang.org/go/internal/cuetest"

Package testing is a helper package for test packages in the CUE project. As such it should only be imported in _test.go files.

Index

Constants

const RaceEnabled = false

Variables

var ForceUpdateGoldenFiles = os.Getenv(envUpdate) == "force"

ForceUpdateGoldenFiles determines whether tests should update expected output in test files even when they would not be updated usually (for example when there are test regressions).

var FormatTxtar = os.Getenv(envFormatTxtar) != ""

FormatTxtar ensures that .cue files in txtar test archives are well formatted, updating the archive as required prior to running a test. It is controlled by setting CUE_FORMAT_TXTAR to a non-empty string like "true".

var UpdateGoldenFiles = os.Getenv(envUpdate) != ""

UpdateGoldenFiles determines whether tests should update expected output in test files in the event of comparison failures (for example after a cmp failure in a testscript-based test). It is controlled by setting CUE_UPDATE to a non-empty string like "1" or "true". It corresponds to testscript.Params.UpdateGoldenFiles; see its docs for details.

In some cases, tests might refuse to perform some updates by default. The special value "force" can be used to force updates in that situation.

Functions

func Condition

func Condition(cond string) (bool, error)

Condition adds support for CUE-specific testscript conditions within testscript scripts. Supported conditions include:

golang.org/issue/N - evaluates to true unless CUE_NON_ISSUES is set to a regexp that matches the condition, i.e. golang.org/issue/N in this case

cuelang.org/issue/N - evaluates to true unless CUE_NON_ISSUES is set to a regexp that matches the condition, i.e. cuelang.org/issue/N in this case

func IssueSkip

func IssueSkip(t *testing.T, s string)

IssueSkip causes the test t to be skipped unless the issue identified by s is deemed to be a non-issue by CUE_NON_ISSUES.

func Run

func Run[TC any](t *testing.T, table []TC, fn func(t *T, tc *TC))

Run creates a new table-driven test using the CUE testing defaults.

TODO: move this wrapper out to cuetdtest. Users should either use the full version of tdtest directly, or use the cuetdtest wrapper.

Types

type Chunker

type Chunker struct {
	// contains filtered or unexported fields
}

A Chunker is used to find segments in text.

func NewChunker

func NewChunker(t *testing.T, b []byte) *Chunker

NewChunker returns a new chunker.

func (*Chunker) Bytes

func (c *Chunker) Bytes() []byte

Bytes returns the segment captured by the last call to Next or Find.

func (*Chunker) Find

func (c *Chunker) Find(key string) bool

Find searches for key from the current position and sets the current segment to the text from current position up till the key's position. If successful, the position is updated to point directly after the occurrence of key.

func (*Chunker) Next

func (c *Chunker) Next(beg, end string) bool

Next finds the first occurrence from the current scan position of beg, records the segment from that position until the first occurrence of end and then updates the current position. It reports whether a segment enclosed by beg and end can be found.

func (*Chunker) Text

func (c *Chunker) Text() string

Text returns the text segment captured by the last call to Next or Find.

type T

type T = tdtest.T

T is an alias to tdtest.T

Source Files

chunker.go cuetest.go norace.go

Version
v0.12.0 (latest)
Published
Jan 30, 2025
Platform
linux/amd64
Imports
6 packages
Last checked
8 hours ago

Tools for package owners.