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

Unified Diff: tools/gn/functions_unittest.cc

Issue 2509333003: Change GN to disallow reading args defined in the same declare_args() call. (Closed)
Patch Set: update w/ review feedback Created 4 years, 1 month 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
Index: tools/gn/functions_unittest.cc
diff --git a/tools/gn/functions_unittest.cc b/tools/gn/functions_unittest.cc
index 7156747471225952ae48d78b3b5f4ca8e509449b..949b844b34bc3a9b2ad5eafdd6653ad3802ccb35 100644
--- a/tools/gn/functions_unittest.cc
+++ b/tools/gn/functions_unittest.cc
@@ -125,3 +125,48 @@ TEST(Functions, SplitList) {
"rounding = [[1, 2], [3, 4], [5], [6]]\n",
setup.print_output());
}
+
+TEST(Functions, DeclareArgs) {
+ TestWithScope setup;
+ Err err;
+
+ // It is not legal to read the value of an argument declared in a
+ // declare_args() from inside the call, but outside the call and in
+ // a separate call should work.
+
+ TestParseInput reading_from_same_call(R"(
+ declare_args() {
+ foo = true
+ bar = foo
+ })");
+ reading_from_same_call.parsed()->Execute(setup.scope(), &err);
+ ASSERT_TRUE(err.has_error());
+
+ TestParseInput reading_from_outside_call(R"(
+ declare_args() {
+ foo = true
+ }
+
+ bar = foo
+ assert(bar)
+ )");
+ err = Err();
+ reading_from_outside_call.parsed()->Execute(setup.scope(), &err);
+ ASSERT_FALSE(err.has_error());
+
+ TestParseInput reading_from_different_call(R"(
+ declare_args() {
+ foo = true
+ }
+
+ declare_args() {
+ bar = foo
+ }
+
+ assert(bar)
+ )");
+ err = Err();
+ TestWithScope setup2;
+ reading_from_different_call.parsed()->Execute(setup2.scope(), &err);
+ ASSERT_FALSE(err.has_error());
+}
« tools/gn/functions.cc ('K') | « tools/gn/functions.cc ('k') | tools/gn/parse_tree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698