chore: Adding macros with message for all ASSERTS.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = \
|
||||
format_string("Expect %d to be %d.\n", act, exp) return; \
|
||||
format_string("Expect %d not to be %d.\n", act, exp) return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_MSG(exp, act, msg) \
|
||||
@@ -33,6 +33,16 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_MSG(exp, act, msg) \
|
||||
if (exp == act) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %d not to be %d\n Failed with message: " msg, act, \
|
||||
exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_TRUE(x) \
|
||||
if (!x) \
|
||||
{ \
|
||||
@@ -41,6 +51,15 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_TRUE_MSG(x, msg) \
|
||||
if (!x) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected true got false.\n Failed with message: " msg); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE(x) \
|
||||
if (x) \
|
||||
{ \
|
||||
@@ -49,6 +68,15 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_FALSE_MSG(x, msg) \
|
||||
if (x) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected false got true.\n Failed with message: " msg); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_FLOAT(exp, act, epsilon) \
|
||||
if (fabs(exp - act) <= epsilon) \
|
||||
{ \
|
||||
@@ -58,12 +86,32 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_FLOAT_MSG(exp, act, epsilon, msg) \
|
||||
if (fabs(exp - act) <= epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %f to be %f (e: %f)\n Failed with message: " msg, \
|
||||
act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_FLOAT(exp, act, epsilon) \
|
||||
if (fabs(exp - act) > epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = \
|
||||
format_string("Expected %f to be %f (e: %f)", act, exp, epsilon); \
|
||||
test->error_msg = format_string("Expected %f not to be %f (e: %f)", \
|
||||
act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_FLOAT_MSG(exp, act, epsilon, msg) \
|
||||
if (fabs(exp - act) > epsilon) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
test->error_msg = format_string( \
|
||||
"Expected %f not to be %f (e: %f)\n Failed with message: " msg, \
|
||||
act, exp, epsilon); \
|
||||
return; \
|
||||
}
|
||||
|
||||
@@ -76,12 +124,32 @@
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_EQ_STR_MSG(exp, act, msg) \
|
||||
if (strcmp(exp, act) != 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = format_string( \
|
||||
"Expected: %d\nBut got: %d\n Failed with message: " msg, act, \
|
||||
exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_STR(exp, act) \
|
||||
if (strcmp(exp, act) == 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = \
|
||||
format_string("Expected: %d\nBut got: %d", act, exp); \
|
||||
format_string("Expected not: %d\nBut got: %d", act, exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define ASSERT_NEQ_STR_MSG(exp, act, msg) \
|
||||
if (strcmp(exp, act) == 0) \
|
||||
{ \
|
||||
test->passed = false; \
|
||||
type->error_msg = format_string( \
|
||||
"Expected not: %d\nBut got: %d\n Failed with message: " msg, \
|
||||
act, exp); \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,7 @@ TEST(Faculty_Negative)
|
||||
{
|
||||
ASSERT_EQ(fac(-2), 1);
|
||||
ASSERT_EQ(fac(0), 1);
|
||||
ASSERT_TRUE_MSG(false, "Hello");
|
||||
}
|
||||
|
||||
SUIT_SETUP(Basic_Setup)
|
||||
|
Reference in New Issue
Block a user