Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: tools/gn/filesystem_utils_unittest.cc

Issue 711113004: original (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win compile fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/filesystem_utils.cc ('k') | tools/gn/function_exec_script.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/filesystem_utils_unittest.cc
diff --git a/tools/gn/filesystem_utils_unittest.cc b/tools/gn/filesystem_utils_unittest.cc
index ba6b9bd509e35bdebdaa5cb2e1759ca5f2453649..7bcfd1af67d838512652ba203a8eb0462e54e4e5 100644
--- a/tools/gn/filesystem_utils_unittest.cc
+++ b/tools/gn/filesystem_utils_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/files/file_path.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -169,16 +170,6 @@ TEST(FilesystemUtils, MakeAbsolutePathRelativeIfPossible) {
#endif
}
-TEST(FilesystemUtils, InvertDir) {
- EXPECT_TRUE(InvertDir(SourceDir()) == "");
- EXPECT_TRUE(InvertDir(SourceDir("/")) == "");
- EXPECT_TRUE(InvertDir(SourceDir("//")) == "");
-
- EXPECT_TRUE(InvertDir(SourceDir("//foo/bar")) == "../../");
- EXPECT_TRUE(InvertDir(SourceDir("//foo\\bar")) == "../../");
- EXPECT_TRUE(InvertDir(SourceDir("/foo/bar/")) == "../../");
-}
-
TEST(FilesystemUtils, NormalizePath) {
std::string input;
@@ -247,54 +238,120 @@ TEST(FilesystemUtils, NormalizePath) {
EXPECT_EQ("../bar", input);
}
-TEST(FilesystemUtils, RebaseSourceAbsolutePath) {
+TEST(FilesystemUtils, RebasePath) {
+ base::StringPiece source_root("/source/root");
+
// Degenerate case.
- EXPECT_EQ(".", RebaseSourceAbsolutePath("//", SourceDir("//")));
- EXPECT_EQ(".",
- RebaseSourceAbsolutePath("//foo/bar/", SourceDir("//foo/bar/")));
+ EXPECT_EQ(".", RebasePath("//", SourceDir("//"), source_root));
+ EXPECT_EQ(".", RebasePath("//foo/bar/", SourceDir("//foo/bar/"),
+ source_root));
// Going up the tree.
- EXPECT_EQ("../foo",
- RebaseSourceAbsolutePath("//foo", SourceDir("//bar/")));
- EXPECT_EQ("../foo/",
- RebaseSourceAbsolutePath("//foo/", SourceDir("//bar/")));
- EXPECT_EQ("../../foo",
- RebaseSourceAbsolutePath("//foo", SourceDir("//bar/moo")));
- EXPECT_EQ("../../foo/",
- RebaseSourceAbsolutePath("//foo/", SourceDir("//bar/moo")));
+ EXPECT_EQ("../foo", RebasePath("//foo", SourceDir("//bar/"), source_root));
+ EXPECT_EQ("../foo/", RebasePath("//foo/", SourceDir("//bar/"), source_root));
+ EXPECT_EQ("../../foo", RebasePath("//foo", SourceDir("//bar/moo"),
+ source_root));
+ EXPECT_EQ("../../foo/", RebasePath("//foo/", SourceDir("//bar/moo"),
+ source_root));
// Going down the tree.
- EXPECT_EQ("foo/bar",
- RebaseSourceAbsolutePath("//foo/bar", SourceDir("//")));
- EXPECT_EQ("foo/bar/",
- RebaseSourceAbsolutePath("//foo/bar/", SourceDir("//")));
+ EXPECT_EQ("foo/bar", RebasePath("//foo/bar", SourceDir("//"), source_root));
+ EXPECT_EQ("foo/bar/", RebasePath("//foo/bar/", SourceDir("//"),
+ source_root));
// Going up and down the tree.
- EXPECT_EQ("../../foo/bar",
- RebaseSourceAbsolutePath("//foo/bar", SourceDir("//a/b/")));
- EXPECT_EQ("../../foo/bar/",
- RebaseSourceAbsolutePath("//foo/bar/", SourceDir("//a/b/")));
+ EXPECT_EQ("../../foo/bar", RebasePath("//foo/bar", SourceDir("//a/b/"),
+ source_root));
+ EXPECT_EQ("../../foo/bar/", RebasePath("//foo/bar/", SourceDir("//a/b/"),
+ source_root));
// Sharing prefix.
- EXPECT_EQ("foo",
- RebaseSourceAbsolutePath("//a/foo", SourceDir("//a/")));
- EXPECT_EQ("foo/",
- RebaseSourceAbsolutePath("//a/foo/", SourceDir("//a/")));
- EXPECT_EQ("foo",
- RebaseSourceAbsolutePath("//a/b/foo", SourceDir("//a/b/")));
- EXPECT_EQ("foo/",
- RebaseSourceAbsolutePath("//a/b/foo/", SourceDir("//a/b/")));
- EXPECT_EQ("foo/bar",
- RebaseSourceAbsolutePath("//a/b/foo/bar", SourceDir("//a/b/")));
- EXPECT_EQ("foo/bar/",
- RebaseSourceAbsolutePath("//a/b/foo/bar/", SourceDir("//a/b/")));
+ EXPECT_EQ("foo", RebasePath("//a/foo", SourceDir("//a/"), source_root));
+ EXPECT_EQ("foo/", RebasePath("//a/foo/", SourceDir("//a/"), source_root));
+ EXPECT_EQ("foo", RebasePath("//a/b/foo", SourceDir("//a/b/"), source_root));
+ EXPECT_EQ("foo/", RebasePath("//a/b/foo/", SourceDir("//a/b/"),
+ source_root));
+ EXPECT_EQ("foo/bar", RebasePath("//a/b/foo/bar", SourceDir("//a/b/"),
+ source_root));
+ EXPECT_EQ("foo/bar/", RebasePath("//a/b/foo/bar/", SourceDir("//a/b/"),
+ source_root));
// One could argue about this case. Since the input doesn't have a slash it
// would normally not be treated like a directory and we'd go up, which is
// simpler. However, since it matches the output directory's name, we could
// potentially infer that it's the same and return "." for this.
- EXPECT_EQ("../bar",
- RebaseSourceAbsolutePath("//foo/bar", SourceDir("//foo/bar/")));
+ EXPECT_EQ("../bar", RebasePath("//foo/bar", SourceDir("//foo/bar/"),
+ source_root));
+
+ // Check when only |input| is system-absolute
+ EXPECT_EQ("foo", RebasePath("/source/root/foo", SourceDir("//"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("foo/", RebasePath("/source/root/foo/", SourceDir("//"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../builddir/Out/Debug",
+ RebasePath("/builddir/Out/Debug", SourceDir("//"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../../builddir/Out/Debug",
+ RebasePath("/builddir/Out/Debug", SourceDir("//"),
+ base::StringPiece("/source/root/foo")));
+ EXPECT_EQ("../../../builddir/Out/Debug/",
+ RebasePath("/builddir/Out/Debug/", SourceDir("//"),
+ base::StringPiece("/source/root/foo")));
+ EXPECT_EQ("../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("//"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("//a"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("//a/b"),
+ base::StringPiece("/source/root")));
+
+ // Check when only |dest_dir| is system-absolute.
+ EXPECT_EQ(".",
+ RebasePath("//", SourceDir("/source/root"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("foo",
+ RebasePath("//foo", SourceDir("/source/root"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../foo",
+ RebasePath("//foo", SourceDir("/source/root/bar"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../../source/root/foo",
+ RebasePath("//foo", SourceDir("/other/source/root"),
+ base::StringPiece("/source/root")));
+ EXPECT_EQ("../../../../source/root/foo",
+ RebasePath("//foo", SourceDir("/other/source/root/bar"),
+ base::StringPiece("/source/root")));
+
+ // Check when |input| and |dest_dir| are both system-absolute. Also,
+ // in this case |source_root| is never used so set it to a dummy
+ // value.
+ EXPECT_EQ("foo",
+ RebasePath("/source/root/foo", SourceDir("/source/root"),
+ base::StringPiece("/x/y/z")));
+ EXPECT_EQ("foo/",
+ RebasePath("/source/root/foo/", SourceDir("/source/root"),
+ base::StringPiece("/x/y/z")));
+ EXPECT_EQ("../../builddir/Out/Debug",
+ RebasePath("/builddir/Out/Debug",SourceDir("/source/root"),
+ base::StringPiece("/x/y/z")));
+ EXPECT_EQ("../../../builddir/Out/Debug",
+ RebasePath("/builddir/Out/Debug", SourceDir("/source/root/foo"),
+ base::StringPiece("/source/root/foo")));
+ EXPECT_EQ("../../../builddir/Out/Debug/",
+ RebasePath("/builddir/Out/Debug/", SourceDir("/source/root/foo"),
+ base::StringPiece("/source/root/foo")));
+ EXPECT_EQ("../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("/source/root"),
+ base::StringPiece("/x/y/z")));
+ EXPECT_EQ("../../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("/source/root/a"),
+ base::StringPiece("/x/y/z")));
+ EXPECT_EQ("../../../../path/to/foo",
+ RebasePath("/path/to/foo", SourceDir("/source/root/a/b"),
+ base::StringPiece("/x/y/z")));
+
}
TEST(FilesystemUtils, DirectoryWithNoLastSlash) {
« no previous file with comments | « tools/gn/filesystem_utils.cc ('k') | tools/gn/function_exec_script.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698