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

Panic utilities improvements: ensure DEBUG_ASSERT compiles, add ASSERT_EQ etc., add tests #571

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

pflanze
Copy link
Contributor

@pflanze pflanze commented Sep 12, 2024

resolves #559

Summary

  • ensure that DEBUG_ASSERT's arguments compile: even someone who just compiles in release mode will see if their test expressions in DEBUG_ASSERT(test-expression) compile
  • add ASSERT_EQ, ASSERT_LT etc.
  • add tests for the important features (including panic features)

I didn't add tests before because I thought it would be necessary to test them (in particular the abort feature) via a script from outside which would have been painful; but turns out gtest has ASSERT_DEATH which allows to do this perfectly.

This PR still doesn't extend UNREACHABLE / UNIMPLEMENTED for arguments, which are a bit challenging to do (the 0-ary case does not need to call fmt::format at all, and CPP macros have no easy dispatch on the number of arguments, but I think I know how to do it anyway now; but will only approach this when asked).

PR Checklist

  • [ x] All necessary documentation has been adapted or there is an issue to do so.
  • [ x] The implemented feature is covered by an appropriate test.

With the previous implementation, without -DDEBUG_ASSERT=1, the tested
expression is not compiled and could accidentally get stale. With this
implementation, the expression is always verified by the compiler, but
then still optimized out if DEBUG_ASSERT != 1.
@pflanze pflanze added the enhancement New feature or request label Sep 12, 2024
@pflanze pflanze changed the title Panic utilities improvemengts: ensure DEBUG_ASSERT compiles, add ASSERT_EQ etc., add tests Panic utilities improvements: ensure DEBUG_ASSERT compiles, add ASSERT_EQ etc., add tests Sep 12, 2024
Copy link
Collaborator

@Taepper Taepper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

There is no change in the changelog. This PR will not produce a new releasable version.

@pflanze
Copy link
Contributor Author

pflanze commented Sep 12, 2024

I have forgotten variable hygiene. Now should be ready.

@pflanze pflanze merged commit c34fa1f into main Sep 12, 2024
10 checks passed
@pflanze pflanze deleted the add_ASSERT_EQ_and_tests branch September 12, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More panic / assertment features
2 participants