| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 #else | 71 #else |
| 72 setup.build_settings()->SetRootPath(base::FilePath("/source")); | 72 setup.build_settings()->SetRootPath(base::FilePath("/source")); |
| 73 EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//")); | 73 EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//")); |
| 74 EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//")); | 74 EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//")); |
| 75 EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//")); | 75 EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//")); |
| 76 EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//")); | 76 EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//")); |
| 77 EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); | 77 EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); |
| 78 #endif | 78 #endif |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST(RebasePath, StringsSystemPaths) { |
| 82 TestWithScope setup; |
| 83 Scope* scope = setup.scope(); |
| 84 |
| 85 #if defined(OS_WIN) |
| 86 setup.build_settings()->SetBuildDir(SourceDir("C:/ssd/out/Debug")); |
| 87 setup.build_settings()->SetRootPath(base::FilePath(L"C:/hdd/src")); |
| 88 |
| 89 // Test system absolute to-dir. |
| 90 EXPECT_EQ("../../ssd/out/Debug", |
| 91 RebaseOne(scope, ".", "//", "C:/ssd/out/Debug")); |
| 92 EXPECT_EQ("../../ssd/out/Debug/", |
| 93 RebaseOne(scope, "./", "//", "C:/ssd/out/Debug")); |
| 94 EXPECT_EQ("../../ssd/out/Debug/foo", |
| 95 RebaseOne(scope, "foo", "//", "C:/ssd/out/Debug")); |
| 96 EXPECT_EQ("../../ssd/out/Debug/foo/", |
| 97 RebaseOne(scope, "foo/", "//", "C:/ssd/out/Debug")); |
| 98 |
| 99 // Test system absolute from-dir. |
| 100 EXPECT_EQ("../../../hdd/src", |
| 101 RebaseOne(scope, ".", "C:/ssd/out/Debug", "//")); |
| 102 EXPECT_EQ("../../../hdd/src/", |
| 103 RebaseOne(scope, "./", "C:/ssd/out/Debug", "//")); |
| 104 EXPECT_EQ("../../../hdd/src/foo", |
| 105 RebaseOne(scope, "foo", "C:/ssd/out/Debug", "//")); |
| 106 EXPECT_EQ("../../../hdd/src/foo/", |
| 107 RebaseOne(scope, "foo/", "C:/ssd/out/Debug", "//")); |
| 108 #else |
| 109 setup.build_settings()->SetBuildDir(SourceDir("/ssd/out/Debug")); |
| 110 setup.build_settings()->SetRootPath(base::FilePath("/hdd/src")); |
| 111 |
| 112 // Test system absolute to-dir. |
| 113 EXPECT_EQ("../../ssd/out/Debug", |
| 114 RebaseOne(scope, ".", "//", "/ssd/out/Debug")); |
| 115 EXPECT_EQ("../../ssd/out/Debug/", |
| 116 RebaseOne(scope, "./", "//", "/ssd/out/Debug")); |
| 117 EXPECT_EQ("../../ssd/out/Debug/foo", |
| 118 RebaseOne(scope, "foo", "//", "/ssd/out/Debug")); |
| 119 EXPECT_EQ("../../ssd/out/Debug/foo/", |
| 120 RebaseOne(scope, "foo/", "//", "/ssd/out/Debug")); |
| 121 |
| 122 // Test system absolute from-dir. |
| 123 EXPECT_EQ("../../../hdd/src", |
| 124 RebaseOne(scope, ".", "/ssd/out/Debug", "//")); |
| 125 EXPECT_EQ("../../../hdd/src/", |
| 126 RebaseOne(scope, "./", "/ssd/out/Debug", "//")); |
| 127 EXPECT_EQ("../../../hdd/src/foo", |
| 128 RebaseOne(scope, "foo", "/ssd/out/Debug", "//")); |
| 129 EXPECT_EQ("../../../hdd/src/foo/", |
| 130 RebaseOne(scope, "foo/", "/ssd/out/Debug", "//")); |
| 131 #endif |
| 132 } |
| 133 |
| 81 // Test list input. | 134 // Test list input. |
| 82 TEST(RebasePath, List) { | 135 TEST(RebasePath, List) { |
| 83 TestWithScope setup; | 136 TestWithScope setup; |
| 84 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 137 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 85 setup.scope()->set_source_dir(SourceDir("//tools/gn/")); | 138 setup.scope()->set_source_dir(SourceDir("//tools/gn/")); |
| 86 | 139 |
| 87 std::vector<Value> args; | 140 std::vector<Value> args; |
| 88 args.push_back(Value(NULL, Value::LIST)); | 141 args.push_back(Value(NULL, Value::LIST)); |
| 89 args[0].list_value().push_back(Value(NULL, "foo.txt")); | 142 args[0].list_value().push_back(Value(NULL, "foo.txt")); |
| 90 args[0].list_value().push_back(Value(NULL, "bar.txt")); | 143 args[0].list_value().push_back(Value(NULL, "bar.txt")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 107 TestWithScope setup; | 160 TestWithScope setup; |
| 108 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 161 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 109 | 162 |
| 110 // No arg input should issue an error. | 163 // No arg input should issue an error. |
| 111 Err err; | 164 Err err; |
| 112 std::vector<Value> args; | 165 std::vector<Value> args; |
| 113 FunctionCallNode function; | 166 FunctionCallNode function; |
| 114 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); | 167 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); |
| 115 EXPECT_TRUE(err.has_error()); | 168 EXPECT_TRUE(err.has_error()); |
| 116 } | 169 } |
| OLD | NEW |