| Index: tools/gn/functions_target_unittest.cc
|
| diff --git a/tools/gn/functions_target_unittest.cc b/tools/gn/functions_target_unittest.cc
|
| index 525bc7cbdb809e2eef2872e3935da64c4d219f88..15d2d77e6b4252f2d35c9246117ec0415b5d79a0 100644
|
| --- a/tools/gn/functions_target_unittest.cc
|
| +++ b/tools/gn/functions_target_unittest.cc
|
| @@ -37,6 +37,45 @@ TEST(FunctionsTarget, CheckUnused) {
|
| ASSERT_TRUE(err.has_error());
|
| }
|
|
|
| +// Checks that we find uses of identifiers marked as unused.
|
| +TEST(FunctionsTarget, CheckNotNeeded) {
|
| + Scheduler scheduler;
|
| + TestWithScope setup;
|
| +
|
| + // The target generator needs a place to put the targets or it will fail.
|
| + Scope::ItemVector item_collector;
|
| + setup.scope()->set_item_collector(&item_collector);
|
| +
|
| + // Test a good one first.
|
| + TestParseInput good_input(
|
| + "a = {x = 1 y = 2}\n"
|
| + "not_needed(a, \"*\")\n");
|
| + ASSERT_FALSE(good_input.has_error());
|
| + Err err;
|
| + good_input.parsed()->Execute(setup.scope(), &err);
|
| + ASSERT_FALSE(err.has_error()) << err.message();
|
| +
|
| + // Test a varible being used before being declared unused.
|
| + TestParseInput before_input(
|
| + "a = {x = 1 y = 2}\n"
|
| + "b = a.x\n"
|
| + "not_needed(a, \"*\")\n");
|
| + ASSERT_FALSE(before_input.has_error());
|
| + err = Err();
|
| + before_input.parsed()->Execute(setup.scope(), &err);
|
| + ASSERT_TRUE(err.has_error());
|
| +
|
| + // Test a varible being used after being declared unused.
|
| + TestParseInput after_input(
|
| + "a = {x = 1 y = 2}\n"
|
| + "assert_unused(a, \"*\")\n"
|
| + "assert_unused({b = a.x}, [ \"b\" ])\n");
|
| + ASSERT_FALSE(after_input.has_error());
|
| + err = Err();
|
| + after_input.parsed()->Execute(setup.scope(), &err);
|
| + ASSERT_TRUE(err.has_error());
|
| +}
|
| +
|
| // Checks that the defaults applied to a template invoked by target() use
|
| // the name of the template, rather than the string "target" (which is the
|
| // name of the actual function being called).
|
|
|