| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "tools/gn/functions.h" | 7 #include "tools/gn/functions.h" |
| 8 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
| 9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 Scope* scope = setup.scope(); | 36 Scope* scope = setup.scope(); |
| 37 scope->set_source_dir(SourceDir("//tools/gn/")); | 37 scope->set_source_dir(SourceDir("//tools/gn/")); |
| 38 | 38 |
| 39 // Build-file relative paths. | 39 // Build-file relative paths. |
| 40 EXPECT_EQ("../../tools/gn", RebaseOne(scope, ".", "//out/Debug", ".")); | 40 EXPECT_EQ("../../tools/gn", RebaseOne(scope, ".", "//out/Debug", ".")); |
| 41 EXPECT_EQ("../../tools/gn/", RebaseOne(scope, "./", "//out/Debug", ".")); | 41 EXPECT_EQ("../../tools/gn/", RebaseOne(scope, "./", "//out/Debug", ".")); |
| 42 EXPECT_EQ("../../tools/gn/foo", RebaseOne(scope, "foo", "//out/Debug", ".")); | 42 EXPECT_EQ("../../tools/gn/foo", RebaseOne(scope, "foo", "//out/Debug", ".")); |
| 43 EXPECT_EQ("../..", RebaseOne(scope, "../..", "//out/Debug", ".")); | 43 EXPECT_EQ("../..", RebaseOne(scope, "../..", "//out/Debug", ".")); |
| 44 EXPECT_EQ("../../", RebaseOne(scope, "../../", "//out/Debug", ".")); | 44 EXPECT_EQ("../../", RebaseOne(scope, "../../", "//out/Debug", ".")); |
| 45 | 45 |
| 46 // We don't allow going above the root source dir. | 46 // Without a source root defined, we cannot move out of the source tree. |
| 47 EXPECT_EQ("../..", RebaseOne(scope, "../../..", "//out/Debug", ".")); | 47 EXPECT_EQ("../..", RebaseOne(scope, "../../..", "//out/Debug", ".")); |
| 48 | 48 |
| 49 // Source-absolute input paths. | 49 // Source-absolute input paths. |
| 50 EXPECT_EQ("./", RebaseOne(scope, "//", "//", "//")); | 50 EXPECT_EQ("./", RebaseOne(scope, "//", "//", "//")); |
| 51 EXPECT_EQ("foo", RebaseOne(scope, "//foo", "//", "//")); | 51 EXPECT_EQ("foo", RebaseOne(scope, "//foo", "//", "//")); |
| 52 EXPECT_EQ("foo/", RebaseOne(scope, "//foo/", "//", "//")); | 52 EXPECT_EQ("foo/", RebaseOne(scope, "//foo/", "//", "//")); |
| 53 EXPECT_EQ("../../foo/bar", RebaseOne(scope, "//foo/bar", "//out/Debug", ".")); | 53 EXPECT_EQ("../../foo/bar", RebaseOne(scope, "//foo/bar", "//out/Debug", ".")); |
| 54 EXPECT_EQ("./", RebaseOne(scope, "//foo/", "//foo/", "//")); | 54 EXPECT_EQ("./", RebaseOne(scope, "//foo/", "//foo/", "//")); |
| 55 // Thie one is technically correct but could be simplified to "." if | 55 // Thie one is technically correct but could be simplified to "." if |
| 56 // necessary. | 56 // necessary. |
| 57 EXPECT_EQ("../foo", RebaseOne(scope, "//foo", "//foo", "//")); | 57 EXPECT_EQ("../foo", RebaseOne(scope, "//foo", "//foo", "//")); |
| 58 | 58 |
| 59 // Test slash conversion. | 59 // Test slash conversion. |
| 60 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo/bar", ".", ".")); | 60 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo/bar", ".", ".")); |
| 61 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo\\bar", ".", ".")); | 61 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo\\bar", ".", ".")); |
| 62 | 62 |
| 63 // Test system path output. | 63 // Test system path output. |
| 64 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 65 setup.build_settings()->SetRootPath(base::FilePath(L"C:/source")); | 65 setup.build_settings()->SetRootPath(base::FilePath(L"C:/path/to/src")); |
| 66 EXPECT_EQ("C:/source", RebaseOne(scope, ".", "", "//")); | 66 EXPECT_EQ("C:/path/to/src", RebaseOne(scope, ".", "", "//")); |
| 67 EXPECT_EQ("C:/source/", RebaseOne(scope, "//", "", "//")); | 67 EXPECT_EQ("C:/path/to/src/", RebaseOne(scope, "//", "", "//")); |
| 68 EXPECT_EQ("C:/source/foo", RebaseOne(scope, "foo", "", "//")); | 68 EXPECT_EQ("C:/path/to/src/foo", RebaseOne(scope, "foo", "", "//")); |
| 69 EXPECT_EQ("C:/source/foo/", RebaseOne(scope, "foo/", "", "//")); | 69 EXPECT_EQ("C:/path/to/src/foo/", RebaseOne(scope, "foo/", "", "//")); |
| 70 EXPECT_EQ("C:/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); | 70 EXPECT_EQ("C:/path/to/src/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); |
| 71 EXPECT_EQ("C:/path/to/other/tools", |
| 72 RebaseOne(scope, "//../other/tools", "", "//")); |
| 73 EXPECT_EQ("C:/path/to/src/foo/bar", |
| 74 RebaseOne(scope, "//../src/foo/bar", "", "//")); |
| 75 EXPECT_EQ("C:/path/to", RebaseOne(scope, "//..", "", "//")); |
| 76 EXPECT_EQ("C:/path", RebaseOne(scope, "../../../..", "", ".")); |
| 77 EXPECT_EQ("C:/path/to/external/dir/", |
| 78 RebaseOne(scope, "//../external/dir/", "", "//")); |
| 79 |
| 71 #else | 80 #else |
| 72 setup.build_settings()->SetRootPath(base::FilePath("/source")); | 81 setup.build_settings()->SetRootPath(base::FilePath("/path/to/src")); |
| 73 EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//")); | 82 EXPECT_EQ("/path/to/src", RebaseOne(scope, ".", "", "//")); |
| 74 EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//")); | 83 EXPECT_EQ("/path/to/src/", RebaseOne(scope, "//", "", "//")); |
| 75 EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//")); | 84 EXPECT_EQ("/path/to/src/foo", RebaseOne(scope, "foo", "", "//")); |
| 76 EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//")); | 85 EXPECT_EQ("/path/to/src/foo/", RebaseOne(scope, "foo/", "", "//")); |
| 77 EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); | 86 EXPECT_EQ("/path/to/src/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); |
| 87 EXPECT_EQ("/path/to/other/tools", |
| 88 RebaseOne(scope, "//../other/tools", "", "//")); |
| 89 EXPECT_EQ("/path/to/src/foo/bar", |
| 90 RebaseOne(scope, "//../src/foo/bar", "", "//")); |
| 91 EXPECT_EQ("/path/to", RebaseOne(scope, "//..", "", "//")); |
| 92 EXPECT_EQ("/path", RebaseOne(scope, "../../../..", "", ".")); |
| 93 EXPECT_EQ("/path/to/external/dir/", |
| 94 RebaseOne(scope, "//../external/dir/", "", "//")); |
| 78 #endif | 95 #endif |
| 79 } | 96 } |
| 80 | 97 |
| 81 TEST(RebasePath, StringsSystemPaths) { | 98 TEST(RebasePath, StringsSystemPaths) { |
| 82 TestWithScope setup; | 99 TestWithScope setup; |
| 83 Scope* scope = setup.scope(); | 100 Scope* scope = setup.scope(); |
| 84 | 101 |
| 85 #if defined(OS_WIN) | 102 #if defined(OS_WIN) |
| 86 setup.build_settings()->SetBuildDir(SourceDir("C:/ssd/out/Debug")); | 103 setup.build_settings()->SetBuildDir(SourceDir("C:/ssd/out/Debug")); |
| 87 setup.build_settings()->SetRootPath(base::FilePath(L"C:/hdd/src")); | 104 setup.build_settings()->SetRootPath(base::FilePath(L"C:/hdd/src")); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 TestWithScope setup; | 177 TestWithScope setup; |
| 161 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 178 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 162 | 179 |
| 163 // No arg input should issue an error. | 180 // No arg input should issue an error. |
| 164 Err err; | 181 Err err; |
| 165 std::vector<Value> args; | 182 std::vector<Value> args; |
| 166 FunctionCallNode function; | 183 FunctionCallNode function; |
| 167 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); | 184 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); |
| 168 EXPECT_TRUE(err.has_error()); | 185 EXPECT_TRUE(err.has_error()); |
| 169 } | 186 } |
| OLD | NEW |