testbuild

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package testbuild provides helper functions to test the build step in GX.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareString

func CompareString(got, want string) error

CompareString compares two string and build an error message if the strings do not match.

func Run

func Run(t *testing.T, tests ...Test)

Run all the test.

Types

type Builder

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

Builder builds test source code.

func (*Builder) Build

func (b *Builder) Build(src string) (builder.Package, error)

Build test source code.

type Decl

type Decl struct {
	// Src is the GX source code.
	Src string
	// Want is the set of nodes that is expected from the compiler to build.
	// If nil (or length 0), the output of the compiler is not checked.
	Want []ir.Node
	// Err is the substring expected if the compiler returns an error.
	Err string
}

Decl specifies a test with GX code declarations.

func (Decl) Run

func (tt Decl) Run(b *Builder) error

Run builds the declarations as a package, then compare to an expected outcome.

func (Decl) Source

func (tt Decl) Source() string

Source code of the declarations.

type DeclarePackage

type DeclarePackage struct {
	// Source code of the package.
	Src string
	// Function called (if not nil)  after the package has been built.
	// Can be use to provide the implementation of builtin functions.
	Post func(*ir.Package)
}

DeclarePackage declares a package for the following tests.

func (DeclarePackage) Run

func (tt DeclarePackage) Run(b *Builder) error

Run the source code to declare it as an importable package.

func (DeclarePackage) Source

func (tt DeclarePackage) Source() string

Source code of the package.

type Expr

type Expr struct {
	// Src is the source code of the expression.
	Src string
	// Want is the expression expected to be built by the compiler.
	Want ir.Expr
	// WantType is the string representation of the expression expected to be built by the compiler.
	WantType string
	// Err is the error expected by the compiler when the expression does not compile.
	Err string
}

Expr specifies a test of a GX expression.

func (Expr) Run

func (tt Expr) Run(ctx *Builder) error

Run the expression test.

func (Expr) Source

func (tt Expr) Source() string

Source code of the expression.

type Test

type Test interface {
	Source() string
	Run(*Builder) error
}

Test to run.

Jump to

Keyboard shortcuts

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