Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / tools / gn / template_unittest.cc
blob13ec8482c1c365821f3bf2eb1a82196a1f403bc4
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/test_with_scope.h"
8 TEST(Template, Basic) {
9 TestWithScope setup;
10 TestParseInput input(
11 "template(\"foo\") {\n"
12 " print(target_name)\n"
13 " print(invoker.bar)\n"
14 "}\n"
15 "foo(\"lala\") {\n"
16 " bar = 42\n"
17 "}");
18 ASSERT_FALSE(input.has_error());
20 Err err;
21 input.parsed()->Execute(setup.scope(), &err);
22 ASSERT_FALSE(err.has_error()) << err.message();
24 EXPECT_EQ("lala\n42\n", setup.print_output());
27 TEST(Template, UnusedTargetNameShouldThrowError) {
28 TestWithScope setup;
29 TestParseInput input(
30 "template(\"foo\") {\n"
31 " print(invoker.bar)\n"
32 "}\n"
33 "foo(\"lala\") {\n"
34 " bar = 42\n"
35 "}");
36 ASSERT_FALSE(input.has_error());
38 Err err;
39 input.parsed()->Execute(setup.scope(), &err);
40 EXPECT_TRUE(err.has_error());
43 TEST(Template, UnusedInvokerShouldThrowError) {
44 TestWithScope setup;
45 TestParseInput input(
46 "template(\"foo\") {\n"
47 " print(target_name)\n"
48 "}\n"
49 "foo(\"lala\") {\n"
50 " bar = 42\n"
51 "}");
52 ASSERT_FALSE(input.has_error());
54 Err err;
55 input.parsed()->Execute(setup.scope(), &err);
56 EXPECT_TRUE(err.has_error());
59 TEST(Template, UnusedVarInInvokerShouldThrowError) {
60 TestWithScope setup;
61 TestParseInput input(
62 "template(\"foo\") {\n"
63 " print(target_name)\n"
64 " print(invoker.bar)\n"
65 "}\n"
66 "foo(\"lala\") {\n"
67 " bar = 42\n"
68 " baz = [ \"foo\" ]\n"
69 "}");
70 ASSERT_FALSE(input.has_error());
72 Err err;
73 input.parsed()->Execute(setup.scope(), &err);
74 EXPECT_TRUE(err.has_error());