Testing with b0 test

The b0 tool provides a simple test runner via the b0 test command.

A test is an unit action tagged with B0_meta.test and B0_meta.run. Lengthy tests have, additionally, the B0_meta.long tag, they are not run by default unless the --long option is specified.

Tests can be spotted by a T in b0 list, non-long tests are in green.

TODO image

The principle of b0 test is simple, it makes a build like a b0 invocation does and any test that must build is executed once built. So the following invocations build the default pack and execute the runnable tests therein.

b0 test
b0 test --long   # Also run the long tests

If any test exits with a non-zero error code, the invocation eventually exits with 1. If a test executable runs multiple tests it is advised to report the number of failing tests as the exit code.

Similar to b0 --what, invoking b0 test with the --what option tells you what the invocation builds and which tests are run:

b0 test --what

The granularity of tests is the executable unit. Above this you can easily devise your own test sets via packs and the usual build selection options -u, -p, -x and -X. For example:

b0 test -p special_tests -x known_to_fail

Also note that tests are just executable units so you can also run them individually with b0:

b0 -- mytest

Testing OCaml code

The infrastructure described above allows to hook the testing framework of your wish by simply tagging your test executables with B0_meta.test and B0_meta.run.

B0 itself provides a few testing tools to make such executables. A simplistic B0_testing module is available in the b0.std package. It simply runs tests as functions from unit -> unit, provides a few asserting tools and integrates nicely with b0 test's rendering. See an example.

The B0_expect tool for testing expectations which is expected to change a little bit in order to integrate in b0 test.