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

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

Issue 269723006: Add get_target_outputs function to GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 7 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_get_target_outputs.cc ('k') | tools/gn/function_toolchain.cc » ('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 2014 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/target.h"
8 #include "tools/gn/test_with_scope.h"
9
10 namespace {
11
12 class GetTargetOutputsTest : public testing::Test {
13 public:
14 GetTargetOutputsTest() {
15 // Want consistent target names so explicitly set platform.
16 setup_.settings()->set_target_os(Settings::LINUX);
17 setup_.scope()->set_item_collector(&items_);
18 }
19
20 Value GetTargetOutputs(const std::string& name, Err* err) {
21 FunctionCallNode function;
22 std::vector<Value> args;
23 args.push_back(Value(NULL, name));
24 return functions::RunGetTargetOutputs(setup_.scope(), &function, args, err);
25 }
26
27 // Shortcut to get a label with the current toolchain.
28 Label GetLabel(const std::string& dir, const std::string& name) {
29 return Label(SourceDir(dir), name, setup_.toolchain()->label().dir(),
30 setup_.toolchain()->label().name());
31 }
32
33 // Asserts that the given list contains a single string with the given value.
34 void AssertSingleStringEquals(const Value& list,
35 const std::string& expected) {
36 ASSERT_TRUE(list.type() == Value::LIST);
37 ASSERT_EQ(1u, list.list_value().size());
38 ASSERT_TRUE(list.list_value()[0].type() == Value::STRING);
39 ASSERT_EQ(expected, list.list_value()[0].string_value());
40 }
41
42 void AssertTwoStringsEqual(const Value& list,
43 const std::string& expected1,
44 const std::string& expected2) {
45 ASSERT_TRUE(list.type() == Value::LIST);
46 ASSERT_EQ(2u, list.list_value().size());
47 ASSERT_TRUE(list.list_value()[0].type() == Value::STRING);
48 ASSERT_EQ(expected1, list.list_value()[0].string_value());
49 ASSERT_TRUE(list.list_value()[1].type() == Value::STRING);
50 ASSERT_EQ(expected2, list.list_value()[1].string_value());
51 }
52
53 protected:
54 TestWithScope setup_;
55
56 Scope::ItemVector items_;
57 };
58
59 } // namespace
60
61 TEST_F(GetTargetOutputsTest, Executable) {
62 Target* exe = new Target(setup_.settings(), GetLabel("//foo/", "bar"));
63 exe->set_output_type(Target::EXECUTABLE);
64 items_.push_back(new scoped_ptr<Item>(exe));
65
66 Err err;
67 Value result = GetTargetOutputs("//foo:bar", &err);
68 ASSERT_FALSE(err.has_error());
69 // The TestWithScope declares that the build is Linux, so we'll have no
70 // extension for the binaries.
71 AssertSingleStringEquals(result, "//out/Debug/bar");
72 }
73
74 TEST_F(GetTargetOutputsTest, SourceSet) {
75 Target* source_set = new Target(setup_.settings(), GetLabel("//foo/", "bar"));
76 source_set->set_output_type(Target::SOURCE_SET);
77 items_.push_back(new scoped_ptr<Item>(source_set));
78
79 Err err;
80 Value result = GetTargetOutputs("//foo:bar", &err);
81 ASSERT_FALSE(err.has_error());
82 AssertSingleStringEquals(result, "//out/Debug/obj/foo/bar.stamp");
83 }
84
85 TEST_F(GetTargetOutputsTest, Action) {
86 Target* action = new Target(setup_.settings(), GetLabel("//foo/", "bar"));
87 action->set_output_type(Target::ACTION);
88 action->action_values().outputs().push_back(SourceFile("//output1.txt"));
89 action->action_values().outputs().push_back(SourceFile("//output2.txt"));
90
91 items_.push_back(new scoped_ptr<Item>(action));
92
93 Err err;
94 Value result = GetTargetOutputs("//foo:bar", &err);
95 ASSERT_FALSE(err.has_error());
96 AssertTwoStringsEqual(result, "//output1.txt", "//output2.txt");
97 }
98
99 TEST_F(GetTargetOutputsTest, ActionForeach) {
100 Target* action = new Target(setup_.settings(), GetLabel("//foo/", "bar"));
101 action->set_output_type(Target::ACTION_FOREACH);
102 action->sources().push_back(SourceFile("//file.txt"));
103 action->action_values().outputs().push_back(
104 SourceFile("//out/Debug/{{source_file_part}}.one"));
105 action->action_values().outputs().push_back(
106 SourceFile("//out/Debug/{{source_file_part}}.two"));
107
108 items_.push_back(new scoped_ptr<Item>(action));
109
110 Err err;
111 Value result = GetTargetOutputs("//foo:bar", &err);
112 ASSERT_FALSE(err.has_error());
113 AssertTwoStringsEqual(result, "//out/Debug/file.txt.one",
114 "//out/Debug/file.txt.two");
115 }
OLDNEW
« no previous file with comments | « tools/gn/function_get_target_outputs.cc ('k') | tools/gn/function_toolchain.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698