| Index: tools/gn/function_template_unittest.cc
|
| diff --git a/tools/gn/function_template_unittest.cc b/tools/gn/function_template_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cd98423a48c5b4151b59cf2378555e5fcadc58ce
|
| --- /dev/null
|
| +++ b/tools/gn/function_template_unittest.cc
|
| @@ -0,0 +1,29 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "tools/gn/test_with_scope.h"
|
| +
|
| +// Checks that variables used inside template definitions aren't reported
|
| +// unused if they were declared above the template.
|
| +TEST(FunctionTemplate, MarkUsed) {
|
| + TestWithScope setup;
|
| + TestParseInput input(
|
| + "a = 1\n" // Unused outside of template.
|
| + "template(\"templ\") {\n"
|
| + " print(a)\n"
|
| + "}\n");
|
| + ASSERT_FALSE(input.has_error()) << input.parse_err().message();
|
| +
|
| + Err err;
|
| + input.parsed()->Execute(setup.scope(), &err);
|
| + ASSERT_FALSE(err.has_error()) << err.message();
|
| +
|
| + // Normally the loader calls CheckForUnusedVars() when it loads a file
|
| + // since normal blocks don't do this check. To avoid having to make this
|
| + // test much more complicated, just explicitly do the check to make sure
|
| + // things are marked properly.
|
| + setup.scope()->CheckForUnusedVars(&err);
|
| + EXPECT_FALSE(err.has_error());
|
| +}
|
|
|