#endif
}
-bool check_condition_impl(char const* file, int line, bool condition)
+bool libtest_check(char const* file, int line, bool pass, bool condition, char const* condition_str)
{
- bool const pass = condition;
+ if (should_print(pass))
+ {
+ fprintf(stderr, "%s %s:%d: %s (%s)\n", pass ? "PASS" : "FAIL", file, line, condition_str, condition ? "true": "false");
+ }
+ return pass;
+}
+
+bool libtest_check_bool(char const* file, int line, bool pass, bool lhs, bool rhs, char const* lhs_str, char const* op_str,
+ char const* rhs_str)
+{
if (should_print(pass))
{
- fprintf(stderr, "%s %s:%d\n", pass ? "PASS" : "FAIL", file, line);
+ fprintf(stderr, "%s %s:%d: %s %s %s (%s %s %s)\n", pass ? "PASS" : "FAIL", file, line, lhs_str, op_str, rhs_str,
+ lhs ? "true" : "false", op_str, rhs ? "true" : "false");
}
return pass;
bool should_print(bool pass);
-bool check_condition_impl(char const* file, int line, bool condition);
-
+bool libtest_check(char const* file, int line, bool pass, bool condition, char const* condition_str);
+bool libtest_check_bool(char const* file, int line, bool pass, bool lhs, bool rhs, char const* lhs_str, char const* op_str,
+ char const* rhs_str);
bool libtest_check_str(char const* file, int line, bool pass, char const* lhs, char const* rhs, char const* lhs_str,
char const* op_str, char const* rhs_str);
bool libtest_check_int(char const* file, int line, bool pass, intmax_t lhs, intmax_t rhs, char const* lhs_str,
{ \
++current_test; \
\
- if (!check_condition_impl(__FILE__, __LINE__, (condition))) \
+ bool const check_result = (condition); \
+ \
+ if (!libtest_check(__FILE__, __LINE__, check_result, check_result, #condition)) \
+ { \
+ return current_test; \
+ } \
+ } \
+ while (0)
+
+#define check_bool(lhs, op, rhs) \
+ do \
+ { \
+ ++current_test; \
+ \
+ bool const check_bool_lhs = (lhs); \
+ bool const check_bool_rhs = (rhs); \
+ \
+ if (!libtest_check_bool(__FILE__, __LINE__, check_bool_lhs op check_bool_rhs, check_bool_lhs, check_bool_rhs, #lhs, \
+ #op, #rhs)) \
{ \
return current_test; \
} \