Better source locations for EXPECT_CALL failures #54129
Open
+321
−35
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Changelog: [Internal]
The team maintaining gmock is uninterested, as a matter of principle, in improving the ergonomics of writing helper functions around
EXPECT_CALL
. However, such helpers have proven very useful for thejsinspector-modern
C++ test suite. The out-of-the-box ergonomics are pretty bad, though, so this diff tries to improve the situation.The biggest offender in our test suite is the
expectMessageFromPage
helper function - if a test fails because an expectation isn't met, the error message points to theEXPECT_CALL
line insideexpectMessageFromPage
, which is utterly useless compared to the line of test code that calledexpectMessageFromPage
.Here, we reach into gmock's internals slightly to create a variant of the
EXPECT_CALL
macro that allows passing in astd::source_location
(thanks, C++20!). We then teachexpectMessageFromPage
and other such helpers to capture a source location at the call site (using a parameter with a default value tosource_location::current()
) and use the modified macro to pass it into gmock.Differential Revision: D84368993