ZeroErr
Assertion

Assertion library provided a list of marcos and functions for you to check condition in both your source code and unit testing code.

Basic Usage

A basic assertion marco is in one the following format:

CHECK(<expr> [, <message>, <args>...])

or

CHECK(<expr> OP <expr> [, <message>, <args>...]) which OP could be one of the ==, !=, <, >, <=, >=

or

CHECK(<cond> OP <cond> [, <message>, <args>...]) which OP could be AND/OR, <cond> could be an <expr> or <expr> OP <expr>

To reduce the complexity of parsing the expression and improve performance, we also provided a list of old style marcos:

Assertion Level

There are 3 levels of assertion marcos, you can replace CHECK to REQUIRE or ASSERT:

  • CHECK - There is something wrong happened but we still be able to continue run and get the result.
  • REQUIRE - The current function don't allow continue work and will throw and error.
  • ASSERT - The current program don't allow this happened and we must exit, there is no way to continue.

Variant

CHECK_NOT, REQUIRE_NOT, and ASSERT_NOT will check the condition which is expected not true.

CHECK_THROWS, REQUIRE_THROWS, and ASSERT_THROWS will expect the expression will throw an exception.