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

MatcherBase::match() runs before EventListenerBase::assertionStarting() #2678

Closed
vberlier opened this issue Apr 20, 2023 · 3 comments
Closed
Labels

Comments

@vberlier
Copy link

Describe the bug
The docs say that assertionStarting is called after the expression is captured, but before the assertion expression is evaluated. For custom matchers the match member function is in charge of evaluating the assertion expression, but by the time the assertionStarting event is dispatched match has already been invoked.

Expected behavior
assertionStarting should run before custom matchers.

Reproduction steps

class DummyCatchListener : public Catch::EventListenerBase {
public:
    using Catch::EventListenerBase::EventListenerBase;

    void assertionStarting(Catch::AssertionInfo const& assertionInfo) override {
        std::cout << assertionInfo.lineInfo.file << ":" << assertionInfo.lineInfo.line << std::endl;
    }
};

CATCH_REGISTER_LISTENER(DummyCatchListener)

class DummyMatcher : public Catch::Matchers::MatcherBase<int> {
public:
    bool match(int const& in) const override {
        std::cout << "match " << in << std::endl;
        return true;
    }
};

TEST_CASE("Dummy") {
    CHECK_THAT(123, DummyMatcher{});
}
match 123
path/to/dummy_test.cpp:42

Additional context
I'm trying to use a listener to update global variables to be able to access the current assertion file and line in a custom matcher. If there's another way to do it let me know :)

@horenmar
Copy link
Member

That's definitely not the intended behaviour, I'll have to check how hard it will be to fix.

@horenmar
Copy link
Member

horenmar commented May 1, 2023

Okay, so it might be a larger surgery. The basic assertions currently behave in the same way, and I would have to ensure that the proper information is wired around before the expression is evaluated.

@horenmar horenmar added the Bug label May 1, 2023
@vberlier
Copy link
Author

vberlier commented May 6, 2023

Thanks for the fix! Have a good day :)

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

No branches or pull requests

2 participants