Collect and compare MoonBit behavior across compiler backends
Dependencies
git clone https://github.com/kaigeliang/moonbit-casekit.git
cd moonbit-casekit
moon update
python3 tools/check_targets.py# Other runnable use cases
python3 tools/check_targets.py --package src/examples/numeric
python3 tools/check_targets.py --package src/examples/collections
# Print an intentional mismatch, including nested array and type differences
moon run --target native src/examples/canary
# Select backends, optimization mode and an explicit floating-point tolerance
python3 tools/check_targets.py --targets native js --release --abs-tol 0.000001members = ["./my-library", "./moonbit-casekit"]import {
"kaigeliang/casekit" @casekit,
}
pkgtype(kind: "executable")fn main raise {
let suite = @casekit.Suite::new("my-library")
suite.observe("sorted", [1, 2, 3].to_json())
suite.observe("message", "你好🌙".to_json())
suite.observe_number("decimal-sum", 0.1 + 0.2)
println(suite.encode())
}python3 tools/check_targets.py --project ../my-library --package src/observationsmoon build --target native
_build/native/debug/build/cli/cli.exe expected.json actual.json
_build/native/debug/build/cli/cli.exe --json expected.json actual.json
_build/native/debug/build/cli/cli.exe --abs-tol 0.000001 expected.json actual.json| Code | Meaning |
|---|---|
| 0 | All recorded cases match |
| 1 | Valid runs differ |
| 2 | Invalid input, invalid settings, build/runtime failure or timeout |
let report = @casekit.compare(@casekit.decode(expected), @casekit.decode(actual))
println(report.render())
println(report.encode()) // JSON report for another toolmoon fmt --check
moon test --target native
moon test --target js
moon test --target wasm
moon test --target wasm-gc
moon build --target native
python3 -m unittest discover -s tests -vpub(all) suberror CaseError {
Invalid(String)
}pub(all) struct Difference {
case_id : String
path : String
kind : DifferenceKind
expected : Json?
actual : Json?
} derive(ToJson)pub(all) struct Report {
suite : String
total_cases : Int
matched_cases : Int
abs_tol : Double
rel_tol : Double
differences : Array[Difference]
} derive(ToJson)pub struct Suite {
name : String
// private fields
}Install
Download zipCollect and compare MoonBit behavior across compiler backends
Dependencies