testrunner

package
v0.1.0-dev.20260313033119 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 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).

Returns:

  • Option: a runner option that sets dry-run mode.

func WithGraphBuilder

func WithGraphBuilder() Option

WithGraphBuilder enables the plan.* graph namespace.

Returns:

  • Option: a runner option that enables the graph builder.

func WithProvider

func WithProvider(name string) Option

WithProvider restricts execution to a specific provider.

Parameters:

  • name: the provider name to restrict to.

Returns:

  • Option: a runner option that sets the provider filter.

func WithReceivers

func WithReceivers(names ...string) Option

WithReceivers sets the Starlark namespaces to expose as globals. If "plan" is included, it is extracted and handled via WithGraphBuilder.

Parameters:

  • names: the receiver names to expose.

Returns:

  • Option: a runner option that sets the receiver list.

func WithTrace

func WithTrace() Option

WithTrace enables Starlark step-by-step trace logging.

Returns:

  • Option: a runner option that enables tracing.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the output writer for executor messages.

Parameters:

  • w: the output writer.

Returns:

  • Option: a runner option that sets the writer.

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.

Parameters:

  • script: the path to the .star test script.
  • opts: functional options to configure the runner.

Returns:

  • *Runner: the configured test runner.

func (*Runner) Graph

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

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

Returns:

  • *op.Graph: the execution graph, or nil if Start has not been called.

func (*Runner) Start

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

Start executes the test script and returns structured results.

Parameters:

  • ctx: the execution context (used for cancellation).

Returns:

  • *Result: the test outcome with pass/fail status and failures.
  • error: non-nil if script loading or graph execution fails unexpectedly.

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. File checks are scoped through op.Root when available.

func NewTestContext

func NewTestContext(tmpDir string, root op.Root) *TestContext

NewTestContext creates a TestContext rooted at the given temp directory. When root is non-nil, file checks (checkFileExists, checkNoFile) are scoped through op.Root.

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