-
Notifications
You must be signed in to change notification settings - Fork 366
Open
Description
title
_assert_false Function implementation logic error, causing the assertion judgment result to be reversed
Problem description
The conditional judgment logic of a function is completely opposite to the function name and expected behavior:
When the input parameter result is 0 (false), the function triggers an error
When the input parameter result is non-zero (true), the function asserts through an assertion
This leads to the use of assert_false(condition) in test cases, where the actual expected condition is true (non-zero), which contradicts the original intention of the function design.
Reproduce steps
void test_assert_false(void **state) {
int result = 0;
assert_false(result); // 期望通过,但实际失败
}but output it
expected 'result' to be false
ERROR: test.c:123 Failure!Debugging shows that the value of 'result' is indeed 0, but the '_assert_false ' function incorrectly triggered an assertion failure
Reason for the problem
in src/cmockery. c
void _assert_true(const LargestIntegralType result,
const char * const expression,
const char * const file, const int line) {
if (!result) {
print_error("expected '%s' to be true\n", expression);
_fail(file, line);
}
}
void _assert_false(const LargestIntegralType result,
const char * const expression,
const char * const file, const int line) {
if (!result) {
print_error("expected '%s' to be false\n", expression);
_fail(file, line);
}
}
Metadata
Metadata
Assignees
Labels
No labels