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

[TEST] Add EXPECT_THROW_MSG #245

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

eseiler
Copy link
Member

@eseiler eseiler commented Feb 27, 2024

This streamlines checking that a statement throws a specific error with a specific description.

Using a macro has the advantage that we get the correct traceback and can use the existing googletest code.

The incorrect description check will also print the diff (like when comparing two strings) if googletest deems it necessary to do so.

Example output for the four cases (line numbers are correct):

../../../../test/unit/parser/parser_design_error_test.cpp:297: Failure
Expected: parser.parse() throws an exception of type sharg::design_error.
  Actual: it throws nothing.

../../../../test/unit/parser/parser_design_error_test.cpp:308: Failure
Expected: parser.add_section("") throws an exception of type sharg::user_input_error.
  Actual: it throws sharg::design_error with description "add_section may only be used before calling parse().".

../../../../test/unit/parser/parser_design_error_test.cpp:311: Failure
parser.add_subsection("") throws the correct exception, but the description is incorrect.
Expected equality of these values:
  Expected
    Which is: "add_subseption may only be used before calling parse()."
  Actual
    Which is: "add_subsection may only be used before calling parse()."

../../../../test/unit/parser/parser_design_error_test.cpp:318: Failure
Expected: throw 42 throws an exception of type sharg::design_error.
  Actual: it throws an unknown exception.

Copy link

vercel bot commented Feb 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
sharg-parser ✅ Ready (Inspect) Visit Preview Feb 27, 2024 3:38pm

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Feb 27, 2024
Copy link

codecov bot commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.13%. Comparing base (64399ce) to head (3295fa5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #245   +/-   ##
=======================================
  Coverage   95.13%   95.13%           
=======================================
  Files          18       18           
  Lines        1728     1728           
=======================================
  Hits         1644     1644           
  Misses         84       84           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@seqan-actions seqan-actions added lint [INTERNAL] signals that clang-format ran and removed lint [INTERNAL] signals that clang-format ran labels Feb 27, 2024
@SGSSGene
Copy link
Contributor

SGSSGene commented Feb 27, 2024

@eseiler
Copy link
Member Author

eseiler commented Feb 28, 2024

Why not using EXPECT_THROW?
https://google.github.io/googletest/reference/assertions.html#EXPECT_THROW

Because it doesn't check the message of the exception. Sometimes you want to check that the correct message is emitted, e. g., design_error is thrown in many places with different messages.

Copy link
Member

Choose a reason for hiding this comment

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

We currently do not have a repo for infrastructure stuff like we have for std stuff right? This is very valuable for seqan3 too

Copy link
Member Author

Choose a reason for hiding this comment

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

I also added it to seqan3, but we don't have a repo for infra stuff

@eseiler eseiler merged commit 01f848e into seqan:main Feb 28, 2024
33 checks passed
@eseiler eseiler deleted the misc/expect_thow_msg branch February 28, 2024 15:41
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

Successfully merging this pull request may close these issues.

4 participants