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

Side by Side Diff: tools/gn/parse_tree_unittest.cc

Issue 439513003: Improve GN value origins for error messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/parse_tree.cc ('k') | tools/gn/value.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/input_file.h" 6 #include "tools/gn/input_file.h"
7 #include "tools/gn/parse_tree.h" 7 #include "tools/gn/parse_tree.h"
8 #include "tools/gn/scope.h" 8 #include "tools/gn/scope.h"
9 #include "tools/gn/test_with_scope.h" 9 #include "tools/gn/test_with_scope.h"
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 TestParseInput input_unused( 69 TestParseInput input_unused(
70 "{\n" 70 "{\n"
71 " a = 12\n" 71 " a = 12\n"
72 " b = 13\n" 72 " b = 13\n"
73 " print(\"$a\")\n" 73 " print(\"$a\")\n"
74 "}"); 74 "}");
75 EXPECT_FALSE(input_unused.has_error()); 75 EXPECT_FALSE(input_unused.has_error());
76 76
77 input_unused.parsed()->Execute(setup.scope(), &err); 77 input_unused.parsed()->Execute(setup.scope(), &err);
78 EXPECT_TRUE(err.has_error()); 78 EXPECT_TRUE(err.has_error());
79
80 // Also verify that the unused variable has the correct origin set. The
81 // origin will point to the value assigned to the variable (in this case, the
82 // "13" assigned to "b".
83 EXPECT_EQ(3, err.location().line_number());
84 EXPECT_EQ(7, err.location().char_offset());
85
79 } 86 }
87
88 TEST(ParseTree, OriginForDereference) {
89 TestWithScope setup;
90 TestParseInput input(
91 "a = 6\n"
92 "get_target_outputs(a)");
93 EXPECT_FALSE(input.has_error());
94
95 Err err;
96 input.parsed()->Execute(setup.scope(), &err);
97 EXPECT_TRUE(err.has_error());
98
99 // The origin for the "not a string" error message should be where the value
100 // was dereferenced (the "a" on the second line).
101 EXPECT_EQ(2, err.location().line_number());
102 EXPECT_EQ(20, err.location().char_offset());
103 }
OLDNEW
« no previous file with comments | « tools/gn/parse_tree.cc ('k') | tools/gn/value.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698