ubtest

package
v0.7.0-9a Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ubtest runs file-based tests for .ub source fixtures. A test points Run at a directory of .ub files and supplies a Driver that compiles one fixture through some pipeline stage (parse, validate, reference check, ...).

For each fixture <name>.ub, the diagnostics the driver produces are compared against a <name>.ub.err golden, and any textual output against a <name>.ub.out golden. A fixture with no .ub.err golden must compile cleanly. The -update flag rewrites the goldens from the driver's actual output.

ubtest depends only on the standard library and testify, so every package (including the lang front end it tests) can use it without an import cycle. The driver closure, which lives in the calling test, does the unobin-specific work: parsing the source and reducing an *lang.ErrorList to []string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, dir string, drive Driver, opts ...Option)

Run discovers every *.ub file under dir (recursively) and runs each through drive as a subtest named by its path relative to dir. Each fixture is run twice and the two results compared, catching nondeterministic drivers. With -update, the goldens are rewritten from actual output instead of asserted.

Types

type Driver

type Driver func(name string, src []byte) (output string, diags []string)

Driver compiles one fixture and reports the result for golden comparison. name is the fixture's path relative to the root, without the .ub extension (e.g. "invalid/unclosed-array"); src is the raw .ub bytes. output is compared against the <name>.ub.out golden; return "" when the stage produces no textual output. diags is the diagnostics the stage produced, in stable order; an empty slice means the input was accepted.

type Option

type Option func(*config)

Option configures Run.

func Idempotent

func Idempotent() Option

Idempotent re-runs the driver on its own output and checks the result is unchanged. Use it for formatters and renderers, where format(format(x)) must equal format(x).

func Substring

func Substring() Option

Substring matches each line of a .ub.err golden as a substring of the produced diagnostics, instead of requiring the whole diagnostics block to match exactly. Use it for the parser layer, whose raw messages are verbose and version-sensitive; prefer exact matching everywhere else.

Jump to

Keyboard shortcuts

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