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

Unified Diff: tools/gn/functions_unittest.cc

Issue 1007963003: Fixes to {} handling in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 9 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/functions.cc ('k') | tools/gn/parse_tree_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/functions_unittest.cc
diff --git a/tools/gn/functions_unittest.cc b/tools/gn/functions_unittest.cc
index 82173edac8bc347342d778b7f00f07e7c83bf345..6a6c679094a92662fd68068193cb41b011997a3a 100644
--- a/tools/gn/functions_unittest.cc
+++ b/tools/gn/functions_unittest.cc
@@ -53,3 +53,36 @@ TEST(Functions, Defined) {
ASSERT_EQ(Value::BOOLEAN, result.type());
EXPECT_FALSE(result.boolean_value());
}
+
+// Tests that an error is thrown when a {} is supplied to a function that
+// doesn't take one.
+TEST(Functions, FunctionsWithBlock) {
+ TestWithScope setup;
+ Err err;
+
+ // No scope to print() is OK.
+ TestParseInput print_no_scope("print(6)");
+ EXPECT_FALSE(print_no_scope.has_error());
+ Value result = print_no_scope.parsed()->Execute(setup.scope(), &err);
+ EXPECT_FALSE(err.has_error());
+
+ // Passing a scope should pass parsing (it doesn't know about what kind of
+ // function it is) and then throw an error during execution.
+ TestParseInput print_with_scope("print(foo) {}");
+ EXPECT_FALSE(print_with_scope.has_error());
+ result = print_with_scope.parsed()->Execute(setup.scope(), &err);
+ EXPECT_TRUE(err.has_error());
+ err = Err();
+
+ // defined() is a special function so test it separately.
+ TestParseInput defined_no_scope("defined(foo)");
+ EXPECT_FALSE(defined_no_scope.has_error());
+ result = defined_no_scope.parsed()->Execute(setup.scope(), &err);
+ EXPECT_FALSE(err.has_error());
+
+ // A block to defined should fail.
+ TestParseInput defined_with_scope("defined(foo) {}");
+ EXPECT_FALSE(defined_with_scope.has_error());
+ result = defined_with_scope.parsed()->Execute(setup.scope(), &err);
+ EXPECT_TRUE(err.has_error());
+}
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/parse_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698