-
Notifications
You must be signed in to change notification settings - Fork 0
testframework
This document describes a self-contained runtime testing framework for Skript. The framework replicates much of Skript’s internal development test suite while extending it with runtime-safe execution, reflection-based inspection, and deterministic event-driven control.
Unlike Skript’s native internal tests, this framework:
- Runs entirely at runtime
- Is safe for production servers
- Supports both automatic (autorun) and manual execution
- Tracks failures centrally with optional console suppression
All framework state is stored under the -test.sk::* namespace.
The framework is intentionally minimal and predictable, prioritizing correctness and isolation over flexibility.
It is designed to:
- Allow tests to be written directly in
.skfiles - Achieve functional parity with Skript’s internal test actions where feasible
- Enable meta-testing of Skript syntax and parser behavior
- Support fail-fast behavior with optional non-halting assertions
- Prevent state leakage between tests
| Feature | Status | Description |
|---|---|---|
| Test structure | Achieved |
test %string% mirrors native test declarations |
| Conditional execution | Achieved |
when <condition> skips tests dynamically |
| Assertions | Achieved |
assert <condition> and assert <condition> to fail
|
| Explicit failure | Achieved |
fail test effect |
| Parser inspection | Experimental | Parse sections and log capture |
The framework is built around four core principles:
- Tests are custom events
- Tests are registered implicitly at parse time
- Execution is event-driven, not inline
- Failures are tracked centrally per test
Each test executes inside a dedicated skriptTest event context.
test "<test name>" [when <condition>]:
<test body>
- Tests are registered automatically when the script is parsed
- The optional
whencondition is evaluated immediately before execution
Inside a test, the framework provides:
-
event-string/event-testFully-qualified test identifier:<test name> -
event-booleanIndicates whether the test is running in autorun mode
Tests are registered automatically at parse time. No explicit registration step is required.
Internal storage format:
-test.sk::tests::<test name>
On script load:
- Previous global test state is cleared
- A hidden sentinel test establishes autorun context
- All registered tests are discovered
- Tests are executed in autorun mode
Autorun execution passes true as the event-boolean value.
run test(s) %strings%
- Accepts one or more fully-qualified test identifiers
- Clears prior error state for each test
- Executes tests outside autorun mode
Identifier format:
<test name>
all tests [with test name %-string%]
- No arguments → all tests from all scripts
-
with test name <string>→ exact match only
Returned values are fully-qualified test identifiers.
Assertions validate test behavior and record failures.
assert true: <condition>
assert false: <condition>
assert <condition> [to fail]
-
without haltingRecords failure but continues execution -
with error message "<message>"Prints formatted failure output -
with no error messageSuppresses console output entirely
Assertions are only valid inside a test context.
test errors [for %-strings%]
-
Returns all recorded failures for the current test
-
Includes:
- Assertion failures
- Explicit
fail testinvocations - Internally tracked errors
Errors are reset between tests and never leak across executions.
fail test
fail test with error message "<message>"
Behavior:
- Records a failure immediately
- Optionally prints formatted output
- Halts execution unless
without haltingis specified
Expression:
event-test is autorun
event-test is not autorun
Type: Boolean condition
Meaning:
- Evaluates to
truewhen the current test is executing as part of automatic test execution - Evaluates to
falsewhen the test is executed manually viarun test(s)
Scope:
- Valid only inside a
testblock - Bound to the
skriptTestevent context
Notes:
- This flag is set by the framework before test execution begins
- It remains constant for the duration of the test
- It is commonly used to guard unsafe, destructive, or environment-dependent logic
Syntax:
stop auto test execution here
Behavior:
-
If
event-test is autorun:- Immediately halts execution of the current test
-
If
event-test is not autorun:- Has no effect
Use Case: Allows tests to opt out of autorun safely while still being available for manual execution.
test "destructive test":
if event-test is autorun:
stop auto test execution here
# manual-only logic below
- Autorun mode is always enabled during load-time execution
- Manual execution always runs with autorun disabled
- The autorun flag is not mutable by user code
- Autorun state never leaks between tests
The framework supports testing Skript syntax itself.
parse:
<skript code>
- Attempts to parse the nested code using
ParserInstance - Does not execute the code
last parse logs
- Returns all
SkriptLoggermessages captured during the most recent parse - Enables validation of expected parser errors
To ensure isolation and repeatability, the framework provides controlled test fixtures:
-
test-world– dedicated test world -
test-location– fixed location (spawn + 10, 1, 0) -
test-block– self-resetting block restored after tests -
test-offline-player– generated offline player instance
Each test maintains its own failure count:
-test.sk::errors::<test id>
After execution completes:
- A summary line is printed:
<X>/<Y> tests passed
Where:
-
Y= executed tests -
X= tests without recorded failures
When enabled, failures are printed as:
[Skript] [TEST FAILURE] <test name> <optional message>
Output is suppressed entirely when with no error message is specified.
The framework guarantees that:
- Tests are isolated by themselves
- Registration is implicit and deterministic
- Autorun and manual execution are distinguishable
- Failures are recorded even in non-halting mode
- State never leaks between tests
The following are implementation details and must not be relied upon:
- Sentinel test usage
- Internal variable layout
- Reflection-based hooks
These may change without notice.
- Regression testing for Skript libraries
- Validation of complex event-driven logic
- Syntax and parser validation
- Automated sanity checks on server startup
- Lightweight CI-style verification
This framework is deliberately constrained to ensure reliability and transparency.