From be83a4b257c8f0dfd74a659261a544483c5df9af Mon Sep 17 00:00:00 2001 From: Ryan Guo Date: Fri, 17 Feb 2023 09:07:35 -0800 Subject: [PATCH] [ADT] Fix tests for `StringMap::at` and `DenseMap::at` These methods won't assert for release build. --- llvm/unittests/ADT/DenseMapTest.cpp | 15 ++++++++------- llvm/unittests/ADT/StringMapTest.cpp | 6 +----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp index ba4e764..69bf4e1 100644 --- a/llvm/unittests/ADT/DenseMapTest.cpp +++ b/llvm/unittests/ADT/DenseMapTest.cpp @@ -125,10 +125,6 @@ TYPED_TEST(DenseMapTest, EmptyIntMapTest) { EXPECT_TRUE(this->Map.find(this->getKey()) == this->Map.end()); EXPECT_EQ(typename TypeParam::mapped_type(), this->Map.lookup(this->getKey())); - - // LookupOrTrap tests - EXPECT_DEATH({ this->Map.at(this->getKey()); }, - "DenseMap::at failed due to a missing key"); } // Constant map tests @@ -160,10 +156,15 @@ TYPED_TEST(DenseMapTest, SingleEntryMapTest) { EXPECT_TRUE(this->Map.find(this->getKey()) == this->Map.begin()); EXPECT_EQ(this->getValue(), this->Map.lookup(this->getKey())); EXPECT_EQ(this->getValue(), this->Map[this->getKey()]); +} - // LookupOrTrap tests - EXPECT_DEATH({ this->Map.at(this->getKey(1)); }, - "DenseMap::at failed due to a missing key"); +TYPED_TEST(DenseMapTest, AtTest) { + this->Map[this->getKey(0)] = this->getValue(0); + this->Map[this->getKey(1)] = this->getValue(1); + this->Map[this->getKey(2)] = this->getValue(2); + EXPECT_EQ(this->getValue(0), this->Map.at(this->getKey(0))); + EXPECT_EQ(this->getValue(1), this->Map.at(this->getKey(1))); + EXPECT_EQ(this->getValue(2), this->Map.at(this->getKey(2))); } // Test clear() method diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index 25562d3..431b397 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -205,12 +205,9 @@ TEST_F(StringMapTest, CopyCtorTest) { EXPECT_EQ(5, Map2.lookup("funf")); } -TEST_F(StringMapTest, LookupOrTrapTest) { +TEST_F(StringMapTest, AtTest) { llvm::StringMap Map; - // key not found on empty map - EXPECT_DEATH({ Map.at("a"); }, "StringMap::at failed due to a missing key"); - // keys both found and not found on non-empty map Map["a"] = 1; Map["b"] = 2; @@ -218,7 +215,6 @@ TEST_F(StringMapTest, LookupOrTrapTest) { EXPECT_EQ(1, Map.at("a")); EXPECT_EQ(2, Map.at("b")); EXPECT_EQ(3, Map.at("c")); - EXPECT_DEATH({ Map.at("d"); }, "StringMap::at failed due to a missing key"); } // A more complex iteration test. -- 2.7.4