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
This commit is contained in:
Daniel Andersson
2019-04-02 16:37:37 -07:00
committed by Facebook Github Bot
parent 17dbf98884
commit 2387d7d255
2 changed files with 18 additions and 1 deletions

View File

@@ -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"),
],
)

View File

@@ -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<char> tmpBuf {tmp.begin(), tmp.end()};