OLD | NEW |
---|---|
(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 protected: | |
43 TestWithScope setup_; | |
44 | |
45 Scope::ItemVector items_; | |
46 }; | |
47 | |
48 } // namespace | |
49 | |
50 TEST_F(GetTargetOutputsTest, Executable) { | |
51 Target* exe = new Target(setup_.settings(), GetLabel("//foo/", "bar")); | |
52 exe->set_output_type(Target::EXECUTABLE); | |
53 items_.push_back(new scoped_ptr<Item>(exe)); | |
54 | |
55 Err err; | |
56 Value result = GetTargetOutputs("//foo:bar", &err); | |
57 ASSERT_FALSE(err.has_error()); | |
58 AssertSingleStringEquals(result, "//out/Debug/bar"); | |
scottmg
2014/05/05 16:31:15
won't this have a .exe on windows?
brettw
2014/05/05 17:09:49
I added a comment. The test scope is set up to act
| |
59 } | |
60 | |
61 TEST_F(GetTargetOutputsTest, SourceSet) { | |
62 Target* source_set = new Target(setup_.settings(), GetLabel("//foo/", "bar")); | |
63 source_set->set_output_type(Target::SOURCE_SET); | |
64 items_.push_back(new scoped_ptr<Item>(source_set)); | |
65 | |
66 Err err; | |
67 Value result = GetTargetOutputs("//foo:bar", &err); | |
68 ASSERT_FALSE(err.has_error()); | |
69 AssertSingleStringEquals(result, "//out/Debug/obj/foo/bar.stamp"); | |
70 } | |
71 | |
72 TEST_F(GetTargetOutputsTest, Action) { | |
73 Target* action = new Target(setup_.settings(), GetLabel("//foo/", "bar")); | |
74 action->set_output_type(Target::ACTION); | |
75 action->action_values().outputs().push_back(SourceFile("//output1.txt")); | |
76 action->action_values().outputs().push_back(SourceFile("//output2.txt")); | |
77 | |
78 items_.push_back(new scoped_ptr<Item>(action)); | |
79 | |
80 Err err; | |
81 Value result = GetTargetOutputs("//foo:bar", &err); | |
82 ASSERT_FALSE(err.has_error()); | |
83 | |
84 ASSERT_TRUE(result.type() == Value::LIST); | |
85 ASSERT_EQ(2u, result.list_value().size()); | |
86 ASSERT_TRUE(result.list_value()[0].type() == Value::STRING); | |
scottmg
2014/05/05 16:31:15
maybe an AssertTwoStrings for this and below
| |
87 ASSERT_EQ("//output1.txt", result.list_value()[0].string_value()); | |
88 ASSERT_TRUE(result.list_value()[1].type() == Value::STRING); | |
89 ASSERT_EQ("//output2.txt", result.list_value()[1].string_value()); | |
90 } | |
91 | |
92 TEST_F(GetTargetOutputsTest, ActionForeach) { | |
93 Target* action = new Target(setup_.settings(), GetLabel("//foo/", "bar")); | |
94 action->set_output_type(Target::ACTION_FOREACH); | |
95 action->sources().push_back(SourceFile("//file.txt")); | |
96 action->action_values().outputs().push_back( | |
97 SourceFile("//out/Debug/{{source_file_part}}.one")); | |
98 action->action_values().outputs().push_back( | |
99 SourceFile("//out/Debug/{{source_file_part}}.two")); | |
100 | |
101 items_.push_back(new scoped_ptr<Item>(action)); | |
102 | |
103 Err err; | |
104 Value result = GetTargetOutputs("//foo:bar", &err); | |
105 ASSERT_FALSE(err.has_error()); | |
106 | |
107 ASSERT_TRUE(result.type() == Value::LIST); | |
108 ASSERT_EQ(2u, result.list_value().size()); | |
109 ASSERT_TRUE(result.list_value()[0].type() == Value::STRING); | |
110 ASSERT_EQ("//out/Debug/file.txt.one", result.list_value()[0].string_value()); | |
111 ASSERT_TRUE(result.list_value()[1].type() == Value::STRING); | |
112 ASSERT_EQ("//out/Debug/file.txt.two", result.list_value()[1].string_value()); | |
113 } | |
OLD | NEW |