Index: tools/gn/parse_tree_unittest.cc |
diff --git a/tools/gn/parse_tree_unittest.cc b/tools/gn/parse_tree_unittest.cc |
index 4f46232416bb6f9137366067b82494db3b3ad0b4..fc06c3255a8dab1d02e451e1f7770320ed2c9f36 100644 |
--- a/tools/gn/parse_tree_unittest.cc |
+++ b/tools/gn/parse_tree_unittest.cc |
@@ -48,3 +48,32 @@ TEST(ParseTree, Accessor) { |
ASSERT_EQ(Value::INTEGER, result.type()); |
EXPECT_EQ(kBValue, result.int_value()); |
} |
+ |
+TEST(ParseTree, BlockUnusedVars) { |
+ TestWithScope setup; |
+ |
+ // Printing both values should be OK. |
+ TestParseInput input_all_used( |
+ "{\n" |
+ " a = 12\n" |
+ " b = 13\n" |
+ " print(\"$a $b\")\n" |
+ "}"); |
+ EXPECT_FALSE(input_all_used.has_error()); |
+ |
+ Err err; |
+ input_all_used.parsed()->Execute(setup.scope(), &err); |
+ EXPECT_FALSE(err.has_error()); |
+ |
+ // Skipping one should throw an unused var error. |
+ TestParseInput input_unused( |
+ "{\n" |
+ " a = 12\n" |
+ " b = 13\n" |
+ " print(\"$a\")\n" |
+ "}"); |
+ EXPECT_FALSE(input_unused.has_error()); |
+ |
+ input_unused.parsed()->Execute(setup.scope(), &err); |
+ EXPECT_TRUE(err.has_error()); |
+} |