on
Extending cmark-gfm pt.3
Bugs, et al.
We’ve written up our code. It works and life is good. Or is it? Are modifications we’ve made going to break the code we already have. Life is good…?
To answer this and be confident that nothing breaks, when we inevitably modify
our code later, we are going to add on to the test cases that are run
automatically at build time via make test
.
Test cases are found under the tests
directory. The existing test samples have
the following format, and are easy enough to follow along
- Begin with a header line of
````` example
. - The Markdown text that needs to be parsed
- A line with a single
.
. This delineates our original Markdown text from the expected output. Our expected output will be in HTML, and will use the HTML renderer we had written earlier. Both being text, it’s easy for the test program to compare and evaluate success/failure. - End with a footer line of
`````
.
An example test case would be
The test script uses the cmark parser built at src/main.c
. We need to ensure
the reddit extension we’ve written is registered by the parser at
initialization. Add the following line to src/main.c: int main()
Finally, edit test/CMakeLists.txt
to add to the test cases that are run when
we build and test our code.
Run make && make test
, and we should see that our test cases are executed
(and, fingers crossed, pass) every time we build our code. Life is good!