Rich Booleans
Developer(s) | Q-Mentum |
---|---|
Stable release | 2.2 / April 27, 2011 |
Written in | C++ |
Type | Assertion |
License | wxWidgets |
Website |
sourceforge |
Rich Booleans is a C++ library of macros that can be used in assertions to check conditions, that provide extra information when the condition fails, which helps the programmer in determining the cause of the problem. This is similar to constraints in JUnit, the main difference being that with Rich Booleans there is no clear distinction between the expected value and the checker, e.g. an assertion with a Rich Boolean for equality would be ASSERT(rbEQUAL(a,1)) while in JUnit it would be assertThat(a, eq(1)).
Rich Booleans is developed by Q-Mentum.[1]
Rich Booleans make it possible to decouple the behaviour of an assertion from the condition it checks. This means a user can write ASSERT(rbEQUAL(a,b)), whereas other frameworks would require ASSERT_EQUAL(a,b); the Rich Booleans allow to separate the functionality in the assertion and the condition, making it possible to have many variations of the assertion and the condition.
If a condition fails it will create an object of the RichBool::Analysis class, which is a base class for different types of analysis. These can be converted to text or processed further to provide the information in them to the developer or user. rbEQUAL(x,y) would create an analysis that holds the text "<x>:`1' == <y>:`2' - nok", showing the expression between < and >, and their values between ` and '. Other Rich Booleans produce longer analyses, e.g. checking string equality will show which characters match and which don't.
Starting in version 2.2 Rich Booleans uses some C++0X features, namely regular expressions and initializer lists, but still works with compilers that don't have these features.
There are over 80 different Rich Booleans.
- Relations between objects, without and with fault tolerance: rbEQUAL, rbLESS, ...
- Bitwise comparisons: rbEQUAL_BITWISE, rbBITS_ON, rbBITS_OFF, rbBITS_ARE ...
- Type checking (with RTTI): rbEQUAL_TYPES, rbHAS_TYPE, ...
- Working on ranges and containers: rbIN_RANGE, rbIN_RANGES, rbIN_CONTAINER, rbIN_CONTAINERS, ... These have an extra argument that tells what kind of check to do, e.g. Sorted, Compare, Has, Unique, IsSubsetOf ...
- String comparisons: rbSTRING, rbSTRING_BEGINS_WITH, rbSTRING_ENDS_WITH, rbSTRING_CONTAINS. These have an extra argument that tells what kind of check to do, e.g. case sensitive or not.
- Checks on strings with C++0X regular expressions: rbREGEXP, rbHAS_REGEXP, ...
- Logical expressions: rbAND, rbOR, rbXOR. These can have Rich Booleans or plain boolean expressions as their arguments.
- File system checks: rbFILE, rbDIRECTORY, rbFILE_EXISTS, rbDIRECTORY_EXISTS, rbDOESNT_EXIST.
- Exceptions: rbEXCEPTION takes an exception as its argument, and uses the information in it.
Some frameworks that use Rich Booleans are the assertion framework ModAssert and the unit testing package UquoniTest.
See also
- UquoniTest
- ModAssert
References
External links
- Rich Booleans on SourceForge.net
- A description of Rich Booleans and ModAssert
- ModAssert ModAssert, an assertion framework that uses Rich Booleans