diff options
author | Laszlo Csomor <laszlocsomor@google.com> | 2017-03-06 12:03:12 +0000 |
---|---|---|
committer | Vladimir Moskva <vladmos@google.com> | 2017-03-06 14:44:13 +0000 |
commit | 2b01b5dd950bbd078a61f3451a5eb0383ea8f270 (patch) | |
tree | 24e769dca3e91db5493e0b9f71c7d53519c3ca8e /src/test | |
parent | bfd9aa359addb582b4f29e54ab09fc350e927e31 (diff) |
Bazel client, Windows: fix AsShortWindowsPath
This method now works for non-existent paths too.
See https://github.com/bazelbuild/bazel/issues/2107
--
PiperOrigin-RevId: 149284633
MOS_MIGRATED_REVID=149284633
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/cpp/util/file_windows_test.cc | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/test/cpp/util/file_windows_test.cc b/src/test/cpp/util/file_windows_test.cc index 83600637de..53116f8076 100644 --- a/src/test/cpp/util/file_windows_test.cc +++ b/src/test/cpp/util/file_windows_test.cc @@ -243,6 +243,19 @@ TEST_F(FileWindowsTest, TestAsShortWindowsPath) { ASSERT_TRUE(AsShortWindowsPath("nul", &actual)); ASSERT_EQ(string("NUL"), actual); + ASSERT_TRUE(AsShortWindowsPath("C://", &actual)); + ASSERT_EQ(string("c:\\"), actual); + ASSERT_TRUE(AsShortWindowsPath("/C//", &actual)); + ASSERT_EQ(string("c:\\"), actual); + + // The A drive usually doesn't exist but AsShortWindowsPath should still work. + // Here we even have multiple trailing slashes, that should be handled too. + ASSERT_TRUE(AsShortWindowsPath("A://", &actual)); + ASSERT_EQ(string("a:\\"), actual); + ASSERT_TRUE(AsShortWindowsPath("/A//", &actual)); + ASSERT_EQ(string("a:\\"), actual); + + // Assert that we can shorten the TEST_TMPDIR. string tmpdir; GET_TEST_TMPDIR(tmpdir); string short_tmpdir; @@ -250,12 +263,26 @@ TEST_F(FileWindowsTest, TestAsShortWindowsPath) { ASSERT_LT(0, short_tmpdir.size()); ASSERT_TRUE(PathExists(short_tmpdir)); + // Assert that a trailing "/" doesn't change the shortening logic and it will + // be stripped from the result. + ASSERT_TRUE(AsShortWindowsPath(tmpdir + "/", &actual)); + ASSERT_EQ(actual, short_tmpdir); + ASSERT_NE(actual.back(), '/'); + ASSERT_NE(actual.back(), '\\'); + + // Assert shortening another long path, and that the result is lowercased. string dirname(JoinPath(short_tmpdir, "LONGpathNAME")); ASSERT_EQ(0, mkdir(dirname.c_str())); ASSERT_TRUE(PathExists(dirname)); - ASSERT_TRUE(AsShortWindowsPath(dirname, &actual)); ASSERT_EQ(short_tmpdir + "\\longpa~1", actual); + + // Assert shortening non-existent paths. + ASSERT_TRUE(AsShortWindowsPath(JoinPath(tmpdir, "NonExistent/FOO"), &actual)); + ASSERT_EQ(short_tmpdir + "\\nonexistent\\foo", actual); + // Assert shortening non-existent root paths. + ASSERT_TRUE(AsShortWindowsPath("/c/NonExistent/FOO", &actual)); + ASSERT_EQ("c:\\nonexistent\\foo", actual); } TEST_F(FileWindowsTest, TestMsysRootRetrieval) { |