Skip to content

Commit

Permalink
Print hash expansions in the hash_testing error messages.
Browse files Browse the repository at this point in the history
I find that this makes it much easier to understand the problems.

Example error without this change:
Hash expansion of #0(24-byte object <00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00>) is a suffix of the hash expansion of #1(24-byte object <00-CB E3-BF FB-12 00-00 F0-FF BE-9D FD-7F 00-00 B8-0D 04-1C 59-7F 00-00>).

Example error with this change:
Hash expansion of #0(24-byte object <00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00>);[

0x0000:  0000 0000 0000 0000
] is a suffix of the hash expansion of #1(24-byte object <00-EC E3-FF F8-31 00-00 50-10 90-94 FF-7F 00-00 40-98 E8-33 5E-7F 00-00>);[

0x0000:  2ebc 2196 d3ab 37da

0x0000:  0000 0000

0x0000:  0000 0000 0000 0000
].
PiperOrigin-RevId: 708356078
Change-Id: Iab9060d70eeb051c5a28786e4542f49629165ce0
  • Loading branch information
ezbr authored and copybara-github committed Dec 20, 2024
1 parent 63c03fe commit a54f802
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions absl/hash/hash_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals) {
if (v.expand() != expected) {
return testing::AssertionFailure()
<< "Values " << c[0].ToString() << " and " << v.ToString()
<< " evaluate as equal but have an unequal hash expansion.";
<< " evaluate as equal but have unequal hash expansions ("
<< expected << " vs. " << v.expand() << ").";
}
}

Expand All @@ -256,17 +257,18 @@ VerifyTypeImplementsAbslHashCorrectly(const Container& values, Eq equals) {
case SpyHashState::CompareResult::kEqual:
return testing::AssertionFailure()
<< "Values " << c[0].ToString() << " and " << c2[0].ToString()
<< " evaluate as unequal but have an equal hash expansion.";
<< " evaluate as unequal but have an equal hash expansion:"
<< c2_hash << ".";
case SpyHashState::CompareResult::kBSuffixA:
return testing::AssertionFailure()
<< "Hash expansion of " << c2[0].ToString()
<< "Hash expansion of " << c2[0].ToString() << ";" << c2_hash
<< " is a suffix of the hash expansion of " << c[0].ToString()
<< ".";
<< ";" << expected << ".";
case SpyHashState::CompareResult::kASuffixB:
return testing::AssertionFailure()
<< "Hash expansion of " << c[0].ToString()
<< " is a suffix of the hash expansion of " << c2[0].ToString()
<< ".";
<< "Hash expansion of " << c[0].ToString() << ";"
<< expected << " is a suffix of the hash expansion of "
<< c2[0].ToString() << ";" << c2_hash << ".";
case SpyHashState::CompareResult::kUnequal:
break;
}
Expand Down

0 comments on commit a54f802

Please sign in to comment.