BOSL2 uses the openscad-test framework for regression testing. Tests are defined in tests/test_*.scadtest files — one file per BOSL2 module.
- OpenSCAD 2021.01 or later
- Python 3.x with
openscad-testinstalled:pip install openscad-test
Run all regression tests from the BOSL2 root directory:
./scripts/run_tests.shRun tests for a specific module:
openscad-test tests/test_transforms.scadtestRun tests for multiple specific modules:
openscad-test tests/test_math.scadtest tests/test_lists.scadtestEach tests/test_<module>.scadtest file contains one [[test]] entry per function or module being tested. Tests are written in TOML format using TOML literal multiline strings (''') for the inline OpenSCAD script.
[[test]]
name = "test_my_function"
script = '''
include <../std.scad>
module test_my_function() {
assert(my_function(1, 2) == 3);
assert_approx(my_function(1.5, 2.5), 4.0);
}
test_my_function();
'''The include <../std.scad> path resolves relative to the tests/ directory. For modules not included by std.scad, add the extra include:
[[test]]
name = "test_something"
script = '''
include <../std.scad>
include <../fnliterals.scad>
module test_something() {
assert(something() == expected);
}
test_something();
'''A test passes when OpenSCAD exits successfully and produces:
- No
ECHOoutput (useassert()rather thanecho()) - No
WARNINGoutput
A test fails if OpenSCAD exits with an error, or produces any unexpected ECHO or WARNING output.
| Helper | Use |
|---|---|
assert(expr) |
Fails if expr is false |
assert(expr, msg) |
Fails with message |
assert_approx(got, expected) |
Approximate equality (floating point) |
assert_equal(got, expected) |
Exact equality with diagnostic output |
If the test module needs a helper defined in the same .scadtest file (e.g., a shared helper used by multiple tests), define it in the script before the test module:
[[test]]
name = "test_my_function"
script = '''
include <../std.scad>
function my_helper(x) = x * 2;
module test_my_function() {
assert(my_function(my_helper(3)) == 6);
}
test_my_function();
'''The [[test]] section supports these optional fields:
[[test]]
name = "test_name"
script = '''...'''
expect_success = true # default: true; set false to expect failure
assert_echoes = ["ECHO: 42"] # require specific ECHO output substrings
assert_no_echoes = true # default: true
assert_warnings = ["WARNING: foo"] # require specific WARNING substrings
assert_no_warnings = true # default: true
set_vars = {var = "value"} # pass -D variables to OpenSCADTo check which public functions lack test coverage:
python3 scripts/func_coverage.pyThis reports which functions in the library source files have no corresponding test_<funcname> entry in the .scadtest files.
Each tests/test_<module>.scadtest file should test the functions and modules defined in <module>.scad. Each [[test]] entry name should match the function or module being tested:
name = "test_translate"→ teststranslate()fromtransforms.scadname = "test_path_length"→ testspath_length()frompaths.scad