I recently completed the Interpreter challenge in Python and wanted to share something that was useful for me.
The author of the book has a comprehensive E2E testing suite that can verify one’s implementation of Lox adheres to the standard.
One needs to install Dart@2.19 in order to run the tests.
➜ craftinginterpreters git:(master) ✗ dart --version
Dart SDK version: 2.19.6 (stable) (Tue Mar 28 13:41:04 2023 +0000) on "macos_arm64"
Then build the project with make:
$ make get
$ make
Tests can be run like so:
$ dart tool/bin/test.dart jlox --interpreter ../codecrafters-interpreter-python/your_program.sh
I’m choosing jlox
as the test suite and passing the path to my interpreter via the --interpreter
option.
One can also run a specific test suite by passing the test file name after the test suite name:
$ dart tool/bin/test.dart jlox operator/comparison.lox --interpreter ../codecrafters-interpreter-python/your_program.sh
It’s also possible to run the tests until a certain chapter, in case you’re still building it out:
$ dart tool/bin/test.dart chap10_functions --interpreter ../codecrafters-interpreter-python/your_program.sh
This test suite is especially helpful if one desires to continue the book and work on chapters 11-13.
I hope this helps folks that are tackling this fun challenge!