scripttest

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package scripttest holds helpers shared by the library registration tests: evaluating a script with clear failure messages, and asserting that an import succeeds, or fails the way a script can catch. It is imported only from _test.go files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eval

Eval runs src on p and fails the test if it errors or panics.

func EvalInt

func EvalInt(t testing.TB, p *scriptling.Scriptling, src string) int64

EvalInt runs src and returns its result as an int.

func EvalString

func EvalString(t testing.TB, p *scriptling.Scriptling, src string) string

EvalString runs src and returns its result as a string.

func ImportFails

func ImportFails(t testing.TB, p *scriptling.Scriptling, name, hint string)

ImportFails asserts that `import name` on p fails with an import error, without panicking, and that a script can catch it as ImportError. hint tells the reader what registering the library would take, for the failure message.

func Imports

func Imports(t testing.TB, p *scriptling.Scriptling, name string)

Imports asserts that `import name` succeeds on p.

func Raises

func Raises(t testing.TB, p *scriptling.Scriptling, src string) (excType, msg string)

Raises runs src inside `try: ... except Exception as e:` on p and returns the caught exception's type name and message. It fails the test when src raises nothing, or the error escapes the handler (so a script could not catch it), or the interpreter panics.

func Refused

func Refused(t testing.TB, p *scriptling.Scriptling, src string) string

Refused asserts that src is stopped by a security policy: the script fails with a PermissionError even though src runs inside `try: ... except Exception:`. Policy refusals (path outside allowedPaths, and the like) are protected exceptions that a handler cannot swallow (see isProtected in the evaluator), so the error must reach the embedder. It returns the error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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