Skip to content

Commit

Permalink
Rearrange test header and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmavr committed Dec 5, 2023
1 parent bb3bea0 commit a73937f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions test/nanotest.h
Expand Up @@ -14,6 +14,9 @@ extern "C" {
#define NTEST_FAIL 1
int ntest_result = NTEST_PASS;

//------------------------------------------------------------//
// Helper (internal) macros //
//------------------------------------------------------------//
// credits @red1ynx (https://stackoverflow.com/a/8488201)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

Expand All @@ -32,12 +35,12 @@ int ntest_result = NTEST_PASS;
// empty="", a=1, b=3, c=37, d=6, e=5, f=4, --> cnt=3
#define COUNT_ARGS_(empty, a, b, c, d, e, f, cnt, ...) cnt

// CHecks if parameter is empty; if so it substitutes it with a
// default value so the compiler doesn't complain #args is fixed.
// credits @p00ya (https://stackoverflow.com/a/62650578)
#define CHECK_EMPTY(default_val, ...) (default_val CHECK_EMPTY_(__VA_ARGS__))
#define CHECK_EMPTY_(...) ,##__VA_ARGS__

// unit test macros
#define NTEST_ASSERT_FLOAT_CLOSE(...) NTEST_ASSERT_FLOAT_CLOSE_(__VA_ARGS__)
#define NTEST_ASSERT_FLOAT_CLOSE_(actual, expected, ...) \
do { \
const float actual_value = (actual); \
Expand All @@ -58,6 +61,11 @@ int ntest_result = NTEST_PASS;
} while(0)


//------------------------------------------------------------//
// External use macros //
//------------------------------------------------------------//
#define NTEST_ASSERT_FLOAT_CLOSE(...) NTEST_ASSERT_FLOAT_CLOSE_(__VA_ARGS__)

#define NTEST_ASSERT(condition) \
do { \
if (condition) \
Expand Down

0 comments on commit a73937f

Please sign in to comment.