From: Peter Griess Date: Wed, 9 Oct 2013 08:24:28 +0000 (-0700) Subject: Only run FBString.testConstructionFromLiteralZero under GNU libstdc++ X-Git-Tag: v0.22.0~822 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=60f2c87ddcc00799c9b0a4d42c8d56a259298e54;p=folly.git 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 --- 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) {