[Bug]: Unordered container matchers ignore result descriptions
- Dominant language
- C++
- Stars
- 39.5k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
### Describe the issue
Consider the following example
```C++
MATCHER(MatchSomething, "")
{
*result_listener << "THIS_SHOULD_APPEAR_SOMEWHERE_IN_THE_OUTPUT";
return false;
}
TEST(Some, Test)
{
std::vector values{{42}};
EXPECT_THAT(values, testing::UnorderedElementsAre(MatchSomething()));
}
```
I would have expected that the string `THIS_SHOULD_APPEAR_SOMEWHERE_IN_THE_OUTPUT` appears somewhere in the output. Instead I get:
```txt
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Some
[ RUN ] Some.Test
/app/example.cpp:13: Failure
Value of: values
Expected: has 1 element and that element match something
Actual: { 42 }, where the following matchers don't match any elements:
matcher #0: match something
and where the following elements don't match any matchers:
element #0: 42
[ FAILED ] Some.Test (0 ms)
[----------] 1 test from Some (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Some.Test
```
See live on [godbolt](https://godbolt.org/z/39j9sTG7j).
Of course in this trivial example this is not an issue. But when considering a more complicated matcher and value, e.g. some classes with various members that I want to match, I would like to see which specific member mismatched. I.e. what exactly in the matcher failed a check. This is usually described via the `result_listener`, but everything I write to it is ignored.
From looking at the code I am guessing that the value written to the `result_listener` always ends up in a `DummyMatchResultListener`, specifically in [this one here](https://github.com/google/googletest/blob/a7f443b80b105f940225332ed3c31f2790092f47/googlemock/include/gmock/gmock-matchers.h#L3664).
Other unordered container matchers show the same behavior.
### Steps to reproduce the problem
Reproduction: [On godbolt](https://godbolt.org/z/39j9sTG7j).
Manually: Take the code
```C++
#include
#include
MATCHER(MatchSomething, "")
{
*result_listener << "THIS_SHOULD_APPEAR_SOMEWHERE_IN_THE_OUTPUT";
return false;
}
TEST(Some, Test)
{
std::vector values{{42}};
EXPECT_THAT(values, testing::UnorderedElementsAre(MatchSomething()));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
```
Expectation: `THIS_SHOULD_APPEAR_SOMEWHERE_IN_THE_OUTPUT` appears somewhere in the test output.
### What version of GoogleTest are you using?
Locally I am using 1.13. Not sure if on godbolt "trunk" really refers to the head of the main branch. Unfortunately, there doesn't seem to be a C-macro available that I could print on godbolt to check.
### What operating system and version are you using?
Windows 10. I don't know what godbolt is using.
### What compiler and version are you using?
The godbolt example uses gcc 13.1.
### What build system are you using?
Manual invocation of gcc.
### Additional context
_No response_
Contributor guide
Research direction
Start in googlemock/include/gmock/gmock-matchers.h, especially the DummyMatchResultListener area linked in the report, and reproduce the failure with the provided UnorderedElementsAre example. Trace where matcher result descriptions are discarded, then verify that the custom listener text appears in the failing test output without changing unrelated unordered-container behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100