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 14 matching lines...) Expand all Loading... |
25 bool is_string = result.type() == Value::STRING; | 25 bool is_string = result.type() == Value::STRING; |
26 EXPECT_TRUE(is_string); | 26 EXPECT_TRUE(is_string); |
27 | 27 |
28 return result.string_value(); | 28 return result.string_value(); |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 TEST(RebasePath, Strings) { | 33 TEST(RebasePath, Strings) { |
34 TestWithScope setup; | 34 TestWithScope setup; |
35 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
36 Scope* scope = setup.scope(); | 35 Scope* scope = setup.scope(); |
37 scope->set_source_dir(SourceDir("//tools/gn/")); | 36 scope->set_source_dir(SourceDir("//tools/gn/")); |
38 | 37 |
39 // Build-file relative paths. | 38 // Build-file relative paths. |
40 EXPECT_EQ("../../tools/gn", RebaseOne(scope, ".", "//out/Debug", ".")); | 39 EXPECT_EQ("../../tools/gn", RebaseOne(scope, ".", "//out/Debug", ".")); |
41 EXPECT_EQ("../../tools/gn/", RebaseOne(scope, "./", "//out/Debug", ".")); | 40 EXPECT_EQ("../../tools/gn/", RebaseOne(scope, "./", "//out/Debug", ".")); |
42 EXPECT_EQ("../../tools/gn/foo", RebaseOne(scope, "foo", "//out/Debug", ".")); | 41 EXPECT_EQ("../../tools/gn/foo", RebaseOne(scope, "foo", "//out/Debug", ".")); |
43 EXPECT_EQ("../..", RebaseOne(scope, "../..", "//out/Debug", ".")); | 42 EXPECT_EQ("../..", RebaseOne(scope, "../..", "//out/Debug", ".")); |
44 EXPECT_EQ("../../", RebaseOne(scope, "../../", "//out/Debug", ".")); | 43 EXPECT_EQ("../../", RebaseOne(scope, "../../", "//out/Debug", ".")); |
45 | 44 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 EXPECT_EQ("../../../hdd/src/foo", | 143 EXPECT_EQ("../../../hdd/src/foo", |
145 RebaseOne(scope, "foo", "/ssd/out/Debug", "//")); | 144 RebaseOne(scope, "foo", "/ssd/out/Debug", "//")); |
146 EXPECT_EQ("../../../hdd/src/foo/", | 145 EXPECT_EQ("../../../hdd/src/foo/", |
147 RebaseOne(scope, "foo/", "/ssd/out/Debug", "//")); | 146 RebaseOne(scope, "foo/", "/ssd/out/Debug", "//")); |
148 #endif | 147 #endif |
149 } | 148 } |
150 | 149 |
151 // Test list input. | 150 // Test list input. |
152 TEST(RebasePath, List) { | 151 TEST(RebasePath, List) { |
153 TestWithScope setup; | 152 TestWithScope setup; |
154 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
155 setup.scope()->set_source_dir(SourceDir("//tools/gn/")); | 153 setup.scope()->set_source_dir(SourceDir("//tools/gn/")); |
156 | 154 |
157 std::vector<Value> args; | 155 std::vector<Value> args; |
158 args.push_back(Value(nullptr, Value::LIST)); | 156 args.push_back(Value(nullptr, Value::LIST)); |
159 args[0].list_value().push_back(Value(nullptr, "foo.txt")); | 157 args[0].list_value().push_back(Value(nullptr, "foo.txt")); |
160 args[0].list_value().push_back(Value(nullptr, "bar.txt")); | 158 args[0].list_value().push_back(Value(nullptr, "bar.txt")); |
161 args.push_back(Value(nullptr, "//out/Debug/")); | 159 args.push_back(Value(nullptr, "//out/Debug/")); |
162 args.push_back(Value(nullptr, ".")); | 160 args.push_back(Value(nullptr, ".")); |
163 | 161 |
164 Err err; | 162 Err err; |
165 FunctionCallNode function; | 163 FunctionCallNode function; |
166 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); | 164 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); |
167 EXPECT_FALSE(err.has_error()); | 165 EXPECT_FALSE(err.has_error()); |
168 | 166 |
169 ASSERT_EQ(Value::LIST, ret.type()); | 167 ASSERT_EQ(Value::LIST, ret.type()); |
170 ASSERT_EQ(2u, ret.list_value().size()); | 168 ASSERT_EQ(2u, ret.list_value().size()); |
171 | 169 |
172 EXPECT_EQ("../../tools/gn/foo.txt", ret.list_value()[0].string_value()); | 170 EXPECT_EQ("../../tools/gn/foo.txt", ret.list_value()[0].string_value()); |
173 EXPECT_EQ("../../tools/gn/bar.txt", ret.list_value()[1].string_value()); | 171 EXPECT_EQ("../../tools/gn/bar.txt", ret.list_value()[1].string_value()); |
174 } | 172 } |
175 | 173 |
176 TEST(RebasePath, Errors) { | 174 TEST(RebasePath, Errors) { |
177 TestWithScope setup; | 175 TestWithScope setup; |
178 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
179 | 176 |
180 // No arg input should issue an error. | 177 // No arg input should issue an error. |
181 Err err; | 178 Err err; |
182 std::vector<Value> args; | 179 std::vector<Value> args; |
183 FunctionCallNode function; | 180 FunctionCallNode function; |
184 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); | 181 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); |
185 EXPECT_TRUE(err.has_error()); | 182 EXPECT_TRUE(err.has_error()); |
186 } | 183 } |
OLD | NEW |