OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/scope.h" | 7 #include "tools/gn/scope.h" |
8 #include "tools/gn/test_with_scope.h" | 8 #include "tools/gn/test_with_scope.h" |
9 | 9 |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 // Test a source set with an unused variable. | 29 // Test a source set with an unused variable. |
30 TestParseInput source_set_input( | 30 TestParseInput source_set_input( |
31 "source_set(\"foo\") {\n" | 31 "source_set(\"foo\") {\n" |
32 " unused = 5\n" | 32 " unused = 5\n" |
33 "}\n"); | 33 "}\n"); |
34 ASSERT_FALSE(source_set_input.has_error()); | 34 ASSERT_FALSE(source_set_input.has_error()); |
35 err = Err(); | 35 err = Err(); |
36 source_set_input.parsed()->Execute(setup.scope(), &err); | 36 source_set_input.parsed()->Execute(setup.scope(), &err); |
37 ASSERT_TRUE(err.has_error()); | 37 ASSERT_TRUE(err.has_error()); |
38 } | 38 } |
| 39 |
| 40 // Checks that the defaults applied to a template invoked by target() use |
| 41 // the name of the template, rather than the string "target" (which is the |
| 42 // name of the actual function being called). |
| 43 TEST(FunctionsTarget, TemplateDefaults) { |
| 44 Scheduler scheduler; |
| 45 TestWithScope setup; |
| 46 |
| 47 // The target generator needs a place to put the targets or it will fail. |
| 48 Scope::ItemVector item_collector; |
| 49 setup.scope()->set_item_collector(&item_collector); |
| 50 |
| 51 // Test a good one first. |
| 52 TestParseInput good_input( |
| 53 // Make a template with defaults set. |
| 54 "template(\"my_templ\") {\n" |
| 55 " source_set(target_name) {\n" |
| 56 " forward_variables_from(invoker, \"*\")\n" |
| 57 " }\n" |
| 58 "}\n" |
| 59 "set_defaults(\"my_templ\") {\n" |
| 60 " default_value = 1\n" |
| 61 "}\n" |
| 62 |
| 63 // Invoke the template with target(). This will fail to execute if the |
| 64 // defaults were not set properly, because "default_value" won't exist. |
| 65 "target(\"my_templ\", \"foo\") {\n" |
| 66 " print(default_value)\n" |
| 67 "}\n"); |
| 68 ASSERT_FALSE(good_input.has_error()); |
| 69 Err err; |
| 70 good_input.parsed()->Execute(setup.scope(), &err); |
| 71 ASSERT_FALSE(err.has_error()) << err.message(); |
| 72 } |
OLD | NEW |