Test that not_needed works with forward_variables_from

This change does not change the existing functionality, but adds
additional test to clarify it and prevent future breakage.

Change-Id: Ic62210481f7734fd23c59720d4b9a7fa10e9ab53
Reviewed-on: https://gn-review.googlesource.com/c/1881
Commit-Queue: Petr Hosek <phosek@google.com>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
diff --git a/tools/gn/functions_target_unittest.cc b/tools/gn/functions_target_unittest.cc
index 708c060..3edd77d 100644
--- a/tools/gn/functions_target_unittest.cc
+++ b/tools/gn/functions_target_unittest.cc
@@ -88,6 +88,27 @@
   error_input.parsed()->Execute(setup.scope(), &err);
   ASSERT_TRUE(err.has_error());
   EXPECT_EQ("Not supported with a variable list.", err.message());
+
+  TestParseInput template_input(
+      R"(# Test that not_needed() propagates through templates correctly;
+      # no error should arise from not using "a".
+      template("inner_templ") {
+        source_set(target_name) {
+          not_needed(invoker, [ "a" ])
+        }
+      }
+      template("outer_templ") {
+        inner_templ(target_name) {
+          forward_variables_from(invoker, "*")
+        }
+      }
+      outer_templ("foo") {
+        a = 1
+      })");
+  ASSERT_FALSE(template_input.has_error());
+  err = Err();
+  template_input.parsed()->Execute(setup.scope(), &err);
+  ASSERT_FALSE(err.has_error()) << err.message();
 }
 
 // Checks that the defaults applied to a template invoked by target() use