Log inGet started
Package

caseBench.package

README.md

caseBench

Run logic tests in-process, from a script, without the engine's test runner.

Why

The engine's runner (tests.run, a suite's :run()) closes the open scene before the first test and reloads it from source after the last, so a suite never depends on what happened to be loaded. On an engine client several people or agents share, that throws away their unsaved scene state. Logic tests need no scene at all. caseBench runs them against a small framework of its own and touches nothing but the Lua values the cases create.

How a kit uses it

  1. Put cases in plain modules that return a function taking the framework:

    -- myKit.package/tests/cases/heat.module/init.luau
    local Heat = require("myKit.modules.heat")
    return function(Test: any)
        Test.describe("myKit.heat", function()
            Test.it("adds the points of a named offence", function()
                Test.expect(Heat.new(cfg):add("seen")).toBe(12)
            end)
        end)
    end
    
  2. Keep the kit's .testSuite as a thin file that hands the engine's framework to the same modules, so the engine runner (CI, the Inspector's Run) runs identical cases:

    local Test = asset.containing(__FILE__).modules.shared
    require("myKit.tests.cases.heat")(Test)
    return true
    
  3. Run them from an execute script while others work:

    local Bench = require("caseBench.modules.bench")
    return Bench.run({ { name = "myKit", cases = { require("myKit.tests.cases.heat") } } })
    

Public API

Bench.run(suites, opts?) -> report

ArgumentMeaning
suites{ { name, cases = { function(Test), ... } } }
opts.filterkeep tests whose "<describe> :: <it>" contains this text
opts.clockseconds source for durations (default os.clock)

report = { total, passed, failed, skipped, seconds, suites = { { name, total, passed, failed, skipped, seconds } }, failures = { { suite, group, test, errors = { text } } }, slowest = { { name, seconds } } }

The framework handed to cases is the subset of the engine's Test that logic cases use: describe, it, skip, beforeEach, afterEach, fail, and expect(value) with toBe, toBeTruthy, toBeFalsy, toBeNil, notToBeNil, toBeType, toBeGreaterThan, toBeLessThan, toBeCloseTo(expected, within = 0.001), toContain, toMatch, toHaveLength, toThrow, never(). A failed expectation is recorded and the body runs on, as in the engine's framework; a raise ends the body and is recorded.

Limits

Synchronous cases only (no waitFrames, no scenes, no entities). A case that needs the world belongs in a suite run by the engine runner. The Inspector's static list of test names reads Test.it calls in the suite file, so a thin suite shows none there; the run itself reports every case.