Repository navigation
Testing and Coverage
A .scadtest file says what a library is supposed to do; coverage says how much of the library the tests actually reached. BelfrySCAD runs both — from the command line, and from a pane inside the app.
The format is openscad-test's own, and so is the output and the exit code, so a project's existing runner script (BOSL2's scripts/run_tests.sh, for instance) works unchanged. The difference is that the scripts run inside BelfrySCAD's evaluator instead of launching the OpenSCAD binary once per test, which is why serial is already faster here than the reference's parallel default.
Tests build no geometry. They run the language — assignments, functions, modules, echo, assert — and stop there.
belfryscad --test suite.scadtest [more.scadtest ...]
--test takes over the rest of the command line; belfryscad --test -h lists its own options.
geom.scadtest
double() doubles PASSED
clamp() holds the low end PASSED
a zero-thickness ring complains PASSED
3 of 3 passed, 0 failed.
3 of 3 tests passed, 0 failed.
A failure names the test, then says what it expected and what it got, and every failure is repeated at the end so you don't have to scroll:
fail.scadtest
this one fails FAILED
Expected echo not found: 99
42
0 of 1 passed, 1 failed.
0 of 1 tests passed, 1 failed.
Failed tests:
fail.scadtest: this one fails
Exit code is 0 if everything passed, 1 if anything failed — which is the whole CI story.
| Option | |
|---|---|
-j N, --jobs N
|
Run N tests at once (default 1). Threads in this process, not fresh launches |
--coverage |
Also report what the tests exercised, merged over every test |
--coverage-json PATH |
Write the merged coverage as JSON as well |
--coverage-min PERCENT |
Exit 1 if overall coverage is below this, even when every test passed |
--coverage-json and --coverage-min imply --coverage.
There is no belfryscad --coverage file.scad. Coverage of one run of one script answers a question worth very little; "what does my suite miss" is the question worth asking. Wrap the script in a one-line .scadtest if you want it measured.
TOML: an optional [config] table of defaults, then any number of [[test]] blocks.
[config]
timeout = 30
[[test]]
name = "double() doubles"
script = '''
include <geom.scad>
echo(double(21));
'''
assert_echoes = ["42"]
[[test]]
name = "a bad thickness is reported, not fatal"
script = '''
include <geom.scad>
ring(10, 0);
'''
assert_echoes = ["thickness must be positive"]Use TOML literal strings (''') for scripts. A basic (""") string eats OpenSCAD's backslashes.
| Key | Default | |
|---|---|---|
name |
"Unnamed Test" |
What the results call it |
script |
— | The script, inline |
script_file |
— | A script on disk instead, relative to the .scadtest file
|
timeout |
60 |
Seconds before the test is failed as hung |
set_vars |
none |
{name = value} pairs, appended to the script as OpenSCAD assignments |
expect_success |
true |
Set false to assert the script fails
|
assert_echoes |
none | Each string must appear in some echo output (substring match) |
assert_no_echoes |
true |
Fail on any echo at all — ignored when assert_echoes names some
|
assert_warnings |
none | Each string must appear in some warning |
assert_no_warnings |
true |
Fail on any warning — ignored when assert_warnings names some
|
A test needs exactly one of script or script_file; both, or neither, is an error.
include and use resolve from the .scadtest file's own directory, whichever way the script was supplied.
[config] supplies defaults for timeout, expect_success, assert_no_echoes and assert_no_warnings.
set_vars values are TOML and are converted to OpenSCAD source, so true stays true rather than becoming 1, and a list becomes a vector.
In order, stopping at the first failure:
- Did the script succeed (or fail, with
expect_success = false)? - Is every string in
assert_echoespresent? -
assert_no_echoes— but only ifassert_echoesis empty. A test that expects an echo cannot also expect none. - Is every string in
assert_warningspresent? -
assert_no_warnings, again only ifassert_warningsis empty.
A crash or a timeout is a failed test, not a crashed run.
belfryscad --test --coverage *.scadtest
Coverage (worst first):
geom.scad 50.0% statements 2/5 branches 2/6 bodies 3/3
TOTAL 50.0% statements 2/5 branches 2/6 bodies 3/3
Three things are counted, and the vocabulary is the evaluator's:
- statements — each statement that ran
-
branches — each arm of an
ifor a?:, so anelsenobody takes shows up - bodies — each function or module body that was entered
Only the resolve pass is measured, which is the pass that runs script code; the geometry pass runs none. The tests' own temporary snippets are dropped from the report, so what you see is the library.
One library reached from two directories by two different relative paths (lib.scad here, ../lib.scad from a subdirectory) is one file in the report, not two half-covered ones.
Put /* nocov */ on a line and it excludes the largest span that starts on that line, and everything nested inside it:
module ring(r, t) { /* nocov */
...
}takes the whole module. On a plain statement it takes just that statement; on an if (...) { line it takes the branch and both arms.
Excluded spans are dropped, not counted as covered — they leave the percentage alone rather than inflating it.
The marker has to be on the same line as the code it excludes. A /* nocov */ on its own line above a module excludes nothing, because no span starts there.
belfryscad --test --coverage --coverage-min 80 tests/*.scadtest
belfryscad: coverage 50.0% is below --coverage-min 80.0
...and exit 1, even though every test passed.
Design ▸ Run Tests… asks for a directory of .scadtest files — tests are project-wide, not per-file — and opens the Testing pane. It's a pane rather than a dialog, so the editor, the console and the coverage overlay stay usable while a suite runs.
| Choose… | Pick the tests directory (searched recursively). The path is elided; the full one is in the tooltip |
| Collect coverage | Record coverage for this run |
| Highlight coverage in editors | Paint the result over your open tabs |
| Run Tests | Becomes Cancel while a run is going |
| New File… | Create a .scadtest and go straight into the test editor |
| Report… | A monospace window: the per-file lines plus every uncovered span, worst file first |
The results tree has one row per .scadtest file — passed/total, % passed, and the coverage that file's tests reach on their own — expanding to the individual tests. A file with a failure opens itself, and the failure messages are the row's tooltip. A totals line sits underneath.
Suites are listed as soon as you choose a directory, before any run, so you can edit tests without running anything first. A long suite fills the tree in as it goes rather than landing all at once.
Double-click a test to open the test editor. Name sits above three tabs:
- Source — an inline script or a script file, and the timeout
-
Overrides — the
set_varstable, a Variable / Value grid with + / −. Each value is TOML, parsed exactly as it would be in the file -
Results —
expect_successand the echo/warning assertions
Right-click the tree for the rest. A file row offers Run Tests in this File, then Add Test. A test row offers Add Test Before, Add Test After and Delete Test (which asks first).
Saving splices the one [[test]] block in or out rather than rewriting the file, so your comments and your [config] formatting survive.
Double-clicking a file row does nothing on purpose — the file is scaffolding; the test is the thing worth editing.
With Highlight coverage in editors on, the result is painted over every open tab — and over a library you have open in a tab, which is the interesting case. Spans that never ran are a translucent red; covered ones a faint green.
Indentation and blank lines are never tinted: a bar of color down the indent column says nothing about what ran. Where spans nest, the innermost one decides — an uncovered statement inside a covered body reads as uncovered, which is also the right answer.
Editing a tab clears its overlay, exactly as it clears the error squiggle: the spans have moved. The next run restores it.
Preferences ▸ Editor ▸ Coverage turns the green off if you would rather see only what never ran.
Coverage is session-only. It is never written to your settings, and it comes from a test run or not at all — there is no per-render capture.
The AI chat can list tests, read one, run them, and ask what coverage is missing. It can also propose a test change — which arrives as a reviewable diff, like every other proposal, and is written only when you accept it. Everything it touches is confined to the tests directory you chose.
- Give a test a name that reads as a claim (
"clamp() holds the low end"), because that name is what the failure output says. -
assert()inside the script is often simpler thanassert_echoes— the script failing is the test failing. -
expect_success = falseis how you test that bad input is actually rejected. - Run with
--coverageoccasionally even if you don't gate on it. Branch coverage in particular tends to reveal theelsenobody has ever taken. - Reach for
/* nocov */sparingly: it is for code that genuinely cannot be exercised, not for code that is merely inconvenient to test.
Start here
Using the app
- Code Editor
- Viewport and Navigation
- Rendering
- Render Performance
- Debugger
- Customizer
- Animation
- Demo Scripts
- Data Viewers
- AI Chat
- Libraries
- Fonts
- Colors
- Exporting
- Testing and Coverage
- Documentation Generation
- Preferences
- Command Line
- Troubleshooting
Language reference