1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "gn/test_with_scope.h" 6 #include "util/test/test.h" 7 8 // Checks that variables used inside template definitions aren't reported 9 // unused if they were declared above the template. TEST(FunctionTemplate,MarkUsed)10TEST(FunctionTemplate, MarkUsed) { 11 TestWithScope setup; 12 TestParseInput input( 13 "a = 1\n" // Unused outside of template. 14 "template(\"templ\") {\n" 15 " print(a)\n" 16 "}\n"); 17 ASSERT_FALSE(input.has_error()) << input.parse_err().message(); 18 19 Err err; 20 input.parsed()->Execute(setup.scope(), &err); 21 ASSERT_FALSE(err.has_error()) << err.message(); 22 23 // Normally the loader calls CheckForUnusedVars() when it loads a file 24 // since normal blocks don't do this check. To avoid having to make this 25 // test much more complicated, just explicitly do the check to make sure 26 // things are marked properly. 27 setup.scope()->CheckForUnusedVars(&err); 28 EXPECT_FALSE(err.has_error()); 29 } 30