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

Side by Side Diff: tools/gn/function_to_build_path_unittest.cc

Issue 23606031: GN: Use build directory for CD for scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/function_to_build_path.cc ('k') | tools/gn/functions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/test_with_scope.h"
9
10 namespace {
11
12 void ExpectCallEqualsString(Scope* scope,
13 const std::string& input,
14 const std::string& expected) {
15 std::vector<Value> args;
16 args.push_back(Value(NULL, input));
17
18 Err err;
19 FunctionCallNode function;
20 Value result = functions::RunToBuildPath(scope, &function, args, &err);
21
22 EXPECT_FALSE(err.has_error());
23 EXPECT_EQ(Value::STRING, result.type());
24 EXPECT_EQ(expected, result.string_value());
25 }
26
27 } // namespace
28
29 TEST(ToBuildPath, Strings) {
30 TestWithScope setup;
31 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
32
33 Scope* scope = setup.scope();
34 scope->set_source_dir(SourceDir("//tools/gn/"));
35
36 // Absolute system paths are unchanged.
37 ExpectCallEqualsString(scope, "/", "/");
38 ExpectCallEqualsString(scope, "/foo", "/foo");
39 ExpectCallEqualsString(scope, "/foo/", "/foo");
40 ExpectCallEqualsString(scope, "/foo/bar.txt", "/foo/bar.txt");
41
42 // Build-file relative paths.
43 ExpectCallEqualsString(scope, ".", "../../tools/gn");
44 ExpectCallEqualsString(scope, "foo.txt", "../../tools/gn/foo.txt");
45 ExpectCallEqualsString(scope, "..", "../../tools");
46 ExpectCallEqualsString(scope, "../", "../../tools");
47 ExpectCallEqualsString(scope, "../foo.txt", "../../tools/foo.txt");
48
49 // Source-root paths.
50 ExpectCallEqualsString(scope, "//", "../..");
51 ExpectCallEqualsString(scope, "//foo/", "../../foo");
52 ExpectCallEqualsString(scope, "//foo.txt", "../../foo.txt");
53 ExpectCallEqualsString(scope, "//foo/bar.txt", "../../foo/bar.txt");
54
55 // Source-root paths. It might be nice if we detected the strings start
56 // with the build dir and collapse, but this is the current behavior.
57 ExpectCallEqualsString(scope, "//out/Debug/",
58 "../../out/Debug"); // Could be ".".
59 ExpectCallEqualsString(scope, "//out/Debug/foo/",
60 "../../out/Debug/foo"); // Could be "foo".
61 }
62
63 // Test list input.
64 TEST(ToBuildPath, List) {
65 TestWithScope setup;
66 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
67 setup.scope()->set_source_dir(SourceDir("//tools/gn/"));
68
69 std::vector<Value> args;
70 args.push_back(Value(NULL, Value::LIST));
71 args[0].list_value().push_back(Value(NULL, "foo.txt"));
72 args[0].list_value().push_back(Value(NULL, "bar.txt"));
73
74 Err err;
75 FunctionCallNode function;
76 Value ret = functions::RunToBuildPath(setup.scope(), &function, args, &err);
77 EXPECT_FALSE(err.has_error());
78
79 ASSERT_EQ(Value::LIST, ret.type());
80 ASSERT_EQ(2u, ret.list_value().size());
81
82 EXPECT_EQ("../../tools/gn/foo.txt", ret.list_value()[0].string_value());
83 EXPECT_EQ("../../tools/gn/bar.txt", ret.list_value()[1].string_value());
84 }
85
86 TEST(ToBuildPath, Errors) {
87 TestWithScope setup;
88 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
89
90 // No arg input should issue an error.
91 Err err;
92 std::vector<Value> args;
93 FunctionCallNode function;
94 Value ret = functions::RunToBuildPath(setup.scope(), &function, args, &err);
95 EXPECT_TRUE(err.has_error());
96
97 // One arg int input.
98 args.push_back(Value(NULL, static_cast<int64>(5)));
99 err = Err();
100 ret = functions::RunToBuildPath(setup.scope(), &function, args, &err);
101 EXPECT_TRUE(err.has_error());
102
103 // Two arg string input.
104 args.clear();
105 args.push_back(Value(NULL, "hello"));
106 args.push_back(Value(NULL, "world"));
107 err = Err();
108 ret = functions::RunToBuildPath(setup.scope(), &function, args, &err);
109 EXPECT_TRUE(err.has_error());
110 }
OLDNEW
« no previous file with comments | « tools/gn/function_to_build_path.cc ('k') | tools/gn/functions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698