[ADT] Fix tests for `StringMap::at` and `DenseMap::at`
authorRyan Guo <ryanguo@modular.com>
Fri, 17 Feb 2023 17:07:35 +0000 (09:07 -0800)
committerRyan Guo <ryanguo@modular.com>
Fri, 17 Feb 2023 18:07:01 +0000 (10:07 -0800)
These methods won't assert for release build.

llvm/unittests/ADT/DenseMapTest.cpp
llvm/unittests/ADT/StringMapTest.cpp

index ba4e764..69bf4e1 100644 (file)
@@ -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
index 25562d3..431b397 100644 (file)
@@ -205,12 +205,9 @@ TEST_F(StringMapTest, CopyCtorTest) {
   EXPECT_EQ(5, Map2.lookup("funf"));
 }
 
-TEST_F(StringMapTest, LookupOrTrapTest) {
+TEST_F(StringMapTest, AtTest) {
   llvm::StringMap<int> 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.