aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp/util/file_test.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-07-25 09:24:56 +0200
committerGravatar Jakob Buchgraber <buchgr@google.com>2017-07-25 13:17:46 +0200
commitea23c2b762adec6625f35ea737d0cf63daf6038d (patch)
tree5bd9963eb65bd139e7e159f713438555a6609b9d /src/test/cpp/util/file_test.cc
parentf929b1a174b535ad6e42bf908879996b77060c31 (diff)
Bazel client: add blaze_util::IsDevNull
Add a method to test if a path is /dev/null (or case-insensitive "NUL" on Windows), and use it in blaze::MakeAbsolute. In this commit: - implement blaze_util::IsDevNull with POSIX and Windows semantics + add tests - blaze::MakeAbsolute calls blaze::ConvertPath on its input to convert MSYS paths on Windows - blaze_util::GetCwdW (thus GetCwd) always returns a lowercase path so that it is deterministic - blaze_util::GetCurrentDrive returns lowercase letter to be consisent with blaze::ConvertPath, which also returns a lowercase path Fixes https://github.com/bazelbuild/bazel/issues/3440 Change-Id: I3af5ba0a033d542fe64a676d67f27472298d1089 PiperOrigin-RevId: 163038503
Diffstat (limited to 'src/test/cpp/util/file_test.cc')
-rw-r--r--src/test/cpp/util/file_test.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/test/cpp/util/file_test.cc b/src/test/cpp/util/file_test.cc
index ab943a7bf9..21b0afca51 100644
--- a/src/test/cpp/util/file_test.cc
+++ b/src/test/cpp/util/file_test.cc
@@ -206,7 +206,7 @@ class CollectingDirectoryEntryConsumer : public DirectoryEntryConsumer {
void Consume(const string& name, bool is_directory) override {
// Strip the path prefix up to the `rootname` to ease testing on all
// platforms.
- int index = name.rfind(rootname);
+ size_t index = name.rfind(rootname);
string key = (index == string::npos) ? name : name.substr(index);
// Replace backslashes with forward slashes (necessary on Windows only).
std::replace(key.begin(), key.end(), '\\', '/');
@@ -248,4 +248,13 @@ TEST(FileTest, ForEachDirectoryEntryTest) {
ASSERT_EQ(consumer.entries, expected);
}
+TEST(FileTest, IsDevNullTest) {
+ ASSERT_TRUE(IsDevNull("/dev/null"));
+ ASSERT_FALSE(IsDevNull("dev/null"));
+ ASSERT_FALSE(IsDevNull("/dev/nul"));
+ ASSERT_FALSE(IsDevNull("/dev/nulll"));
+ ASSERT_FALSE(IsDevNull(NULL));
+ ASSERT_FALSE(IsDevNull(""));
+}
+
} // namespace blaze_util