go.starlark.net: go.starlark.net/starlarktest Index | Files

package starlarktest

import "go.starlark.net/starlarktest"

Package starlarktest defines utilities for testing Starlark programs.

Clients can call LoadAssertModule to load a module that defines several functions useful for testing. See assert.star for its definition.

The assert.error function, which reports errors to the current Go testing.T, requires that clients call SetTest(thread, t) before use.

Index

Package Files

starlarktest.go

Variables

var DataFile = func(pkgdir, filename string) string {

    testSrcdir := os.Getenv("TEST_SRCDIR")
    testWorkspace := os.Getenv("TEST_WORKSPACE")
    if testSrcdir != "" && testWorkspace != "" {
        return filepath.Join(testSrcdir, "net_starlark_go", pkgdir, filename)
    }

    return filepath.Join(build.Default.GOPATH, "src/go.starlark.net", pkgdir, filename)
}

DataFile returns the effective filename of the specified test data resource. The function abstracts differences between 'go build', under which a test runs in its package directory, and Blaze, under which a test runs in the root of the tree.

func LoadAssertModule Uses

func LoadAssertModule() (starlark.StringDict, error)

LoadAssertModule loads the assert module. It is concurrency-safe and idempotent.

func SetReporter Uses

func SetReporter(thread *starlark.Thread, r Reporter)

SetReporter associates an error reporter (such as a testing.T in a Go test) with the Starlark thread so that Starlark programs may report errors to it.

type Reporter Uses

type Reporter interface {
    Error(args ...interface{})
}

A Reporter is a value to which errors may be reported. It is satisfied by *testing.T.

func GetReporter Uses

func GetReporter(thread *starlark.Thread) Reporter

GetReporter returns the Starlark thread's error reporter. It must be preceded by a call to SetReporter.

Package starlarktest imports 9 packages (graph) and is imported by 1 packages. Updated 2020-02-01. Refresh now. Tools for package owners.