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

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

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
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 "dart:async"; 5 import "dart:async";
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import "package:compiler/src/diagnostics/messages.dart";
9 import "package:compiler/src/elements/elements.dart"; 8 import "package:compiler/src/elements/elements.dart";
10 import "package:compiler/src/resolution/members.dart"; 9 import "package:compiler/src/resolution/members.dart";
11 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; 10 import "package:compiler/src/diagnostics/diagnostic_listener.dart";
12 import "mock_compiler.dart"; 11 import "mock_compiler.dart";
12 import "diagnostic_reporter_helper.dart";
13 13
14 14
15 class CallbackMockCompiler extends MockCompiler { 15 class CallbackMockCompiler extends MockCompiler {
16 CallbackMockCompiler() : super.internal(); 16 CallbackReporter reporter;
17
18 CallbackMockCompiler() : super.internal() {
19 reporter = new CallbackReporter(super.reporter);
20 }
21
22 }
23
24 class CallbackReporter extends DiagnosticReporterWrapper {
25 final DiagnosticReporter reporter;
26
27 CallbackReporter(this.reporter);
17 28
18 var onError; 29 var onError;
19 var onWarning; 30 var onWarning;
20 31
21 setOnError(var f) => onError = f; 32 setOnError(var f) => onError = f;
22 setOnWarning(var f) => onWarning = f; 33 setOnWarning(var f) => onWarning = f;
23 34
24 void reportWarning( 35 void reportWarning(
25 DiagnosticMessage message, 36 DiagnosticMessage message,
26 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) { 37 [List<DiagnosticMessage> infos = const <DiagnosticMessage>[]]) {
(...skipping 14 matching lines...) Expand all
41 } 52 }
42 53
43 Future testErrorHandling() { 54 Future testErrorHandling() {
44 // Test that compiler.currentElement is set correctly when 55 // Test that compiler.currentElement is set correctly when
45 // reporting errors/warnings. 56 // reporting errors/warnings.
46 CallbackMockCompiler compiler = new CallbackMockCompiler(); 57 CallbackMockCompiler compiler = new CallbackMockCompiler();
47 return compiler.init().then((_) { 58 return compiler.init().then((_) {
48 ResolverVisitor visitor = compiler.resolverVisitor(); 59 ResolverVisitor visitor = compiler.resolverVisitor();
49 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); 60 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}');
50 FunctionElement foo = compiler.mainApp.find('foo'); 61 FunctionElement foo = compiler.mainApp.find('foo');
51 compiler.setOnWarning( 62 compiler.reporter.setOnWarning(
52 (c, n, m) => Expect.equals(foo, compiler.currentElement)); 63 (c, n, m) => Expect.equals(foo, compiler.currentElement));
53 foo.computeType(compiler.resolution); 64 foo.computeType(compiler.resolution);
54 Expect.equals(1, compiler.warnings.length); 65 Expect.equals(1, compiler.warnings.length);
55 }); 66 });
56 } 67 }
57 68
58 main() { 69 main() {
59 asyncTest(() => testErrorHandling()); 70 asyncTest(() => testErrorHandling());
60 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698