testhelpers

package
v1.13.21 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testhelpers provides shared test infrastructure for Scheme primitive tests.

Each helper creates a fresh environment.EnvironmentFrame via bootstrap, ensuring test isolation:

result, err := testhelpers.RunSchemeCode(t, "(+ 1 2)")
c.Assert(err, qt.IsNil)
c.Assert(result, valuestest.SchemeEquals, values.NewInteger(3))

Helpers

Test Case Structs

SchemeCodeTestCase and SchemeCodeErrorTestCase enable consistent table-driven test patterns across primitive test files.

Package testhelpers provides shared test infrastructure for Scheme primitive tests.

All functions use the internal pipeline (parser → expander → compiler → VM) with a full environment including all extensions. This matches the environment available in the standalone scheme binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvalScheme added in v1.10.7

func EvalScheme(t *testing.T, code string) values.Value

EvalScheme evaluates one or more Scheme expressions and returns the last value. Fails the test on any error.

func EvalSchemeInEnv added in v1.10.7

func EvalSchemeInEnv(t *testing.T, env *environment.EnvironmentFrame, code string) values.Value

EvalSchemeInEnv evaluates one or more Scheme expressions in the given environment and returns the last value. Calls t.Fatal on any error.

func EvalSchemeInEnvMayFail added in v1.10.7

func EvalSchemeInEnvMayFail(t *testing.T, env *environment.EnvironmentFrame, code string) (result values.Value, err error)

EvalSchemeInEnvMayFail evaluates Scheme expressions in the given environment, returning the last value and any error. VM panics are recovered and returned as errors.

func NewFullRuntimeEnv added in v1.10.7

func NewFullRuntimeEnv(t *testing.T) *environment.EnvironmentFrame

NewFullRuntimeEnv creates a full runtime environment with all primitives and bootstrap macros registered.

func NewMinimalNamespace added in v1.10.7

func NewMinimalNamespace(env *environment.EnvironmentFrame) *environment.EnvironmentFrame

NewMinimalNamespace creates a minimal namespace with core special form bindings registered (if, lambda, quote, etc.). Useful for unit tests that need compilation without a full bootstrap.

func NewTopLevelThunk added in v1.10.7

NewTopLevelThunk expands, compiles, and wraps a syntax value into a continuation ready for MachineContext.Run().

func ParseSchemeExpr added in v1.10.7

func ParseSchemeExpr(t *testing.T, env *environment.EnvironmentFrame, code string) syntax.SyntaxValue

ParseSchemeExpr parses a single Scheme expression from code.

func RunProgramAST added in v1.5.0

func RunProgramAST(t *testing.T, prog values.Value) (values.Value, error)

RunProgramAST compiles and runs a Scheme program from a pre-built values.Value AST. Uses a minimal top-level environment (bootstrap.NewNamespaceFrameTiny).

func RunProgramASTWithEnv added in v1.5.0

func RunProgramASTWithEnv(t *testing.T, env *environment.EnvironmentFrame, prog values.Value) (values.Value, error)

RunProgramASTWithEnv compiles and runs a Scheme program AST with the given environment.

func RunSchemeCode

func RunSchemeCode(t *testing.T, code string) (values.Value, error)

RunSchemeCode parses and runs Scheme source code string using a fresh environment with all core primitives and extensions loaded.

func RunSchemeCodeExpectError

func RunSchemeCodeExpectError(t *testing.T, code string) (err error)

RunSchemeCodeExpectError runs code and expects an error (including panics).

func RunSchemeCodeExpectFalse

func RunSchemeCodeExpectFalse(t *testing.T, code string)

RunSchemeCodeExpectFalse is a shorthand for boolean false result.

func RunSchemeCodeExpectTrue

func RunSchemeCodeExpectTrue(t *testing.T, code string)

RunSchemeCodeExpectTrue is a shorthand for boolean true result.

func RunSchemeCodeWithContext

func RunSchemeCodeWithContext(ctx context.Context, t *testing.T, code string) (values.Value, error)

RunSchemeCodeWithContext parses and runs Scheme source code with the given context. The context enables cancellation/timeout - the VM loop checks ctx.Done() on each iteration.

func RunSchemeCodeWithEnv added in v1.5.0

func RunSchemeCodeWithEnv(t *testing.T, env *environment.EnvironmentFrame, code string) (values.Value, error)

RunSchemeCodeWithEnv parses, expands, compiles, and runs Scheme source code with the given environment. Useful for tests that need custom bindings.

func RunSchemeCodeWithEnvAndContext added in v1.5.0

func RunSchemeCodeWithEnvAndContext(ctx context.Context, t *testing.T, env *environment.EnvironmentFrame, code string) (values.Value, error)

RunSchemeCodeWithEnvAndContext parses, expands, compiles, and runs Scheme source code with the given context and environment.

func RunSchemeCodeWithTimeout

func RunSchemeCodeWithTimeout(t *testing.T, code string, timeout time.Duration) (values.Value, error)

RunSchemeCodeWithTimeout runs code with a timeout to prevent infinite loops. Uses context.WithTimeout for proper cooperative cancellation - the VM loop checks ctx.Done() on each iteration and exits cleanly when cancelled.

func SetupEngineTest added in v1.10.7

func SetupEngineTest(t *testing.T, fsys fs.FS) *environment.EnvironmentFrame

SetupEngineTest creates a test environment with full library loading support, mirroring what wile.NewEngine(WithSourceFS(...)) does internally. The fsys parameter provides the virtual filesystem for library resolution (use testing/fstest.MapFS for inline .sld content). Pass nil to skip FS setup.

This avoids importing the root wile package (which would create a circular dependency) while providing the same library infrastructure.

func SetupLibraryTest added in v1.10.7

func SetupLibraryTest(t *testing.T, testdataPath string) *environment.EnvironmentFrame

SetupLibraryTest creates a test environment with library loading capability, using the testdata/ directory at the given path as the library search path.

Types

type SchemeCodeErrorTestCase

type SchemeCodeErrorTestCase struct {
	Name string
	Code string
}

SchemeCodeErrorTestCase is the common struct for table-driven tests that run Scheme code and expect an error (or just verify execution without checking the result).

type SchemeCodeTestCase

type SchemeCodeTestCase struct {
	Name     string
	Code     string
	Expected values.Value
}

SchemeCodeTestCase is the common struct for table-driven tests that run Scheme code and compare against an expected value.

Jump to

Keyboard shortcuts

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