Commit a0dca4df authored by Andreas Schuh's avatar Andreas Schuh

Create temporary directory for unit tests in specified --test_tmpdir if possible.

parent eeb4db32
...@@ -237,23 +237,36 @@ class Test {}; ...@@ -237,23 +237,36 @@ class Test {};
#if defined(__MINGW32__) #if defined(__MINGW32__)
#include <io.h> #include <io.h>
inline void MakeTmpdir(std::string* path) { inline void MakeTmpdir(std::string* path) {
if (!path->empty()) {
path->append("/gflags_unittest_testdir");
int err = mkdir(path->c_str());
if (err == 0 || errno == EEXIST) return;
}
// I had trouble creating a directory in /tmp from mingw // I had trouble creating a directory in /tmp from mingw
*path = "./gflags_unittest_testdir"; *path = "./gflags_unittest";
mkdir(path->c_str()); // mingw has a weird one-arg mkdir mkdir(path->c_str());
} }
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#include <direct.h> #include <direct.h>
inline void MakeTmpdir(std::string* path) { inline void MakeTmpdir(std::string* path) {
if (!path->empty()) {
int err = _mkdir(path->c_str());
if (err == 0 || errno == EEXIST) return;
}
char tmppath_buffer[1024]; char tmppath_buffer[1024];
int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer); int tmppath_len = GetTempPathA(sizeof(tmppath_buffer), tmppath_buffer);
assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer)); assert(tmppath_len > 0 && tmppath_len < sizeof(tmppath_buffer));
assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it assert(tmppath_buffer[tmppath_len - 1] == '\\'); // API guarantees it
*path = std::string(tmppath_buffer) + "gflags_unittest_testdir"; *path = std::string(tmppath_buffer) + "gflags_unittest";
_mkdir(path->c_str()); _mkdir(path->c_str());
} }
#else #else
inline void MakeTmpdir(std::string* path) { inline void MakeTmpdir(std::string* path) {
mkdir(path->c_str(), 0755); if (!path->empty()) {
int err = mkdir(path->c_str(), 0755);
if (err == 0 || errno == EEXIST) return;
}
mkdir("/tmp/gflags_unittest", 0755);
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment