-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic asserts (Design by Contract)
- Loading branch information
Showing
7 changed files
with
160 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** \file */ | ||
|
||
#ifndef ASSERT_H | ||
#define ASSERT_H | ||
|
||
#include <stdbool.h> | ||
|
||
#include "CException.h" /* Exception handling lib. interface */ | ||
|
||
/* `assert` replacement for unit testing */ | ||
#define assert(condition_) if (false == (condition_)) Throw(0) | ||
|
||
/* Unit testing assertion that `assert` is triggered */ | ||
#define TEST_ASSERT_FAIL_ASSERT(codeUnderTest_) \ | ||
do { \ | ||
CEXCEPTION_T exception_; \ | ||
Try { \ | ||
codeUnderTest_; \ | ||
TEST_FAIL_MESSAGE("Code under test did not assert."); \ | ||
} \ | ||
Catch(exception_) {;} \ | ||
} while (false) | ||
|
||
/* Unit testing assertion that `assert` is *not* triggered */ | ||
#define TEST_ASSERT_PASS_ASSERT(codeUnderTest_) \ | ||
do { \ | ||
CEXCEPTION_T exception_; \ | ||
Try { \ | ||
codeUnderTest_; \ | ||
} \ | ||
Catch(exception_) { \ | ||
TEST_FAIL_MESSAGE("Code under test failed an assertion."); \ | ||
} \ | ||
} while (false) | ||
|
||
#endif /* ASSERT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters