Testing
Every capability claimed on the parity page has an executable test. None of them need hardware.
Run the suite
$ cmake -B build . && cmake --build build # the tests drive the real VM binary
$ cd tools/mothc && dart test
01:18 +84: All tests passed!
How it works
Each case is a .dart file in test/cases/ with a matching .out file. The
runner compiles the source, runs it on mothrun, and compares stdout exactly.
The useful part is where the expectations come from. For anything that is pure
computation — arithmetic, control flow, recursion, logic — the .out file is
generated by running the same program on the real Dart SDK:
$ cd test/cases
$ dart arithmetic.dart > arithmetic.out
So the suite does not assert that moth matches its own past behavior. It
asserts that moth matches Dart. That caught a real bug on the first run:
Dart's % is Euclidean, so 7 % -3 is 1, and the VM had it as -2.
Add a case
Create test/cases/mycase.dart, then generate its expectation:
$ dart test/cases/mycase.dart > test/cases/mycase.out # if it is pure Dart
If the program calls hardware built-ins, real Dart cannot run it — produce the
expectation with mothrun instead, and read it carefully before committing,
since it is only as correct as the run that produced it:
$ dart run tools/mothc/bin/mothc.dart test/cases/mycase.dart
$ ./build/vm/mothrun test/cases/mycase.mothb --quiet > test/cases/mycase.out
Testing peripherals
A case may ship a .args file with simulator flags, so hardware behavior is
testable without hardware. test/cases/peripherals.args:
--analog 4=1234 --i2c-device 0x5a
That makes analogRead(4) return 1234 and puts a fake I2C device at 0x5A, so
the case can assert on a write/read round-trip and on the −1 "no answer"
sentinel for a missing device.
Testing on real hardware
The simulator proves logic; only a board proves wiring. examples/i2c_scan.dart
is the standard smoke test — flash it and confirm the addresses it reports match
the devices you expect:
$ dart run tools/mothc/bin/mothc.dart examples/i2c_scan.dart \
-o vm/esp/main/program.mothb
$ cd vm/esp && idf.py build && idf.py -p <port> -b 115200 flash monitor
On a Waveshare ESP32-S3-Touch-AMOLED it finds eight devices, 0x5A being the touch controller.
What is not tested yet
- No test asserts VM performance; the interpreter's speed is unmeasured.
- The ESP host's natives are exercised by hand, not in CI — there is no hardware-in-the-loop runner.
moth_renderhas no conformance suite yet (see the backend contract, §7).