Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ runfiles library test: cut unwanted dependency #8864

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tools/cpp/runfiles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ cc_test(
visibility = ["//visibility:public"],
deps = [
":runfiles",
"//src/main/cpp/util:filesystem",
"@com_google_googletest//:gtest_main",
],
)
Expand Down
24 changes: 13 additions & 11 deletions tools/cpp/runfiles/runfiles_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <vector>

#include "gtest/gtest.h"
#include "src/main/cpp/util/file.h"
#include "src/main/cpp/util/path.h"

#define RUNFILES_TEST_TOSTRING_HELPER(x) #x
#define RUNFILES_TEST_TOSTRING(x) RUNFILES_TEST_TOSTRING_HELPER(x)
Expand Down Expand Up @@ -99,14 +97,14 @@ string RunfilesTest::GetTemp() {
#ifdef _WIN32
DWORD size = ::GetEnvironmentVariableA("TEST_TMPDIR", NULL, 0);
if (size == 0) {
return std::move(string()); // unset or empty envvar
return string(); // unset or empty envvar
}
unique_ptr<char[]> value(new char[size]);
::GetEnvironmentVariableA("TEST_TMPDIR", value.get(), size);
return std::move(string(value.get()));
return value.get();
#else
char* result = getenv("TEST_TMPDIR");
return result != NULL ? std::move(string(result)) : std::move(string());
return result != NULL ? string(result) : string();
#endif
}

Expand All @@ -122,18 +120,22 @@ RunfilesTest::MockFile* RunfilesTest::MockFile::Create(
return nullptr;
}

string tmp(std::move(RunfilesTest::GetTemp()));
string tmp(RunfilesTest::GetTemp());
if (tmp.empty()) {
cerr << "WARNING: " << __FILE__ << "(" << __LINE__
<< "): $TEST_TMPDIR is empty" << endl;
return nullptr;
}
string path(tmp + "/" + name);
string dirname = blaze_util::Dirname(path);
if (!blaze_util::MakeDirectories(dirname, 0777)) {
cerr << "WARNING: " << __FILE__ << "(" << __LINE__ << "): MakeDirectories("
<< dirname << ") failed" << endl;
return nullptr;

string::size_type i = 0;
while ((i = name.find_first_of("/\\", i + 1)) != string::npos) {
string d = tmp + "\\" + name.substr(0, i);
if (!CreateDirectoryA(d.c_str(), NULL)) {
cerr << "ERROR: " << __FILE__ << "(" << __LINE__
<< "): failed to create directory \"" << d << "\"" << endl;
return nullptr;
}
}

auto stm = std::ofstream(path);
Expand Down