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
) {
11 "template(\"foo\") {\n"
12 " print(target_name)\n"
13 " print(invoker.bar)\n"
18 ASSERT_FALSE(input
.has_error());
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
) {
30 "template(\"foo\") {\n"
31 " print(invoker.bar)\n"
36 ASSERT_FALSE(input
.has_error());
39 input
.parsed()->Execute(setup
.scope(), &err
);
40 EXPECT_TRUE(err
.has_error());
43 TEST(Template
, UnusedInvokerShouldThrowError
) {
46 "template(\"foo\") {\n"
47 " print(target_name)\n"
52 ASSERT_FALSE(input
.has_error());
55 input
.parsed()->Execute(setup
.scope(), &err
);
56 EXPECT_TRUE(err
.has_error());
59 TEST(Template
, UnusedVarInInvokerShouldThrowError
) {
62 "template(\"foo\") {\n"
63 " print(target_name)\n"
64 " print(invoker.bar)\n"
68 " baz = [ \"foo\" ]\n"
70 ASSERT_FALSE(input
.has_error());
73 input
.parsed()->Execute(setup
.scope(), &err
);
74 EXPECT_TRUE(err
.has_error());