Trisha Shetty (Editor)

ModAssert

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer(s)
  
Q-Mentum

Type
  
Assertion

Written in
  
C++

License
  
wxWidgets

Stable release
  
2.0.4 / April 27, 2011; 5 years ago (2011-04-27)

Website
  
modassert.sourceforge.net

ModAssert is an open source C++ library of assertion macros and a framework to process assertions. It is developed by Q-Mentum. The main difference from other assertion frameworks is that it can use Rich Booleans as well as ordinary conditions, allowing to decouple the behaviour of the assertion from the condition that it checks. Another difference is that it allows a developer to choose how failed assertions are handled by creating classes that implement the abstract base class ModAssert::Responder or ModAssert::Logger. Several implementations for various platforms of these are included. It also lets a developer add custom information when a failed assertion is processed by deriving from the abstract base class ModAssert::InfoProvider; several of these are provided, e.g. for the actual value of errno, the date and time, the amount of free memory, ...

It has a total of 144 different assertions. These can be divided in 9 basic types of assertions, that each have 16 variations. ModAssert makes a distinction between unexpected and expectes failures. Unexpected failures are failures due to programming errors, e.g. when a function returns an index to a container that is out of bounds. Expected failures are failures due to other conditions, e.g. a user entered a non-existing filename or a network connection could not be made. For unexpected failures there are the assertions MOD_ASSERT (removed in release versions), MOD_VERIFY (not removed in release versions), MOD_FAIL (without condition, always fails), MOD_VERIFY_V (returns a value in the condition) and MOD_VERIFY_B (returns true if the condition succeeded, false otherwise). For expected failures there are the similar macros MOD_CHECK, MOD_CHECK_FAIL, MOD_CHECK_V and MOD_CHECK_B, which are not removed for release versions.

These have variations that have one letter suffixes for each added capability. These are showing expressions if the assertion fails, offering an optional action to the user, assiging a group and or a level to the assertion, and ignoring default parameters. These four can be combined to make 16 variations of each basic assertion type.

ModAssert allows a developer to choose how failed assertions are reported. Typically this is a dialog box and or a log file. This allows the unit testing library UquoniTest to handle them somewhat differently, namely it reports failed assertions in domain code in a way similar to failed assertions in test code. UquoniTest can even check whether an assertion that is supposed to fail in certain condition, will actually fail.

References

ModAssert Wikipedia