diff --git a/test/test.c b/test/test.c index 7bd1565..59fd6da 100644 --- a/test/test.c +++ b/test/test.c @@ -259,3 +259,14 @@ UTEST(c, Near) { } UTEST(c, Todo) { UTEST_SKIP("Not yet implemented!"); } + +static int test_func_int(int a, int b) +{ + return a -1.00001f && res < -0.99999f;}); + ASSERT_PRED(1, 2, [](int a, int b){return a 0) { \ + UTEST_PRINTF(" Message : %s\n", msg); \ + } \ + *utest_result = UTEST_TEST_FAILURE; \ + if (is_assert) { \ + return; \ + } \ + } \ + } \ + while (0) \ + UTEST_SURPRESS_WARNING_END +#elif defined(__GNUC__) || defined(__TINYC__) +#define UTEST_PRED(x, y, cond, msg, is_assert) \ + UTEST_SURPRESS_WARNING_BEGIN do { \ + UTEST_AUTO(x) xEval = (x); \ + UTEST_AUTO(y) yEval = (y); \ + if (!(cond((xEval),(yEval)))) { \ + UTEST_PRINTF("%s:%i: Failure\n", __FILE__, __LINE__); \ + UTEST_PRINTF(" Actual : "); \ + utest_type_printer(xEval); \ + UTEST_PRINTF(" vs "); \ + utest_type_printer(yEval); \ + UTEST_PRINTF("\n"); \ + if (strlen(msg) > 0) { \ + UTEST_PRINTF(" Message : %s\n", msg); \ + } \ + *utest_result = UTEST_TEST_FAILURE; \ + if (is_assert) { \ + return; \ + } \ + } \ + } \ + while (0) \ + UTEST_SURPRESS_WARNING_END +#else +#define UTEST_PRED(x, y, cond, msg, is_assert) \ + UTEST_SURPRESS_WARNING_BEGIN do { \ + if (!(cond((x),(y)))) { \ + UTEST_PRINTF("%s:%i: Failure", __FILE__, __LINE__); \ + if (strlen(msg) > 0) { \ + UTEST_PRINTF(" Message : %s", msg); \ + } \ + UTEST_PRINTF("\n"); \ + *utest_result = UTEST_TEST_FAILURE; \ + if (is_assert) { \ + return; \ + } \ + } \ + } \ + while (0) \ + UTEST_SURPRESS_WARNING_END +#endif + +#define EXPECT_PRED(x, y, pred) UTEST_PRED(x, y, pred, "", 0) +#define EXPECT_PRED_MSG(x, y, pred, msg) UTEST_PRED(x, y, pred, msg, 0) +#define ASSERT_PRED(x, y, pred) UTEST_PRED(x, y, pred, "", 1) +#define ASSERT_PRED_MSG(x, y, pred, msg) UTEST_PRED(x, y, pred, msg, 1) + + #if defined(__clang__) #if __has_warning("-Wunsafe-buffer-usage") #define UTEST_SURPRESS_WARNINGS_BEGIN \