Chromium Code Reviews| 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 not needed. | |
| 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 TestParseInput nonscoped_input( | |
| 50 "a = 1\n" | |
| 51 "not_needed([ \"a\" ])\n"); | |
| 52 ASSERT_FALSE(nonscoped_input.has_error()); | |
| 53 Err err; | |
| 54 nonscoped_input.parsed()->Execute(setup.scope(), &err); | |
| 55 ASSERT_FALSE(err.has_error()) << err.message(); | |
| 56 | |
| 57 TestParseInput scoped_input( | |
| 58 "a = {x = 1 y = 2}\n" | |
| 59 "not_needed(a, \"*\")\n"); | |
|
brettw
2017/06/28 20:16:49
Can you test the exclusion list also?
Petr Hosek
2017/06/28 23:21:32
Done.
| |
| 60 ASSERT_FALSE(scoped_input.has_error()); | |
| 61 err = Err(); | |
| 62 scoped_input.parsed()->Execute(setup.scope(), &err); | |
| 63 ASSERT_FALSE(err.has_error()) << err.message(); | |
| 64 } | |
| 65 | |
| 40 // Checks that the defaults applied to a template invoked by target() use | 66 // 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 | 67 // the name of the template, rather than the string "target" (which is the |
| 42 // name of the actual function being called). | 68 // name of the actual function being called). |
| 43 TEST(FunctionsTarget, TemplateDefaults) { | 69 TEST(FunctionsTarget, TemplateDefaults) { |
| 44 Scheduler scheduler; | 70 Scheduler scheduler; |
| 45 TestWithScope setup; | 71 TestWithScope setup; |
| 46 | 72 |
| 47 // The target generator needs a place to put the targets or it will fail. | 73 // The target generator needs a place to put the targets or it will fail. |
| 48 Scope::ItemVector item_collector; | 74 Scope::ItemVector item_collector; |
| 49 setup.scope()->set_item_collector(&item_collector); | 75 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 | 89 # Invoke the template with target(). This will fail to execute if the |
| 64 # defaults were not set properly, because "default_value" won't exist. | 90 # defaults were not set properly, because "default_value" won't exist. |
| 65 target("my_templ", "foo") { | 91 target("my_templ", "foo") { |
| 66 print(default_value) | 92 print(default_value) |
| 67 })"); | 93 })"); |
| 68 ASSERT_FALSE(good_input.has_error()); | 94 ASSERT_FALSE(good_input.has_error()); |
| 69 Err err; | 95 Err err; |
| 70 good_input.parsed()->Execute(setup.scope(), &err); | 96 good_input.parsed()->Execute(setup.scope(), &err); |
| 71 ASSERT_FALSE(err.has_error()) << err.message(); | 97 ASSERT_FALSE(err.has_error()) << err.message(); |
| 72 } | 98 } |
| OLD | NEW |