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