-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split debug and assert code into separate headers.
Assert can be used earlier because it only depends on the error-handler and not logging.
- Loading branch information
Showing
17 changed files
with
135 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*********************************************************************************************************************************** | ||
Assert Routines | ||
***********************************************************************************************************************************/ | ||
#ifndef COMMON_ASSERT_H | ||
#define COMMON_ASSERT_H | ||
|
||
#include "common/error.h" | ||
|
||
/*********************************************************************************************************************************** | ||
For very important asserts that are shipped with the production code | ||
***********************************************************************************************************************************/ | ||
#define ASSERT(condition) \ | ||
{ \ | ||
if (!(condition)) \ | ||
THROW(AssertError, "assertion '%s' failed", #condition); \ | ||
} | ||
|
||
/*********************************************************************************************************************************** | ||
Used for assertions that should only be run when debugging. Ideal for conditions that need to be tested during development but | ||
be too expensive to ship with the production code. | ||
***********************************************************************************************************************************/ | ||
#ifndef NDEBUG | ||
#define ASSERT_DEBUG(condition) \ | ||
{ \ | ||
if (!(condition)) \ | ||
THROW(AssertError, "debug assertion '%s' failed", #condition); \ | ||
} | ||
#else | ||
#define ASSERT_DEBUG(condition) | ||
#endif | ||
|
||
#endif |
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
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,24 @@ | ||
/*********************************************************************************************************************************** | ||
Test Assert Macros and Routines when Disabled | ||
***********************************************************************************************************************************/ | ||
|
||
/*********************************************************************************************************************************** | ||
Test Run | ||
***********************************************************************************************************************************/ | ||
void | ||
testRun() | ||
{ | ||
// ----------------------------------------------------------------------------------------------------------------------------- | ||
if (testBegin("ASSERT()")) | ||
{ | ||
TEST_RESULT_VOID(ASSERT(true), "assert true"); | ||
TEST_ERROR(ASSERT(false || false), AssertError, "assertion 'false || false' failed"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------------------------------------- | ||
if (testBegin("ASSERT_DEBUG()")) | ||
{ | ||
TEST_RESULT_VOID(ASSERT_DEBUG(true), "assert true ignored"); | ||
TEST_RESULT_VOID(ASSERT_DEBUG(false || false), "assert false ignored"); | ||
} | ||
} |
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,24 @@ | ||
/*********************************************************************************************************************************** | ||
Test Assert Macros and Routines | ||
***********************************************************************************************************************************/ | ||
|
||
/*********************************************************************************************************************************** | ||
Test Run | ||
***********************************************************************************************************************************/ | ||
void | ||
testRun() | ||
{ | ||
// ----------------------------------------------------------------------------------------------------------------------------- | ||
if (testBegin("ASSERT()")) | ||
{ | ||
TEST_RESULT_VOID(ASSERT(true), "assert true"); | ||
TEST_ERROR(ASSERT(false || false), AssertError, "assertion 'false || false' failed"); | ||
} | ||
|
||
// ----------------------------------------------------------------------------------------------------------------------------- | ||
if (testBegin("ASSERT_DEBUG()")) | ||
{ | ||
TEST_RESULT_VOID(ASSERT_DEBUG(true), "assert true"); | ||
TEST_ERROR(ASSERT_DEBUG(false || false), AssertError, "debug assertion 'false || false' failed"); | ||
} | ||
} |
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