From 2387d7d25536f87330cd62d3d53febd70514ffe8 Mon Sep 17 00:00:00 2001 From: Daniel Andersson Date: Tue, 2 Apr 2019 16:37:37 -0700 Subject: [PATCH] Make it possible to run JSBigString tests Summary: Add a target for JSBigString tests that can be run with a normal `buck test` invocation. Also fix an issue in the test when `getenv` returns null by defaulting to `/tmp`. Reviewed By: ridiculousfish Differential Revision: D14716270 fbshipit-source-id: f2eb6d3aab93c32a4b41f5786aedd04a70468d75 --- ReactCommon/cxxreact/tests/BUCK | 14 ++++++++++++++ ReactCommon/cxxreact/tests/jsbigstring.cpp | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ReactCommon/cxxreact/tests/BUCK b/ReactCommon/cxxreact/tests/BUCK index e9ae81aa21a..b123414e910 100644 --- a/ReactCommon/cxxreact/tests/BUCK +++ b/ReactCommon/cxxreact/tests/BUCK @@ -55,3 +55,17 @@ fb_xplat_cxx_test( react_native_xplat_target("cxxreact:jsbigstring"), ], ) + +fb_xplat_cxx_test( + name = "jsbigstring_test", + srcs = ["jsbigstring.cpp"], + compiler_flags = [ + "-fexceptions", + "-frtti", + ], + deps = [ + "fbsource//xplat/folly:molly", + "fbsource//xplat/third-party/gmock:gtest", + react_native_xplat_target("cxxreact:jsbigstring"), + ], +) diff --git a/ReactCommon/cxxreact/tests/jsbigstring.cpp b/ReactCommon/cxxreact/tests/jsbigstring.cpp index 69e265c96f0..a8f58f16646 100644 --- a/ReactCommon/cxxreact/tests/jsbigstring.cpp +++ b/ReactCommon/cxxreact/tests/jsbigstring.cpp @@ -15,7 +15,10 @@ using namespace facebook::react; namespace { int tempFileFromString(std::string contents) { - std::string tmp {getenv("TMPDIR")}; + const char *tmpDir = getenv("TMPDIR"); + if (tmpDir == nullptr) + tmpDir = "/tmp"; + std::string tmp {tmpDir}; tmp += "/temp.XXXXXX"; std::vector tmpBuf {tmp.begin(), tmp.end()};