Skip to content

Improve ElementsAreArray mismatch explanations for readability #4934#4976

Open
ShrutiPundir17 wants to merge 4 commits into
google:mainfrom
ShrutiPundir17:improve-elementsarearray-failure-output
Open

Improve ElementsAreArray mismatch explanations for readability #4934#4976
ShrutiPundir17 wants to merge 4 commits into
google:mainfrom
ShrutiPundir17:improve-elementsarearray-failure-output

Conversation

@ShrutiPundir17
Copy link
Copy Markdown

@ShrutiPundir17 ShrutiPundir17 commented May 10, 2026

Fixes #4934

Summary

This change improves failure diagnostics for ElementsAre* and UnorderedElementsAre* matchers by making explanations more structured and easier to scan during debugging loops.

What changed

  • Updated ElementsAreMatcherImpl mismatch explanations to be more explicit:
    • size mismatch now reports:
      • expected size
      • actual size
    • element mismatch now reports:
      • mismatch index
      • actual value
      • expected matcher description
      • detail line from matcher negation/explanation
  • Updated successful non-trivial match explanation wording to a cleaner element #N matches: ... form.
  • Updated unordered matcher explanations to consistently use Expected vs Actual terminology:
    • unmatched expected entries are listed as Expected #...
    • unmatched actual entries are listed as Actual #...
    • pairing diagnostics now print as Actual #X <-> Expected #Y
  • Updated affected expectation strings in container matcher tests accordingly.

Why

Current output for (Unordered)ElementsAreArray failures can be difficult to parse quickly, especially with large struct payloads.
This change prioritizes:

  • faster visual diffing
  • consistent LHS/RHS terminology
  • clearer first-line diagnosis before details

Scope

Only diagnostic message formatting and corresponding tests were changed.
Matching semantics and matcher algorithms are unchanged.

Files touched

  • googlemock/include/gmock/gmock-matchers.h
  • googlemock/src/gmock-matchers.cc
  • googlemock/test/gmock-matchers-containers_test.cc

Use structured Expected/Actual-oriented diagnostics for ElementsAre and UnorderedElementsAre failures, and update matcher container tests to assert the new clearer output format.
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 10, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

siddh and others added 3 commits May 10, 2026 23:06
Add a short comment documenting why unordered pairing diagnostics print in Actual/Expected order.
Drop the follow-up comment added for CLA retrigger so the PR includes only necessary matcher output changes.
@ShrutiPundir17 ShrutiPundir17 changed the title Improve ElementsAreArray mismatch explanations for readability Improve ElementsAreArray mismatch explanations for readability #4934 May 11, 2026
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.

[FR]: Making EXPECT_THAT of (Unordered)ElementsAreArray human/AI readable

2 participants