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

Unified Diff: tools/gn/function_rebase_path_unittest.cc

Issue 1455203002: [GN] Add support to rebase_path to resolve paths above the source root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Add tests, handle Windows sources. Created 5 years 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_unittest.cc ('k') | tools/gn/source_dir.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_rebase_path_unittest.cc
diff --git a/tools/gn/function_rebase_path_unittest.cc b/tools/gn/function_rebase_path_unittest.cc
index bed5663917b66df3fb6c78e08c6777441f220824..456d4fb8a967798a8a57c121bf6736e3d5c63598 100644
--- a/tools/gn/function_rebase_path_unittest.cc
+++ b/tools/gn/function_rebase_path_unittest.cc
@@ -43,7 +43,7 @@ TEST(RebasePath, Strings) {
EXPECT_EQ("../..", RebaseOne(scope, "../..", "//out/Debug", "."));
EXPECT_EQ("../../", RebaseOne(scope, "../../", "//out/Debug", "."));
- // We don't allow going above the root source dir.
+ // Without a source root defined, we cannot move out of the source tree.
EXPECT_EQ("../..", RebaseOne(scope, "../../..", "//out/Debug", "."));
// Source-absolute input paths.
@@ -62,19 +62,36 @@ TEST(RebasePath, Strings) {
// Test system path output.
#if defined(OS_WIN)
- setup.build_settings()->SetRootPath(base::FilePath(L"C:/source"));
- EXPECT_EQ("C:/source", RebaseOne(scope, ".", "", "//"));
- EXPECT_EQ("C:/source/", RebaseOne(scope, "//", "", "//"));
- EXPECT_EQ("C:/source/foo", RebaseOne(scope, "foo", "", "//"));
- EXPECT_EQ("C:/source/foo/", RebaseOne(scope, "foo/", "", "//"));
- EXPECT_EQ("C:/source/tools/gn/foo", RebaseOne(scope, "foo", "", "."));
+ setup.build_settings()->SetRootPath(base::FilePath(L"C:/path/to/src"));
+ EXPECT_EQ("C:/path/to/src", RebaseOne(scope, ".", "", "//"));
+ EXPECT_EQ("C:/path/to/src/", RebaseOne(scope, "//", "", "//"));
+ EXPECT_EQ("C:/path/to/src/foo", RebaseOne(scope, "foo", "", "//"));
+ EXPECT_EQ("C:/path/to/src/foo/", RebaseOne(scope, "foo/", "", "//"));
+ EXPECT_EQ("C:/path/to/src/tools/gn/foo", RebaseOne(scope, "foo", "", "."));
+ EXPECT_EQ("C:/path/to/other/tools",
+ RebaseOne(scope, "//../other/tools", "", "//"));
+ EXPECT_EQ("C:/path/to/src/foo/bar",
+ RebaseOne(scope, "//../src/foo/bar", "", "//"));
+ EXPECT_EQ("C:/path/to", RebaseOne(scope, "//..", "", "//"));
+ EXPECT_EQ("C:/path", RebaseOne(scope, "../../../..", "", "."));
+ EXPECT_EQ("C:/path/to/external/dir/",
+ RebaseOne(scope, "//../external/dir/", "", "//"));
+
#else
- setup.build_settings()->SetRootPath(base::FilePath("/source"));
- EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//"));
- EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//"));
- EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//"));
- EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//"));
- EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", "."));
+ setup.build_settings()->SetRootPath(base::FilePath("/path/to/src"));
+ EXPECT_EQ("/path/to/src", RebaseOne(scope, ".", "", "//"));
+ EXPECT_EQ("/path/to/src/", RebaseOne(scope, "//", "", "//"));
+ EXPECT_EQ("/path/to/src/foo", RebaseOne(scope, "foo", "", "//"));
+ EXPECT_EQ("/path/to/src/foo/", RebaseOne(scope, "foo/", "", "//"));
+ EXPECT_EQ("/path/to/src/tools/gn/foo", RebaseOne(scope, "foo", "", "."));
+ EXPECT_EQ("/path/to/other/tools",
+ RebaseOne(scope, "//../other/tools", "", "//"));
+ EXPECT_EQ("/path/to/src/foo/bar",
+ RebaseOne(scope, "//../src/foo/bar", "", "//"));
+ EXPECT_EQ("/path/to", RebaseOne(scope, "//..", "", "//"));
+ EXPECT_EQ("/path", RebaseOne(scope, "../../../..", "", "."));
+ EXPECT_EQ("/path/to/external/dir/",
+ RebaseOne(scope, "//../external/dir/", "", "//"));
#endif
}
« no previous file with comments | « tools/gn/filesystem_utils_unittest.cc ('k') | tools/gn/source_dir.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698