diff --git a/xtest.c b/xtest.c index 2cd8af5..3b0209e 100644 --- a/xtest.c +++ b/xtest.c @@ -119,7 +119,7 @@ void xtest_internal_run(xtest_test_fn fn, const char *name, xtest_param *params, } expecting_assertion = 0; fn(fixture, current_vals); - int carry = 1; + _Bool carry = 1; for (int i = num_params - 1; i >= 0; --i) { validx[i] += 1; if (validx[i] >= valmax[i]) { @@ -129,7 +129,7 @@ void xtest_internal_run(xtest_test_fn fn, const char *name, xtest_param *params, break; } } - if (carry == 1) break; + if (carry) break; } } @@ -211,7 +211,7 @@ void xtest_internal_assert(const char *file, int line, const char *func, const c expression, invert ? "not " : "", CAST_PTR(type, expected), CAST_PTR(type, actual), file, line) void xtest_fail_assert(const char *expression, const char *file, int line, void *expected, - void *actual, int invert, enum xtest_type type) { + void *actual, _Bool invert, enum xtest_type type) { switch (type) { case xtest_type_bool: snprintf(assert_message, XTEST_ASSERT_MESSAGE_MAX_LEN, FAIL_ASSERT_FORMAT("%s"), expression, @@ -272,15 +272,15 @@ void xtest_fail_assert(const char *expression, const char *file, int line, void } void -xtest_assert_float(double expected, double actual, int precision, int invert, const char *expression, const char *file, +xtest_assert_float(double expected, double actual, int precision, _Bool invert, const char *expression, const char *file, int line) { double epsilon = 1.0; for (int i = 0; i < precision; ++i) epsilon /= 10.0; double diff = expected - actual; if (diff < 0) diff = -diff; - int equals = diff < epsilon; - int failed = invert == equals; // invert = true: fail if equals, invert = false: fail if not equals + _Bool equals = diff < epsilon; + _Bool failed = invert == equals; // invert = true: fail if equals, invert = false: fail if not equals if (!failed) return; snprintf(assert_message, 1024, "assertion failed: %s, expected %s%g but got %g (difference %g, precision %d) (%s:%d)", @@ -294,12 +294,12 @@ size_t find_diff_offset(const char *a, const char *b, size_t length) { return offset; } -void xtest_assert_mem(const char *expected, const char *actual, size_t length, int invert, const char *expression, +void xtest_assert_mem(const char *expected, const char *actual, size_t length, _Bool invert, const char *expression, const char *file, int line) { size_t offset = find_diff_offset(expected, actual, length); - int equals = offset == length; - int failed = invert == equals; // invert = true: fail if equals, invert = false: fail if not equals + _Bool equals = offset == length; + _Bool failed = invert == equals; // invert = true: fail if equals, invert = false: fail if not equals if (!failed) return; if (invert) { diff --git a/xtest.h b/xtest.h index 1d9a2ba..5808212 100644 --- a/xtest.h +++ b/xtest.h @@ -44,12 +44,12 @@ enum xtest_type { void xtest_fail_assert(const char *expression, const char *file, int line, void *expected, - void *actual, int invert, enum xtest_type type); + void *actual, _Bool invert, enum xtest_type type); void -xtest_assert_float(double expected, double actual, int precision, int invert, const char *expression, const char *file, +xtest_assert_float(double expected, double actual, int precision, _Bool invert, const char *expression, const char *file, int line); -void xtest_assert_mem(const char *expected, const char *actual, size_t length, int invert, const char *expression, const char *file, +void xtest_assert_mem(const char *expected, const char *actual, size_t length, _Bool invert, const char *expression, const char *file, int line); void xtest_internal_run(xtest_test_fn fn, const char *name, xtest_param *params, xtest_setup_fn setup,