Skip to content

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

Description

@kenoss

Does the feature exist in the most recent commit?

I guess yes (version that is used in chromium).

Why do we need this feature?

For daily chromium development.

Describe the proposal.

Motivation

I think that the current output of EXPECT_THAT of (Unordered)ElementsAreArray is not human/AI readable. We can improve it.

Example

Code: Something like https://source.chromium.org/chromium/chromium/src/+/main:content/browser/preloading/prerender/prerender_browsertest.cc;l=8357;drc=02e3f72738b5ad02e8f30ab40ea1467550a91f2c

Result:

../../content/browser/preloading/prerender/prerender_browsertest.cc:8988: Failure
Value of: prerender_entries
Expected: has 4 elements where
element #0 is equal to Entry{source=65 AccurateTriggering=1 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=5 },
element #1 is equal to Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=4 },
element #2 is equal to Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=186 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=6 },
element #3 is equal to Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }
  Actual: { Entry{source=65 AccurateTriggering=1 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=5 }, Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }, Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=9 }, Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=9 } }, whose element #1 (Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }) isn't equal to Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=4 }

It's not readable for me. What I'm currently doing is:

  1. Find "whose element ASSERT_STRCASEEQ and ASSERT_STRCASENE macros should compare strings consistently across platforms #1".
  2. Copy the line.
  3. Paste to an editor.
  4. Edit
  5. Eye diff

Editted result:

whose element #1 (
Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }
) isn't equal to 
Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=4 }

Then, I got Diff: prerender_entries[1], ReadyTime=1247, TriggeringOutcome=3/4.

Sometimes I ask to an AI to visualize the diff.

This work is in most-inner loop of iteration. It's OK for oneshot, but I need to do it for every edit and compile.

Possible solutions

I prefer

  • Human/AI readable output.
  • Structural output rather than natural english.

Imporved output:

../../content/browser/preloading/prerender/prerender_browsertest.cc:8988: Failure
Value of: prerender_entries
Expected: With `ElementsAreArray`
  - Entry{source=65 AccurateTriggering=1 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=5 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=4 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=186 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=6 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }
Actual:
  - Entry{source=65 AccurateTriggering=1 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=5 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=9 },
  - Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=9 } }
Note that the expected element #1 isn't equal to the actual one.
  - Expected #1: Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=3 }
  - Actual   #1: Entry{source=65 AccurateTriggering=0 Eligibility=1 FailureReason=0 HoldbackStatus=1 PreloadingPredictor=50 PreloadingType=4 ReadyTime=1247 SpeculationEagerness=2 TimeToNextNavigation=1247 TriggeringOutcome=4 }

Points:

  1. Comparison using LHS/RHS.
  2. Same indentation and format for LHS/RHS.
  3. Say the conclusion first and avoid embedding parameters. (Note that the expected element #1 isn'st equal to the actual one.\n - {lhs}\n - {rhs} rather than Actual {actual}, whose element #1 ({rhs}) isn't equal to {lhs}. Note also that the natural English version reverts the order as actual/expected, which is avoided in gtest.)

WDYT?

Is the feature specific to an operating system, compiler, or build system version?

No.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions