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

Unified Diff: tools/gn/action_target_generator_unittest.cc

Issue 2627703002: Validate GN substitutions in args and rsp files. (Closed)
Patch Set: Format Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/action_target_generator.cc ('k') | tools/gn/ninja_action_target_writer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/action_target_generator_unittest.cc
diff --git a/tools/gn/action_target_generator_unittest.cc b/tools/gn/action_target_generator_unittest.cc
index 8f3e4d4c3327755c146fa3d1dc54c5877d3f56e8..5a45932e01115448a0bea569d772482f374feb40 100644
--- a/tools/gn/action_target_generator_unittest.cc
+++ b/tools/gn/action_target_generator_unittest.cc
@@ -15,11 +15,11 @@ TEST(ActionTargetGenerator, ActionOutputSubstitutions) {
// First test one with no substitutions, this should be valid.
TestParseInput input_good(
- "action(\"foo\") {\n"
- " script = \"//foo.py\"\n"
- " sources = [ \"//bar.txt\" ]\n"
- " outputs = [ \"//out/Debug/one.txt\" ]\n"
- "}");
+ R"(action("foo") {
+ script = "//foo.py"
+ sources = [ "//bar.txt" ]
+ outputs = [ "//out/Debug/one.txt" ]
+ })");
ASSERT_FALSE(input_good.has_error());
// This should run fine.
@@ -29,14 +29,93 @@ TEST(ActionTargetGenerator, ActionOutputSubstitutions) {
// Same thing with a pattern in the output should fail.
TestParseInput input_bad(
- "action(\"foo\") {\n"
- " script = \"//foo.py\"\n"
- " sources = [ \"//bar.txt\" ]\n"
- " outputs = [ \"//out/Debug/{{source_name_part}}.txt\" ]\n"
- "}");
+ 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(ActionTargetGenerator, ActionForeachSubstitutions) {
+ Scheduler scheduler;
+ 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();
+}
« no previous file with comments | « tools/gn/action_target_generator.cc ('k') | tools/gn/ninja_action_target_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698