Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: tools/gn/function_template_unittest.cc

Issue 2233893005: GN: Mark all variables used when defining a template. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/function_template.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « tools/gn/function_template.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698