Testing with b0 test

Running tests

The b0 test command is a simple test runner for your B0.ml file.

A test unit is a unit tagged with B0_meta.test and B0_meta.run and, for lengthy tests, the B0_meta.long tag. Tests can be spotted by a T in b0 list; the non-lengthy ones are in green.

The operating principle of b0 test is simple:

  1. It makes a build exactly like a b0 invocation does.
  2. It executes the action of any test unit that must build in that build.

For example the following invocations build the default pack and execute the test units therein:

b0 test
b0 test -l      # Do not skip the long tests

If any test exits with a non-zero error code, the b0 test invocation eventually exits with 1.

Adding --what a b0 test invocation reports what is build and which tests are executed.

b0 test --what  # Show what builds and runs

For b0 the testing granularity is the executable unit. 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

Since tests are just executable units so you can also run them individually with usual b0 invocations:

b0 -- mytest

That's all there is to know about b0 and testing.

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 for OCaml: