aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/DenseMapTest.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2023-06-28 01:13:52 +0200
committerSam McCall <sam.mccall@gmail.com>2023-06-28 11:29:52 +0200
commitfe8a168161a3b4c1bbd2d8d916c510cfe4711cbd (patch)
treee933e6fba975fc4c81d1e1126d917517a3346fe5 /llvm/unittests/ADT/DenseMapTest.cpp
parent7049393a5865cec0a2ba6aa7ec460ec7ed1398df (diff)
downloadllvm-fe8a168161a3b4c1bbd2d8d916c510cfe4711cbd.zip
llvm-fe8a168161a3b4c1bbd2d8d916c510cfe4711cbd.tar.gz
llvm-fe8a168161a3b4c1bbd2d8d916c510cfe4711cbd.tar.bz2
[unittest] teach gTest to print entries of DenseMap as pairs
When an assertion like the following fails: EXPECT_THAT(map, ElementsAre(Pair("p", "nullable")))); Error message before: Actual: { 40-byte object <E8-A5 9C-7F 25-37 00-00 58-7E 51-51 D0-7F 00-00 00-00 00-00 00-00 00-00 01-00 00-00 00-00 00-00 00-DA C7-7F 25-37 00-00> } After: Actual: { ("p", "nonnull") } It is not ideal that we need to refer directly to DenseMapPair inside the internal namespace, but I believe the practical maintenance risk is low. This change is covered by DenseMap's unittests, as we've covered SmallString etc in the past. Differential Revision: https://reviews.llvm.org/D153930
Diffstat (limited to 'llvm/unittests/ADT/DenseMapTest.cpp')
-rw-r--r--llvm/unittests/ADT/DenseMapTest.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp
index 94764a8..cc32445 100644
--- a/llvm/unittests/ADT/DenseMapTest.cpp
+++ b/llvm/unittests/ADT/DenseMapTest.cpp
@@ -9,6 +9,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/DenseMapInfoVariant.h"
+#include "llvm/ADT/StringRef.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <map>
@@ -756,4 +757,12 @@ TEST(DenseMapCustomTest, VariantSupport) {
// operator==.
EXPECT_FALSE(DenseMapInfo<variant>::isEqual(Keys[2], Keys[2]));
}
+
+// Test that gTest prints map entries as pairs instead of opaque objects.
+// See third-party/unittest/googletest/internal/custom/gtest-printers.h
+TEST(DenseMapCustomTest, PairPrinting) {
+ DenseMap<int, StringRef> Map = {{1, "one"}, {2, "two"}};
+ EXPECT_EQ(R"({ (1, "one"), (2, "two") })", ::testing::PrintToString(Map));
+}
+
} // namespace