-
Notifications
You must be signed in to change notification settings - Fork 0
/
action_target_generator_unittest.cc
122 lines (109 loc) · 4.29 KB
/
action_target_generator_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/scheduler.h"
#include "tools/gn/test_with_scheduler.h"
#include "tools/gn/test_with_scope.h"
using ActionTargetGenerator = TestWithScheduler;
// Tests that actions can't have output substitutions.
TEST_F(ActionTargetGenerator, ActionOutputSubstitutions) {
TestWithScope setup;
Scope::ItemVector items_;
setup.scope()->set_item_collector(&items_);
// First test one with no substitutions, this should be valid.
TestParseInput input_good(
R"(action("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/one.txt" ]
})");
ASSERT_FALSE(input_good.has_error());
// This should run fine.
Err err;
input_good.parsed()->Execute(setup.scope(), &err);
ASSERT_FALSE(err.has_error()) << err.message();
// Same thing with a pattern in the output should fail.
TestParseInput input_bad(
R"(action("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}.txt" ]
})");
ASSERT_FALSE(input_bad.has_error());
// This should run fine.
input_bad.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error());
}
// Tests that arg and response file substitutions are validated for
// action_foreach targets.
TEST_F(ActionTargetGenerator, ActionForeachSubstitutions) {
TestWithScope setup;
Scope::ItemVector items_;
setup.scope()->set_item_collector(&items_);
// Args listing a response file but missing a response file definition should
// fail.
TestParseInput input_missing_resp_file(
R"(action_foreach("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}" ]
args = [ "{{response_file_name}}" ]
})");
ASSERT_FALSE(input_missing_resp_file.has_error());
Err err;
input_missing_resp_file.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error());
// Adding a response file definition should pass.
err = Err();
TestParseInput input_resp_file(
R"(action_foreach("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}" ]
args = [ "{{response_file_name}}" ]
response_file_contents = [ "{{source_name_part}}" ]
})");
ASSERT_FALSE(input_resp_file.has_error());
input_resp_file.parsed()->Execute(setup.scope(), &err);
ASSERT_FALSE(err.has_error()) << err.message();
// Defining a response file but not referencing it should fail.
err = Err();
TestParseInput input_missing_rsp_args(
R"(action_foreach("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}" ]
args = [ "{{source_name_part}}" ]
response_file_contents = [ "{{source_name_part}}" ]
})");
ASSERT_FALSE(input_missing_rsp_args.has_error());
input_missing_rsp_args.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error()) << err.message();
// Bad substitutions in args.
err = Err();
TestParseInput input_bad_args(
R"(action_foreach("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}" ]
args = [ "{{response_file_name}} {{ldflags}}" ]
response_file_contents = [ "{{source_name_part}}" ]
})");
ASSERT_FALSE(input_bad_args.has_error());
input_bad_args.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error()) << err.message();
// Bad substitutions in response file contents.
err = Err();
TestParseInput input_bad_rsp(
R"(action_foreach("foo") {
script = "//foo.py"
sources = [ "//bar.txt" ]
outputs = [ "//out/Debug/{{source_name_part}}" ]
args = [ "{{response_file_name}}" ]
response_file_contents = [ "{{source_name_part}} {{ldflags}}" ]
})");
ASSERT_FALSE(input_bad_rsp.has_error());
input_bad_rsp.parsed()->Execute(setup.scope(), &err);
ASSERT_TRUE(err.has_error()) << err.message();
}