gotest

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package gotest owns GoScript package-test execution.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultParallelism added in v0.1.2

func DefaultParallelism() int

DefaultParallelism returns the default package subprocess concurrency.

Types

type Action

type Action string

Action names the package-level result action.

const (
	// ActionPass means the package tests passed.
	ActionPass Action = "pass"
	// ActionFail means the package tests failed.
	ActionFail Action = "fail"
	// ActionSkip means the package has no runnable tests.
	ActionSkip Action = "skip"
)

type Owner

type Owner string

Owner classifies the package owner that should receive a test-runner failure.

const (
	// OwnerPackageGraph classifies package pattern, build tag, or dependency graph failures.
	OwnerPackageGraph Owner = "PackageGraphOwner"
	// OwnerSemanticModel classifies Go type or semantic fact failures.
	OwnerSemanticModel Owner = "SemanticModelOwner"
	// OwnerLowering classifies unsupported Go-to-GoScript lowering failures.
	OwnerLowering Owner = "LoweringOwner"
	// OwnerTypeScriptEmitter classifies invalid emitted TypeScript failures.
	OwnerTypeScriptEmitter Owner = "TypeScriptEmitterOwner"
	// OwnerRuntimePackage classifies GoScript runtime primitive failures.
	OwnerRuntimePackage Owner = "RuntimePackageOwner"
	// OwnerOverridePackage classifies handwritten package override failures.
	OwnerOverridePackage Owner = "OverridePackageOwner"
	// OwnerTestRunner classifies generated testmain, execution, and aggregation failures.
	OwnerTestRunner Owner = "TestRunnerOwner"
	// OwnerSpacewaveHarness classifies target-ring or harness selection failures.
	OwnerSpacewaveHarness Owner = "SpacewaveHarnessOwner"
)

type PackagePhases

type PackagePhases struct {
	// Workspace covers workspace files and tool discovery.
	Workspace PhaseStatus
	// Compile covers GoScript compile/lowering work.
	Compile PhaseStatus
	// Emit covers TypeScript emit/copy output work.
	Emit PhaseStatus
	// TypeCheck covers tsgo execution.
	TypeCheck PhaseStatus
	// Runtime covers Bun test execution.
	Runtime PhaseStatus
}

PackagePhases records structured package-test phase status.

type PackageResult

type PackageResult struct {
	// PackagePath is the package under test.
	PackagePath string
	// SourceDir is the package source directory used as the runtime cwd.
	SourceDir string
	// TestPackagePath is the package variant that contains test functions.
	TestPackagePath string
	// TestImports are direct imports from selected test variants.
	TestImports []string
	// Tests are the selected tests for this package.
	Tests []Test
	// Action is the package result.
	Action Action
	// Phases records structured status for each runner phase.
	Phases PackagePhases
	// Owner is the primary owner classification for failures.
	Owner Owner
	// Error is the concise package failure message.
	Error string
	// Output is raw process output for the package.
	Output string
	// Elapsed is the package runtime.
	Elapsed time.Duration
}

PackageResult describes one package-test result.

type PhaseStatus

type PhaseStatus string

PhaseStatus names a package-test phase state.

const (
	// PhaseStatusPending means the phase has not run yet.
	PhaseStatusPending PhaseStatus = "pending"
	// PhaseStatusPass means the phase passed.
	PhaseStatusPass PhaseStatus = "pass"
	// PhaseStatusFail means the phase failed.
	PhaseStatusFail PhaseStatus = "fail"
	// PhaseStatusSkip means the phase was skipped.
	PhaseStatusSkip PhaseStatus = "skip"
)

type Request

type Request struct {
	// Dir is the working directory for package loading.
	Dir string
	// Patterns are Go package patterns to test.
	Patterns []string
	// BuildTags are normalized into a Go -tags build flag.
	BuildTags []string
	// OverrideDirs are additional GoScript override roots.
	OverrideDirs []string
	// Run is the optional Go test name regexp.
	Run string
	// Count is the number of times to run matched tests.
	Count int
	// Short reports true from testing.Short in generated tests.
	Short bool
	// Timeout bounds compile, typecheck, and execution.
	Timeout time.Duration
	// Verbose emits test-level output.
	Verbose bool
	// PanicOnExit0 makes os.Exit(0) fail like go test's -test.paniconexit0.
	PanicOnExit0 bool
	// WorkDir stores generated runner files and logs.
	WorkDir string
	// OutputRoot stores generated TypeScript packages.
	OutputRoot string
	// Parallelism limits concurrent package typecheck/runtime subprocesses.
	Parallelism int
	// RuntimeBackend selects the JavaScript host used for package runtime tests.
	RuntimeBackend RuntimeBackend
	// RuntimeGroups allows package runtimes to share worker Bun processes.
	RuntimeGroups bool
	// IncrementalTypeCheck reuses TypeScript build-info files inside WorkDir.
	IncrementalTypeCheck bool
}

Request describes one GoScript package-test run.

type Result

type Result struct {
	// WorkDir is the generated test workspace.
	WorkDir string
	// OutputRoot is the generated TypeScript package root.
	OutputRoot string
	// Packages are deterministic package-level test results.
	Packages []PackageResult
	// Diagnostics are compiler diagnostics surfaced during the run.
	Diagnostics []compiler.Diagnostic
}

Result describes one GoScript package-test run.

func (*Result) Passed

func (r *Result) Passed() bool

Passed returns true when every package result passed or had no tests.

type Runner

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

Runner owns GoScript package-test loading, compilation, typecheck, and execution.

func NewRunner

func NewRunner() *Runner

NewRunner creates a package-test runner.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, req *Request) (*Result, error)

Run executes package tests through the GoScript compiler and TypeScript runtime.

type RuntimeBackend added in v0.2.0

type RuntimeBackend string

RuntimeBackend selects the JavaScript host used for package runtime tests.

const (
	// RuntimeBackendBun runs generated package-test modules directly in Bun.
	RuntimeBackendBun RuntimeBackend = "bun"
	// RuntimeBackendBrowser runs generated package-test modules in Chromium.
	RuntimeBackendBrowser RuntimeBackend = "browser"
)

type Test

type Test struct {
	// Name is the Go TestXxx function name.
	Name string
	// PackagePath is the package variant that exports the function.
	PackagePath string
}

Test describes one discovered Go test function.

Jump to

Keyboard shortcuts

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