OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/functions.h" | 6 #include "tools/gn/functions.h" |
7 #include "tools/gn/parse_tree.h" | 7 #include "tools/gn/parse_tree.h" |
8 #include "tools/gn/test_with_scope.h" | 8 #include "tools/gn/test_with_scope.h" |
9 #include "tools/gn/value.h" | 9 #include "tools/gn/value.h" |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 undef_accessor->set_base(defined_token); | 46 undef_accessor->set_base(defined_token); |
47 undef_accessor->set_member(scoped_ptr<IdentifierNode>( | 47 undef_accessor->set_member(scoped_ptr<IdentifierNode>( |
48 new IdentifierNode(undefined_token))); | 48 new IdentifierNode(undefined_token))); |
49 ListNode args_list_accessor_defined; | 49 ListNode args_list_accessor_defined; |
50 args_list_accessor_defined.append_item(undef_accessor.Pass()); | 50 args_list_accessor_defined.append_item(undef_accessor.Pass()); |
51 result = functions::RunDefined(setup.scope(), &function_call, | 51 result = functions::RunDefined(setup.scope(), &function_call, |
52 &args_list_accessor_defined, &err); | 52 &args_list_accessor_defined, &err); |
53 ASSERT_EQ(Value::BOOLEAN, result.type()); | 53 ASSERT_EQ(Value::BOOLEAN, result.type()); |
54 EXPECT_FALSE(result.boolean_value()); | 54 EXPECT_FALSE(result.boolean_value()); |
55 } | 55 } |
| 56 |
| 57 // Tests that an error is thrown when a {} is supplied to a function that |
| 58 // doesn't take one. |
| 59 TEST(Functions, FunctionsWithBlock) { |
| 60 TestWithScope setup; |
| 61 Err err; |
| 62 |
| 63 // No scope to print() is OK. |
| 64 TestParseInput print_no_scope("print(6)"); |
| 65 EXPECT_FALSE(print_no_scope.has_error()); |
| 66 Value result = print_no_scope.parsed()->Execute(setup.scope(), &err); |
| 67 EXPECT_FALSE(err.has_error()); |
| 68 |
| 69 // Passing a scope should pass parsing (it doesn't know about what kind of |
| 70 // function it is) and then throw an error during execution. |
| 71 TestParseInput print_with_scope("print(foo) {}"); |
| 72 EXPECT_FALSE(print_with_scope.has_error()); |
| 73 result = print_with_scope.parsed()->Execute(setup.scope(), &err); |
| 74 EXPECT_TRUE(err.has_error()); |
| 75 err = Err(); |
| 76 |
| 77 // defined() is a special function so test it separately. |
| 78 TestParseInput defined_no_scope("defined(foo)"); |
| 79 EXPECT_FALSE(defined_no_scope.has_error()); |
| 80 result = defined_no_scope.parsed()->Execute(setup.scope(), &err); |
| 81 EXPECT_FALSE(err.has_error()); |
| 82 |
| 83 // A block to defined should fail. |
| 84 TestParseInput defined_with_scope("defined(foo) {}"); |
| 85 EXPECT_FALSE(defined_with_scope.has_error()); |
| 86 result = defined_with_scope.parsed()->Execute(setup.scope(), &err); |
| 87 EXPECT_TRUE(err.has_error()); |
| 88 } |
OLD | NEW |