Skip to content

Commit

Permalink
[ADT] Fix tests for StringMap::at and DenseMap::at
Browse files Browse the repository at this point in the history
These methods won't assert for release build.
  • Loading branch information
StrongerXi committed Feb 17, 2023
1 parent 42944ab commit be83a4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 8 additions & 7 deletions llvm/unittests/ADT/DenseMapTest.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions llvm/unittests/ADT/StringMapTest.cpp
Expand Up @@ -205,20 +205,16 @@ 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;
Map["c"] = 3;
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.
Expand Down

0 comments on commit be83a4b

Please sign in to comment.