(sigil test)
(sigil test) - Test Framework for Sigil
Provides a simple but powerful test framework with support for test groups, assertions, and structured results for CLI integration.
Usage: (import (sigil test))
(test-group "Arithmetic" (test "addition" (assert-equal 3 (+ 1 2))) (test "multiplication" (assert-equal 12 (* 3 4))))
(run-tests)
Exports
test-descriptorprocedureA test descriptor holds metadata about a registered test
test-descriptor?procedureTest if a value is a test-descriptor struct.
test-descriptor-nameprocedureGet the name field of a test-descriptor struct.
test-descriptor-groupprocedureGet the group field of a test-descriptor struct.
test-descriptor-thunkprocedureGet the thunk field of a test-descriptor struct.
test-descriptor-fileprocedureGet the file field of a test-descriptor struct.
test-descriptor-lineprocedureGet the line field of a test-descriptor struct.
%test-result--typevariableGet the line field of a test-descriptor struct.
test-resultprocedureA test result holds the outcome of running a test
test-result?procedureTest if a value is a test-result struct.
test-result-nameprocedureGet the name field of a test-result struct.
test-result-groupprocedureGet the group field of a test-result struct.
test-result-passed?procedureGet the passed? field of a test-result struct.
test-result-messageprocedureGet the message field of a test-result struct.
test-result-expectedprocedureGet the expected field of a test-result struct.
test-result-actualprocedureGet the actual field of a test-result struct.
test-result-duration-msprocedureGet the duration-ms field of a test-result struct.
test-result-fileprocedureGet the file field of a test-result struct.
test-result-lineprocedureGet the line field of a test-result struct.
%test-summary--typevariableGet the line field of a test-result struct.
test-summaryprocedureConstruct a test-summary struct.
test-summary?procedureTest if a value is a test-summary struct.
test-summary-totalprocedureGet the total field of a test-summary struct.
test-summary-passedprocedureGet the passed field of a test-summary struct.
test-summary-failedprocedureGet the failed field of a test-summary struct.
test-summary-skippedprocedureGet the skipped field of a test-summary struct.
test-summary-duration-msprocedureGet the duration-ms field of a test-summary struct.
test-summary-resultsprocedureGet the results field of a test-summary struct.
*tests*variableGlobal list of registered tests
*current-group*variableCurrent test group (set by test-group)
*current-file*variableCurrent source file (set before loading test file)
*runner-mode*variableRunner mode flag - when #t, run-tests-exit doesn't print or exit This allows the CLI runner to handle output formatting
set-default-group!procedureSet the default group for tests (used by runner for filename-based grouping)
current-groupprocedureGet the current test group name.
push-group!procedurePush a new group onto the group stack.
Returns the previous group for later restoration with pop-group!. Used internally by test-group.
pop-group!procedurePop back to a previous group.
Restores the group saved by push-group!.
get-testsprocedureGet all registered tests as a list of test descriptors.
clear-tests!procedureClear all registered tests.
Resets the test registry and current group. Useful when running multiple test files in sequence.
*fail-message*variableCurrent assertion failure info
fail-assertionprocedureSignal assertion failure
reset-assertion-state!procedureReset assertion state
assert-equalprocedureAssert two values are equal using deep equality.
Uses equal? for comparison, which recursively compares lists, vectors, and strings by content.
(assert-equal 3 (+ 1 2)) ; passes
(assert-equal '(1 2) '(1 2)) ; passes (deep equality)
(assert-equal "hello" "hello") ; passes
(assert-equal 5 6) ; fails: expected 5 but got 6assert-eqvprocedureAssert two values are equivalent using eqv?.
Uses eqv? which compares numbers by value and characters, but not lists or strings by content.
(assert-eqv 42 42) ; passes
(assert-eqv #\a #\a) ; passes
(assert-eqv 3.14 3.14) ; passesassert-eqprocedureAssert two values are the same object using eq?.
Uses eq? which tests object identity. Useful for symbols and checking if two variables reference the same object.
(assert-eq 'foo 'foo) ; passes (symbols are interned)
(let ((x '(1 2)))
(assert-eq x x)) ; passes (same object)
(assert-eq '(1) '(1)) ; fails (different list objects)assert-trueprocedureAssert a value is truthy (not #f).
Any value except #f is considered truthy in Scheme.
(assert-true #t) ; passes
(assert-true 42) ; passes (non-#f is truthy)
(assert-true '()) ; passes (empty list is truthy)
(assert-true #f) ; failsassert-falseprocedureAssert a value is #f.
(assert-false #f) ; passes
(assert-false (member 'x '())) ; passes (member returns #f)
(assert-false #t) ; failsassert-nullprocedureAssert a value is the empty list ().
(assert-null '()) ; passes
(assert-null (cdr '(1))) ; passes
(assert-null '(1 2)) ; failsassert-not-nullprocedureAssert a value is not the empty list.
(assert-not-null '(1 2 3)) ; passes
(assert-not-null "hello") ; passes
(assert-not-null '()) ; failsassert-failprocedureFail unconditionally with a message.
Use this to mark code paths that should not be reached.
(test "unreachable"
(if (some-condition)
(assert-equal ...)
(assert-fail "should not reach here")))trapped-exit-prefixvariableAssert that an expression raises an error.
The test passes if the expression raises any error, and fails if it completes normally.
(assert-error (error "boom")) ; passes
(assert-error (car '())) ; passes (error on empty list)
(assert-error (+ 1 2)) ; fails (no error raised)A TRAPPED EXIT IS NOT AN ERROR, AND MUST NOT SATISFY THIS ASSERTION.
The runtime's exit trap (%set-exit-trap!) turns an exit under the test runner into an ordinary VM error, so one test file can no longer terminate the whole suite. That is a large improvement and it creates one new hazard, here: before the trap existed, (assert-error <something-that-exits>) KILLED the run — loud, and impossible to miss. Afterwards the trap converts it to an error and this guard accepts it, so the assertion turns GREEN.
A green assertion that is green because the code under test tried to terminate the process is exactly the class of lie the exit trap was built to remove; introducing a fresh instance of it while removing the old ones would be a poor trade. So this is a defect, not a footnote, and it is caught rather than documented.
The message prefix below is a CONTRACT with native_exit in packages/sigil-lib/src/process.c, which is the only producer of this text. It is asserted from both ends: change one and packages/sigil-test-runner/test/test-exit-trap.sgl goes red. Spelled with core string operations rather than string-starts-with? so this library does not have to grow a (sigil string) import.
run-single-testprocedureRun a single test and return its result.
Takes a test descriptor and returns a test-result struct with pass/fail status and any failure details.
run-testsprocedureRun all registered tests and report results.
In standalone mode, prints results and exits with code 1 if any tests fail. In runner mode (set by CLI), returns a summary struct for the test runner to process.
(test "example" (assert-true #t))
(run-tests) ; runs test and prints resultrun-tests-filteredprocedureRun tests matching a predicate and return a summary.
The predicate receives each test descriptor and should return #t for tests to include.
(run-tests-filtered
(lambda (td)
(string-contains? (test-descriptor-name td) "math")))run-tests-verboseprocedureRun tests and print results (legacy)
print-summaryprocedurePrint summary (legacy format)
countprocedureCount items matching predicate
value->stringprocedureConvert value to string for display
pair->stringprocedureConvert pair/list to string
vector->string-reprprocedureConvert vector to string
join-stringsprocedureJoin strings with separator
list?procedureCheck if something is a proper list
testvariable(No description)
test-groupvariable(No description)
test-skipvariable(No description)
test-pendingvariable(No description)
assert-errorvariable(No description)
register-test!variable(No description)
set-runner-mode!variable(No description)