Skip to content

Commit 4b8b49a

Browse files
add negative test
1 parent 78eca92 commit 4b8b49a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

llvm/unittests/ADT/STLExtrasTest.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,6 @@ TEST(STLExtrasTest, hasSingleElement) {
10171017
}
10181018

10191019
TEST(STLExtrasTest, getSingleElement) {
1020-
// Note: Asserting behavior of getSingleElement cannot be tested because the
1021-
// program would crash.
1022-
10231020
// Test const and non-const containers.
10241021
const std::vector<int> V1 = {7};
10251022
EXPECT_EQ(getSingleElement(V1), 7);
@@ -1043,6 +1040,14 @@ TEST(STLExtrasTest, getSingleElement) {
10431040
some_namespace::some_struct S;
10441041
S.data = V2;
10451042
EXPECT_EQ(getSingleElement(S), 8);
1043+
1044+
// Make sure that we crash on empty or too many elements.
1045+
SmallVector<int> V4;
1046+
EXPECT_DEATH(getSingleElement(V4), "expected container with single element");
1047+
SmallVector<int> V5{12, 13, 14};
1048+
EXPECT_DEATH(getSingleElement(V5), "expected container with single element");
1049+
std::list<int> L2;
1050+
EXPECT_DEATH(getSingleElement(L2), "expected container with single element");
10461051
}
10471052

10481053
TEST(STLExtrasTest, hasNItems) {

0 commit comments

Comments
 (0)