Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cr_assert(): Paste condition as a string cause error #550

Open
MrZLeo opened this issue Jul 27, 2024 · 0 comments
Open

cr_assert(): Paste condition as a string cause error #550

MrZLeo opened this issue Jul 27, 2024 · 0 comments

Comments

@MrZLeo
Copy link

MrZLeo commented Jul 27, 2024

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 functionrb_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 macroCRI_ASSERT_SPECIFIER82 |         cri_cond_un = CRI_ASSERT_SPECIFIER(Condition);                          \
      |                       ^~~~~~~~~~~~~~~~~~~~
../subprojects/criterion/include/criterion/new/../internal/new_asserts.h:173:5: note: in expansion of macroCRI_ASSERT_CALL173 |     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 macrocr_assert_user179 | #define cr_assert(...)    cr_assert_user(__FILE__, __LINE__, criterion_abort_test, __VA_ARGS__)
      |                           ^~~~~~~~~~~~~~
../test/rbtree.c:104:5: note: in expansion of macrocr_assert104 |     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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant