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

Side by Side Diff: dart/tests/compiler/dart2js/compiler_test.dart

Issue 20742002: Clean up error handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added documentation guide lines. Created 7 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 9 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
10 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 10 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
11 import "mock_compiler.dart"; 11 import "mock_compiler.dart";
12 import "parser_helper.dart"; 12 import "parser_helper.dart";
13 13
14 class CallbackMockCompiler extends MockCompiler { 14 class CallbackMockCompiler extends MockCompiler {
15 CallbackMockCompiler(); 15 CallbackMockCompiler();
16 16
17 var onError; 17 var onError;
18 var onWarning; 18 var onWarning;
19 19
20 setOnError(var f) => onError = f; 20 setOnError(var f) => onError = f;
21 setOnWarning(var f) => onWarning = f; 21 setOnWarning(var f) => onWarning = f;
22 22
23 void reportWarning(Node node, var message) { 23 void reportWarning(Node node, var message) {
24 if (onWarning != null) onWarning(this, node, message); 24 if (onWarning != null) onWarning(this, node, message);
25 super.reportWarning(node, message); 25 super.reportWarning(node, message);
26 } 26 }
27 27
28 void reportError(Node node, var message) { 28 void reportError(Spannable node,
29 if (onError != null) onError(this, node, message); 29 MessageKind errorCode,
30 super.reportError(node, message); 30 [Map arguments = const {}]) {
31 if (onError != null) onError(this, node, errorCode.error(arguments));
32 super.reportError(node, errorCode, arguments);
31 } 33 }
32 } 34 }
33 35
34 testErrorHandling() { 36 testErrorHandling() {
35 // Test that compiler.currentElement is set correctly when 37 // Test that compiler.currentElement is set correctly when
36 // reporting errors/warnings. 38 // reporting errors/warnings.
37 CallbackMockCompiler compiler = new CallbackMockCompiler(); 39 CallbackMockCompiler compiler = new CallbackMockCompiler();
38 ResolverVisitor visitor = compiler.resolverVisitor(); 40 ResolverVisitor visitor = compiler.resolverVisitor();
39 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); 41 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}');
40 FunctionElement foo = compiler.mainApp.find(buildSourceString('foo')); 42 FunctionElement foo = compiler.mainApp.find(buildSourceString('foo'));
41 compiler.setOnWarning((c, n, m) => Expect.equals(foo, compiler.currentElement) ); 43 compiler.setOnWarning(
44 (c, n, m) => Expect.equals(foo, compiler.currentElement));
42 foo.computeType(compiler); 45 foo.computeType(compiler);
43 Expect.equals(1, compiler.warnings.length); 46 Expect.equals(1, compiler.warnings.length);
44 } 47 }
45 48
46 main() { 49 main() {
47 testErrorHandling(); 50 testErrorHandling();
48 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698