From: Hans Fugal Date: Thu, 8 Jan 2015 22:55:34 +0000 (-0800) Subject: (folly) Account for different vsnprintf behavior on OSX in test X-Git-Tag: v0.22.0~11 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7f0c4bda69ff762d7d611cf95ba1153b5f1e446b;p=folly.git (folly) Account for different vsnprintf behavior on OSX in test Summary: Apparently there is some dispute about the correct thing for `snprintf(buf, len, "bogus%", "foo")` to return. OSX says 5, Linux says -1. The code in `folly/String.cpp` depends on -1 to throw the exception this test was expecting. Test Plan: make check on OSX Reviewed By: chip@fb.com Subscribers: exa, folly-diffs@ FB internal diff: D1770970 Tasks: 5936226 Signature: t1:1770970:1420680750:bafae2aa8327a52013e68af64a163323244ca03b --- diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index 93b0fb6e..7b9f1a4e 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -99,8 +99,13 @@ void vprintfError(const char* fmt, ...) { va_end(ap); }; + // OSX's sprintf family does not return a negative number on a bad format + // string, but Linux does. It's unclear to me which behavior is more + // correct. +#if !__APPLE__ EXPECT_THROW({stringVPrintf(fmt, ap);}, std::runtime_error); +#endif } TEST(StringPrintf, VPrintf) {