While searching the forum for ‘unit testing,’ I found quite a few ideas and pointers, but no clear, step-by-step instructions. So, I’ll share the solution I came up with.
It’s a minor patch that adds Catch2 as a submodule to Rack and an extra command-line option, which finds all tests inside the loaded plugins and runs them.
To get this running download this patch to your development rack dir: Catch2_patch.txt (updated April 27)
cd your_dev_rack_dir
git submodule add -f https://github.com/catchorg/Catch2.git dep/Catch2
git apply Catch2_patch.txt
make dep
make
And you can start running tests like so:
./Rack -d -r
./Rack -d --runtests='-?'
./Rack -d --runtests='--rng-seed=234 --order=decl [Shared]'
Which generates output like:
[2.536 info src/tests/runtests.cpp:29 runTests] Running tests with arguments --rng-seed=234 --order=decl [Shared]
Filters: [Shared]
Randomness seeded to: 234
==============================================================================
All tests passed (92 assertions in 3 test cases)
On the plugin side:
Download and add these files from the Catch2 project to your own project:
And start writing tests in your plugin:
#include "catch_amalgamated.hpp"
#include "ClockTracker.hpp"
TEST_CASE("ClockTracker", "[Shared][ClockTracker][lowlevel]") {
SECTION("isPeriodDetected") {
REQUIRE(...)
...
etc.
Only tested this on Linux using version 241 and 251.