(folly) Account for different vsnprintf behavior on OSX in test
authorHans Fugal <fugalh@fb.com>
Thu, 8 Jan 2015 22:55:34 +0000 (14:55 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:05 +0000 (11:01 -0800)
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

folly/test/StringTest.cpp

index 93b0fb6ecb85d26a72f27c4ac536e36037ba9812..7b9f1a4ee059b83fc2bd1aebed1a0c7d3ffa55f1 100644 (file)
@@ -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) {