testing

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: Apache-2.0 Imports: 39 Imported by: 1

Documentation

Overview

Package testing provides functions to run gx tests.

Index

Constants

View Source
const WantPrefix = "Want:"

WantPrefix is the prefix in the comment indicating the result of a test.

Variables

This section is empty.

Functions

func BuildCompileOptions

func BuildCompileOptions(rtm *api.Runtime, pkg *ir.Package) ([]options.PackageOption, error)

BuildCompileOptions from the source code of the package.

func CheckSource

func CheckSource(errs *fmterr.Errors, node ir.Node)

CheckSource checks that Source and File return non-nil values.

func CompareToExpectedErrors

func CompareToExpectedErrors(pkg *ir.Package, err error) (bool, error)

CompareToExpectedErrors removes errors declared in the source code using: ERROR <sub string to search in the error message> from a set of errors and returns the remaining errors if any.

First, all expected errors are collected from the comments. Second, these errors are compared to the errors generated by the compiler. If some errors have been generated by the compiler and are not expected, an error is returned. If some errors are expected in the comments and have not been generated by the compiler, an error is returned.

func FetchArray

func FetchArray[T dtype.GoDataType](t *testing.T, array types.Array[T]) []T

FetchArray fetches an array from a device.

func FetchAtom

func FetchAtom[T dtype.GoDataType](t *testing.T, atom types.Atom[T]) T

FetchAtom fetches an atomic value from a device.

func FindTests

func FindTests(pkg *ir.Package) ([]*ir.FuncDecl, error)

FindTests finds all the tests at the top-level of a filesystem.

func NewBuilderStaticSource

func NewBuilderStaticSource(stdlibImpl *impl.Stdlib) *builder.Builder

NewBuilderStaticSource returns a builder using the embedpkg importer which embeds GX testing source files into their corresponding Go package.

func NumberLines

func NumberLines(s string) string

NumberLines returns a string where lines are prefixed by their number.

func RunAll

func RunAll(t *testing.T, rtm *api.Runtime, pkg *ir.Package, err error) (numTests int)

RunAll compiles and runs all the test at a specified path. Returns the number of tests that have been run.

func Validate

func Validate(node ir.Node, visitors ...Visitor) error

Validate an intermediate representation tree to make sure all fields are set.

Types

type Runner

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

Runner runs test functions.

func NewRunner

func NewRunner(rtm *api.Runtime, devID int) (*Runner, error)

NewRunner returns a test runner given a device.

func (*Runner) Run

func (r *Runner) Run(fn *ir.FuncDecl, options []options.PackageOption) ([]values.Value, string, error)

Run compiles a function into a XLA graph, runs it, and returns the result.

func (*Runner) RunWithArgs

func (r *Runner) RunWithArgs(fn *ir.FuncDecl, recv values.Value, args []values.Value, options []options.PackageOption) ([]values.Value, string, error)

RunWithArgs compiles a function into a XLA graph, runs it, and returns the result.

type Session

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

Session is a test session to a set of tests given a filesystem, a builder, and a backend.

func NewSession

func NewSession(rtm *api.Runtime, fs fs.ReadDirFS) *Session

NewSession returns a new testing session given a runtime.

func (*Session) TestFolder

func (s *Session) TestFolder(t *testing.T, path string)

TestFolder run the tests in a folder.

type UnitSession

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

UnitSession is a test session that reads files from a file system and, for each file:

  1. Create a new builder.
  2. Read and compile the file as its own package. The package name needs to match the file name.
  3. Run the tests present in the file.

This is different to a Session where all packages will be built using the same builder.

func NewUnitSession

func NewUnitSession(rtmF func() (*api.Runtime, error), fs fs.ReadDirFS) *UnitSession

NewUnitSession returns a new testing session given a runtime.

func (*UnitSession) TestFolder

func (s *UnitSession) TestFolder(t *testing.T, path string)

TestFolder run the tests in a folder.

type Visitor

type Visitor func(errs *fmterr.Errors, node ir.Node)

Visitor checks node in the intermediate representation.

Directories

Path Synopsis
Package prime generates prime numbers.
Package prime generates prime numbers.

Jump to

Keyboard shortcuts

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