From 60f2c87ddcc00799c9b0a4d42c8d56a259298e54 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Wed, 9 Oct 2013 01:24:28 -0700 Subject: [PATCH] Only run FBString.testConstructionFromLiteralZero under GNU libstdc++ Summary: - This test verifies the behavior of std::string(0), which the GNU library expects to throw an std::logic_error. Other libraries may have other behaviors; libc++ segfaults. Test Plan: - fbconfig -r folly && fbmake runtests - ./configure && make check on Ubuntu/FC/Mac Reviewed By: simpkins@fb.com FB internal diff: D1003125 --- folly/test/FBStringTest.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/folly/test/FBStringTest.cpp b/folly/test/FBStringTest.cpp index ddc8a646..6cd5d1fa 100644 --- a/folly/test/FBStringTest.cpp +++ b/folly/test/FBStringTest.cpp @@ -1082,22 +1082,14 @@ TEST(FBString, testMoveOperatorPlusRhs) { EXPECT_EQ(size1 + size2, test.size()); } +// The GNU C++ standard library throws an std::logic_error when an std::string +// is constructed with a null pointer. Verify that we mirror this behavior. +// +// N.B. We behave this way even if the C++ library being used is something +// other than libstdc++. Someday if we deem it important to present +// identical undefined behavior for other platforms, we can re-visit this. TEST(FBString, testConstructionFromLiteralZero) { - try { - std::string s(0); - EXPECT_TRUE(false); - } catch (const std::logic_error&) { - } catch (...) { - EXPECT_TRUE(false); - } - - try { - fbstring s(0); - EXPECT_TRUE(false); - } catch (const std::logic_error& e) { - } catch (...) { - EXPECT_TRUE(false); - } + EXPECT_THROW(fbstring s(0), std::logic_error); } TEST(FBString, testFixedBugs) { -- 2.34.1