title | group | category |
---|---|---|
Running & Writing Tests |
Documents |
Guides |
The comment-tests framework allows us to define CFG generation tests in the source-code that we test on. This makes test-writing easier, as we don't need to include code as strings in our tests.
Use bun test
to run all the tests.
If you have failing tests, you might want to visualize them. To do that, collect the test results as they get updated:
bun web-tests --watch
And run the web server to visualize them:
bun web
The current available test types are:
nodes
: asserts the expected node-count in the CFGexits
: asserts the expected exit-node count in the CFGreaches
: asserts reachability between node pairsrender
: asserts that the code CFG for ths code renders successfully
Additionally, code-segmentation and snapshot-tests are added automatically for the code used in comment-tests.
- Write your code in a new function in the matching file under
src/test/commentTestSamples
- Add a comment right above the function, declaring the relevant tests. The commend format is JSON, but without the curly braces.
When we add a new language, we need to add a test-collector for that language.
A test collector exports a getTestFuncs(code: string): Generator<TestFunction>
function.
To do that, we need to parse the code, and extract all functions and comments inside it.
It's best to look at one of the collect-<language>.ts
files to see how this is done.
Once we have a collector, we add it in src/test/commentTestCollector.ts
and map file-extensions to use with it.
Then, we add a test file under src/test/commentTestSamples
.