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

REQUIRE_THROWS_MESSAGE not checking message correctly #150

Closed
martinfinke opened this issue Sep 7, 2018 · 4 comments
Closed

REQUIRE_THROWS_MESSAGE not checking message correctly #150

martinfinke opened this issue Sep 7, 2018 · 4 comments

Comments

@martinfinke
Copy link

martinfinke commented Sep 7, 2018

Description

REQUIRE_THROWS_MESSAGE only checks if an exception was thrown, and doesn't check if the exception had the expected message.

[EDIT] I understand that the macro doesn't do what I thought. There doesn't seem to be documentation on it, and the name is IMO misleading. I would except that the message has to match the exception's what(). Is there a macro like this in doctest?

Steps to reproduce

TEST_CASE("REQUIRE_THROWS_MESSAGE")
{
    SUBCASE("Checks whether the message is correct")
    {
        auto throwException = [] {
            throw std::runtime_error("Some Message");
        };

        // This passes
        REQUIRE_THROWS_MESSAGE(throwException(), "Something else");
    }
}

Extra information

  • doctest version: 2.0.0
  • Operating System: macOS 10.13.6
  • Compiler+version: Xcode 9.4.1
@onqtam
Copy link
Member

onqtam commented Sep 13, 2018

Hi!

Perhaps I should improve the documentation...

As for checking the message of an exception - that is in the roadmap - there is even an open issue for it.

This might get into version 2.1 but that wouldn’t be anytime soon.

@martinfinke
Copy link
Author

Ok, got it! Thanks for clearing that up.

@onqtam
Copy link
Member

onqtam commented Dec 10, 2018

In the recently released version 2.1 (latest is 2.2) I added the CHECK_THROWS_WITH(expr, exception_string) macro - changelog, docs

@martinfinke
Copy link
Author

Thanks!

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

2 participants