testrunner

package
v0.1.0-dev.20260308222923 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Expectation

type Expectation struct {
	Kind    string         // "file_exists", "no_file", "node_count", "error", "equal"
	Path    string         // for file expectations
	Content string         // optional expected content
	Count   int            // for node_count
	Pattern string         // for error expectations
	Got     starlark.Value // for equal expectations
	Want    starlark.Value // for equal expectations
}

Expectation represents a single test assertion queued during script execution.

type Failure

type Failure struct {
	Expectation string `json:"expectation"`
	Message     string `json:"message"`
}

Failure records a failed expectation.

type Option

type Option func(*Runner)

Option configures a Runner.

func WithDryRun

func WithDryRun() Option

WithDryRun enables dry-run mode (plan only, no side effects).

func WithProvider

func WithProvider(name string) Option

WithProvider restricts execution to a specific provider.

func WithReceivers

func WithReceivers(names ...string) Option

WithReceivers sets the Starlark namespaces to expose as globals.

func WithTrace

func WithTrace() Option

WithTrace enables Starlark step-by-step trace logging.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the output writer for executor messages.

type Result

type Result struct {
	Passed           bool      `json:"passed"`
	NodeCount        int       `json:"node_count"`
	ExpectationCount int       `json:"expectation_count"`
	Failures         []Failure `json:"failures"`
	Trace            []string  `json:"trace,omitempty"`
}

Result is the structured output of a test run.

type Runner

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

Runner orchestrates a single test script execution.

func New

func New(script string, opts ...Option) *Runner

New creates a Runner for the given script path.

func (*Runner) Graph

func (r *Runner) Graph() *op.Graph

Graph returns the execution graph after Start completes. Returns nil before Start is called.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context) (*Result, error)

Start executes the test script and returns structured results.

type TestContext

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

TestContext is the `t` namespace injected into Starlark test scripts. It provides a temp directory and queues expectations that are checked after graph execution completes.

func NewTestContext

func NewTestContext(tmpDir string) *TestContext

NewTestContext creates a TestContext rooted at the given temp directory.

func (*TestContext) Check

func (tc *TestContext) Check(graph *op.Graph, execErr error) []Failure

Check evaluates all queued expectations against the executed graph and filesystem. Returns failures for any expectations that did not hold.

func (*TestContext) Expectations

func (tc *TestContext) Expectations() []Expectation

Expectations returns the queued expectations.

func (*TestContext) StarlarkValue

func (tc *TestContext) StarlarkValue() starlark.Value

StarlarkValue returns the `t` namespace as a Starlark struct.

func (*TestContext) TmpDir

func (tc *TestContext) TmpDir() string

TmpDir returns the temp directory path.

type Tracer

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

Tracer collects trace entries during Starlark script execution. When enabled, it records position and expression info via the thread's Print handler and captures plan.* invocations.

func NewTracer

func NewTracer(enabled bool) *Tracer

NewTracer creates a Tracer. If enabled is false, all operations are no-ops.

func (*Tracer) Enabled

func (tr *Tracer) Enabled() bool

Enabled returns whether tracing is active.

func (*Tracer) Entries

func (tr *Tracer) Entries() []string

Entries returns a copy of all recorded trace entries.

func (*Tracer) PrintHandler

func (tr *Tracer) PrintHandler() func(*starlark.Thread, string)

PrintHandler returns a starlark.Thread.Print function that captures print() output as trace entries and logs them.

func (*Tracer) Record

func (tr *Tracer) Record(format string, args ...any)

Record adds a trace entry.

func (*Tracer) RecordThread

func (tr *Tracer) RecordThread(thread *starlark.Thread, msg string)

RecordThread logs the current thread position.

Jump to

Keyboard shortcuts

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