[llvm] be83a4b - [ADT] Fix tests for `StringMap::at` and `DenseMap::at`
Ryan Guo via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 17 10:07:25 PST 2023
Author: Ryan Guo
Date: 2023-02-17T10:07:01-08:00
New Revision: be83a4b257c8f0dfd74a659261a544483c5df9af
URL: https://github.com/llvm/llvm-project/commit/be83a4b257c8f0dfd74a659261a544483c5df9af
DIFF: https://github.com/llvm/llvm-project/commit/be83a4b257c8f0dfd74a659261a544483c5df9af.diff
LOG: [ADT] Fix tests for `StringMap::at` and `DenseMap::at`
These methods won't assert for release build.
Added:
Modified:
llvm/unittests/ADT/DenseMapTest.cpp
llvm/unittests/ADT/StringMapTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp
index ba4e76424f04f..69bf4e19e4eea 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 25562d366c425..431b3973d6d6c 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<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.
More information about the llvm-commits
mailing list