diff options
author | Brian Silverman <bsilver16384@gmail.com> | 2015-09-08 18:56:58 -0400 |
---|---|---|
committer | Brian Silverman <bsilver16384@gmail.com> | 2015-09-08 20:25:48 -0400 |
commit | 133be3dc1f1eb3f3c6252b950e89895469f1193c (patch) | |
tree | cc15b7542cf6decc757fdee3a51b5557b05bcb19 /src/google/protobuf/testing/googletest.cc | |
parent | 0e606bc2eb5258193641d58a1ee7962983b33aa3 (diff) | |
download | protobuf-133be3dc1f1eb3f3c6252b950e89895469f1193c.tar.gz protobuf-133be3dc1f1eb3f3c6252b950e89895469f1193c.tar.bz2 protobuf-133be3dc1f1eb3f3c6252b950e89895469f1193c.zip |
Use TEST_TMPDIR for writing temporary files if it's set.
Bazel expects all tests to do this.
Diffstat (limited to 'src/google/protobuf/testing/googletest.cc')
-rw-r--r-- | src/google/protobuf/testing/googletest.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/google/protobuf/testing/googletest.cc b/src/google/protobuf/testing/googletest.cc index b8bd790b..2b9cddef 100644 --- a/src/google/protobuf/testing/googletest.cc +++ b/src/google/protobuf/testing/googletest.cc @@ -94,6 +94,13 @@ string TestSourceDir() { namespace { string GetTemporaryDirectoryName() { + // Tests run under Bazel "should not" use /tmp. Bazel sets this environment + // variable for tests to use instead. + char *from_environment = getenv("TEST_TMPDIR"); + if (from_environment != NULL && from_environment[0] != '\0') { + return string(from_environment) + "/protobuf_tmpdir"; + } + // tmpnam() is generally not considered safe but we're only using it for // testing. We cannot use tmpfile() or mkstemp() since we're creating a // directory. |