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 19 matching lines...) Expand all Loading... |
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 | 39 |
| 40 // Checks that we find uses of identifiers marked as unused. |
| 41 TEST(FunctionsTarget, CheckNotNeeded) { |
| 42 Scheduler scheduler; |
| 43 TestWithScope setup; |
| 44 |
| 45 // The target generator needs a place to put the targets or it will fail. |
| 46 Scope::ItemVector item_collector; |
| 47 setup.scope()->set_item_collector(&item_collector); |
| 48 |
| 49 // Test a good one first. |
| 50 TestParseInput good_input( |
| 51 "a = {x = 1 y = 2}\n" |
| 52 "not_needed(a, \"*\")\n"); |
| 53 ASSERT_FALSE(good_input.has_error()); |
| 54 Err err; |
| 55 good_input.parsed()->Execute(setup.scope(), &err); |
| 56 ASSERT_FALSE(err.has_error()) << err.message(); |
| 57 |
| 58 // Test a varible being used before being declared unused. |
| 59 TestParseInput before_input( |
| 60 "a = {x = 1 y = 2}\n" |
| 61 "b = a.x\n" |
| 62 "not_needed(a, \"*\")\n"); |
| 63 ASSERT_FALSE(before_input.has_error()); |
| 64 err = Err(); |
| 65 before_input.parsed()->Execute(setup.scope(), &err); |
| 66 ASSERT_TRUE(err.has_error()); |
| 67 |
| 68 // Test a varible being used after being declared unused. |
| 69 TestParseInput after_input( |
| 70 "a = {x = 1 y = 2}\n" |
| 71 "assert_unused(a, \"*\")\n" |
| 72 "assert_unused({b = a.x}, [ \"b\" ])\n"); |
| 73 ASSERT_FALSE(after_input.has_error()); |
| 74 err = Err(); |
| 75 after_input.parsed()->Execute(setup.scope(), &err); |
| 76 ASSERT_TRUE(err.has_error()); |
| 77 } |
| 78 |
40 // Checks that the defaults applied to a template invoked by target() use | 79 // 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 | 80 // the name of the template, rather than the string "target" (which is the |
42 // name of the actual function being called). | 81 // name of the actual function being called). |
43 TEST(FunctionsTarget, TemplateDefaults) { | 82 TEST(FunctionsTarget, TemplateDefaults) { |
44 Scheduler scheduler; | 83 Scheduler scheduler; |
45 TestWithScope setup; | 84 TestWithScope setup; |
46 | 85 |
47 // The target generator needs a place to put the targets or it will fail. | 86 // The target generator needs a place to put the targets or it will fail. |
48 Scope::ItemVector item_collector; | 87 Scope::ItemVector item_collector; |
49 setup.scope()->set_item_collector(&item_collector); | 88 setup.scope()->set_item_collector(&item_collector); |
(...skipping 13 matching lines...) Expand all Loading... |
63 # Invoke the template with target(). This will fail to execute if the | 102 # Invoke the template with target(). This will fail to execute if the |
64 # defaults were not set properly, because "default_value" won't exist. | 103 # defaults were not set properly, because "default_value" won't exist. |
65 target("my_templ", "foo") { | 104 target("my_templ", "foo") { |
66 print(default_value) | 105 print(default_value) |
67 })"); | 106 })"); |
68 ASSERT_FALSE(good_input.has_error()); | 107 ASSERT_FALSE(good_input.has_error()); |
69 Err err; | 108 Err err; |
70 good_input.parsed()->Execute(setup.scope(), &err); | 109 good_input.parsed()->Execute(setup.scope(), &err); |
71 ASSERT_FALSE(err.has_error()) << err.message(); | 110 ASSERT_FALSE(err.has_error()) << err.message(); |
72 } | 111 } |
OLD | NEW |