Larzscript Course · Lesson 13 of 15

Testing Your Larzscript Code

Larz covers Larzscript's test package: assert_eq and assert for checks, and report() for a pass/fail summary that also sets the process exit code.

writing an assertion

assert_eq checks a value against what you expected. report() prints a summary of everything you checked:

import "test" as t

fn add(a, b) {
    return a + b
}

t.assert_eq(add(2, 3), 5, "adds")
t.assert(add(2, 3) > 0, "result is positive")
t.report()
Output
ok - 2 passed

when a test fails

A failing assertion doesn't stop the run - it's recorded, and report() lists exactly what went wrong, and sets the exit code to 1:

import "test" as t

fn add(a, b) {
    return a + b
}

t.assert_eq(add(2, 3), 5, "adds")
t.assert_eq(add(2, 3), 6, "adds wrong on purpose")
t.report()
Output
  FAIL: adds wrong on purpose: expected 6 but got 5
1 failed, 1 passed

Every snippet on this page is run through the real larzscript interpreter, not hand-typed โ€” what you see in the Output blocks is the actual output, for everything shown: a passing test run and a genuinely failing one.

← Lesson 12Course syllabusGitHub