-
Notifications
You must be signed in to change notification settings - Fork 184
Open
Description
In cr_assert(), criterion paste condition as a string directly, preventing use a simple bool expression:
In file included from ../subprojects/criterion/include/criterion/new/assert.h:464,
from ../test/rbtree.c:4:
../test/rbtree.c: In function ‘rb_insert_color_rr_inbalance_impl’:
../subprojects/criterion/include/criterion/new/../internal/new_asserts.h:54:20: error: pasting "CRI_ASSERT_TEST_SPECIFIER_" and "!" does not give a valid preprocessing token
54 | CRI_IF_DEFINED(CRI_ASSERT_TEST_SPECIFIER_ ## Spec, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
../subprojects/criterion/include/criterion/new/../internal/new_asserts.h:82:23: note: in expansion of macro ‘CRI_ASSERT_SPECIFIER’
82 | cri_cond_un = CRI_ASSERT_SPECIFIER(Condition); \
| ^~~~~~~~~~~~~~~~~~~~
../subprojects/criterion/include/criterion/new/../internal/new_asserts.h:173:5: note: in expansion of macro ‘CRI_ASSERT_CALL’
173 | CRI_ASSERT_CALL(File, Line, Fail, CR_VA_HEAD(__VA_ARGS__), , CR_VA_TAIL(__VA_ARGS__))
| ^~~~~~~~~~~~~~~
../subprojects/criterion/include/criterion/new/../internal/new_asserts.h:179:27: note: in expansion of macro ‘cr_assert_user’
179 | #define cr_assert(...) cr_assert_user(__FILE__, __LINE__, criterion_abort_test, __VA_ARGS__)
| ^~~~~~~~~~~~~~
../test/rbtree.c:104:5: note: in expansion of macro ‘cr_assert’
104 | cr_assert(!!rb_is_black(&(node2->rb)), "Root node should be black");
| ^~~~~~~~~Here what I am doing is call rb_is_black() and assert it should be true. but in this case, compile error evoked. The reason is clear that we paste the whole condition as a string together with CRI_ASSERT_TEST_SPECIFIER_, and ! is not a valid token.
An ugly workaround is:
cr_assert(
eq(i32, true, rb_is_black(&(node2->rb))),
"Root node should be black"
);which makes it a comparison between my function and the true.
sderr
Metadata
Metadata
Assignees
Labels
No labels