Switch from tmpdir to TemporaryDirectory
authorMichael Lee <mzlee@fb.com>
Sat, 5 Mar 2016 00:06:40 +0000 (16:06 -0800)
committerFacebook Github Bot 0 <facebook-github-bot-0-bot@fb.com>
Sat, 5 Mar 2016 00:20:24 +0000 (16:20 -0800)
Summary: tmpdir does not work on all platforms. TemporaryDirectory is more robust.

Reviewed By: yfeldblum

Differential Revision: D3013866

fb-gh-sync-id: 51e2b7ec2348eb95b99c125a27bb2aca2b87ac21
shipit-source-id: 51e2b7ec2348eb95b99c125a27bb2aca2b87ac21

folly/test/ExceptionTest.cpp

index 49232faad1294b1c75e5fa5e0d45e5c6f2037dbc..30a70da0d646e206b6fd29f470d59465bc71246f 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <folly/Exception.h>
 
+#include <folly/experimental/TestUtil.h>
+
 #include <cstdio>
 #include <memory>
 
@@ -72,15 +74,18 @@ TEST(ExceptionTest, Simple) {
   EXPECT_SYSTEM_ERROR({checkUnixErrorExplicit(-1, EIO, "hello", " world");},
                       EIO, "hello world");
 
-  std::shared_ptr<FILE> fp(tmpfile(), fclose);
+  TemporaryDirectory tmpdir;
+  auto exnpath = tmpdir.path() / "ExceptionTest";
+  auto fp = fopen(exnpath.c_str(), "w+b");
   ASSERT_TRUE(fp != nullptr);
+  SCOPE_EXIT { fclose(fp); };
 
-  EXPECT_NO_THROW({checkFopenError(fp.get(), "hello", " world");});
+  EXPECT_NO_THROW({ checkFopenError(fp, "hello", " world"); });
   errno = ERANGE;
   EXPECT_SYSTEM_ERROR({checkFopenError(nullptr, "hello", " world");},
                       ERANGE, "hello world");
 
-  EXPECT_NO_THROW({checkFopenErrorExplicit(fp.get(), EIO, "hello", " world");});
+  EXPECT_NO_THROW({ checkFopenErrorExplicit(fp, EIO, "hello", " world"); });
   errno = ERANGE;
   EXPECT_SYSTEM_ERROR({checkFopenErrorExplicit(nullptr, EIO,
                                                "hello", " world");},