File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -1017,9 +1017,6 @@ TEST(STLExtrasTest, hasSingleElement) {
10171017}
10181018
10191019TEST (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
10481053TEST (STLExtrasTest, hasNItems) {
You can’t perform that action at this time.
0 commit comments