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 ¶
- RunSchemeCode: evaluate Scheme code, return result
- RunSchemeCodeWithTimeout: evaluate with timeout (prevents hangs)
- RunSchemeCodeWithContext: evaluate with custom context
- RunSchemeCodeExpectTrue: assert result is #t
- RunSchemeCodeExpectFalse: assert result is #f
- RunSchemeCodeExpectError: assert evaluation raises an error
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 ¶
- func EvalScheme(t *testing.T, code string) values.Value
- func EvalSchemeInEnv(t *testing.T, env *environment.EnvironmentFrame, code string) values.Value
- func EvalSchemeInEnvMayFail(t *testing.T, env *environment.EnvironmentFrame, code string) (result values.Value, err error)
- func NewFullRuntimeEnv(t *testing.T) *environment.EnvironmentFrame
- func NewMinimalNamespace(env *environment.EnvironmentFrame) *environment.EnvironmentFrame
- func NewTopLevelThunk(sv syntax.SyntaxValue, env *environment.EnvironmentFrame) (*machine.MachineContinuation, error)
- func ParseSchemeExpr(t *testing.T, env *environment.EnvironmentFrame, code string) syntax.SyntaxValue
- func RunProgramAST(t *testing.T, prog values.Value) (values.Value, error)
- func RunProgramASTWithEnv(t *testing.T, env *environment.EnvironmentFrame, prog values.Value) (values.Value, error)
- func RunSchemeCode(t *testing.T, code string) (values.Value, error)
- func RunSchemeCodeExpectError(t *testing.T, code string) (err error)
- func RunSchemeCodeExpectFalse(t *testing.T, code string)
- func RunSchemeCodeExpectTrue(t *testing.T, code string)
- func RunSchemeCodeWithContext(ctx context.Context, t *testing.T, code string) (values.Value, error)
- func RunSchemeCodeWithEnv(t *testing.T, env *environment.EnvironmentFrame, code string) (values.Value, error)
- func RunSchemeCodeWithEnvAndContext(ctx context.Context, t *testing.T, env *environment.EnvironmentFrame, ...) (values.Value, error)
- func RunSchemeCodeWithTimeout(t *testing.T, code string, timeout time.Duration) (values.Value, error)
- func SetupEngineTest(t *testing.T, fsys fs.FS) *environment.EnvironmentFrame
- func SetupLibraryTest(t *testing.T, testdataPath string) *environment.EnvironmentFrame
- type SchemeCodeErrorTestCase
- type SchemeCodeTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EvalScheme ¶ added in v1.10.7
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
func NewTopLevelThunk( sv syntax.SyntaxValue, env *environment.EnvironmentFrame, ) (*machine.MachineContinuation, error)
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
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 ¶
RunSchemeCode parses and runs Scheme source code string using a fresh environment with all core primitives and extensions loaded.
func RunSchemeCodeExpectError ¶
RunSchemeCodeExpectError runs code and expects an error (including panics).
func RunSchemeCodeExpectFalse ¶
RunSchemeCodeExpectFalse is a shorthand for boolean false result.
func RunSchemeCodeExpectTrue ¶
RunSchemeCodeExpectTrue is a shorthand for boolean true result.
func RunSchemeCodeWithContext ¶
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 ¶
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).