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

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

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.test.diagnostic_helper; 5 library dart2js.test.diagnostic_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:compiler/compiler_new.dart' show 9 import 'package:compiler/compiler_new.dart'
10 CompilerDiagnostics, 10 show CompilerDiagnostics, Diagnostic;
11 Diagnostic; 11 import 'package:compiler/src/diagnostics/messages.dart'
12 import 'package:compiler/src/diagnostics/messages.dart' show 12 show Message, MessageKind;
13 Message,
14 MessageKind;
15 import 'package:expect/expect.dart'; 13 import 'package:expect/expect.dart';
16 14
17 class CollectedMessage { 15 class CollectedMessage {
18 final Message message; 16 final Message message;
19 final Uri uri; 17 final Uri uri;
20 final int begin; 18 final int begin;
21 final int end; 19 final int end;
22 final String text; 20 final String text;
23 final Diagnostic kind; 21 final Diagnostic kind;
24 22
25 CollectedMessage( 23 CollectedMessage(
26 this.message, this.uri, this.begin, this.end, this.text, this.kind); 24 this.message, this.uri, this.begin, this.end, this.text, this.kind);
27 25
28 MessageKind get messageKind => message?.kind; 26 MessageKind get messageKind => message?.kind;
29 27
30 String toString() { 28 String toString() {
31 return '${message != null ? message.kind : ''}' 29 return '${message != null ? message.kind : ''}'
32 ':$uri:$begin:$end:$text:$kind'; 30 ':$uri:$begin:$end:$text:$kind';
33 } 31 }
34 } 32 }
35 33
36 class DiagnosticCollector implements CompilerDiagnostics { 34 class DiagnosticCollector implements CompilerDiagnostics {
37 List<CollectedMessage> messages = <CollectedMessage>[]; 35 List<CollectedMessage> messages = <CollectedMessage>[];
38 36
39 @override 37 @override
40 void report(Message message, 38 void report(Message message, Uri uri, int begin, int end, String text,
41 Uri uri, int begin, int end, String text, Diagnostic kind) { 39 Diagnostic kind) {
42 messages.add(new CollectedMessage(message, uri, begin, end, text, kind)); 40 messages.add(new CollectedMessage(message, uri, begin, end, text, kind));
43 } 41 }
44 42
45 Iterable<CollectedMessage> filterMessagesByKinds(List<Diagnostic> kinds) { 43 Iterable<CollectedMessage> filterMessagesByKinds(List<Diagnostic> kinds) {
46 return messages.where( 44 return messages
47 (CollectedMessage message) => kinds.contains(message.kind)); 45 .where((CollectedMessage message) => kinds.contains(message.kind));
48 } 46 }
49 47
50 Iterable<CollectedMessage> get errors { 48 Iterable<CollectedMessage> get errors {
51 return filterMessagesByKinds([Diagnostic.ERROR]); 49 return filterMessagesByKinds([Diagnostic.ERROR]);
52 } 50 }
53 51
54 Iterable<CollectedMessage> get warnings { 52 Iterable<CollectedMessage> get warnings {
55 return filterMessagesByKinds([Diagnostic.WARNING]); 53 return filterMessagesByKinds([Diagnostic.WARNING]);
56 } 54 }
57 55
(...skipping 13 matching lines...) Expand all
71 bool get hasRegularMessages { 69 bool get hasRegularMessages {
72 return messages.any((m) => m.kind != Diagnostic.VERBOSE_INFO); 70 return messages.any((m) => m.kind != Diagnostic.VERBOSE_INFO);
73 } 71 }
74 72
75 void clear() { 73 void clear() {
76 messages.clear(); 74 messages.clear();
77 } 75 }
78 76
79 void checkMessages(List<Expected> expectedMessages) { 77 void checkMessages(List<Expected> expectedMessages) {
80 int index = 0; 78 int index = 0;
81 Iterable<CollectedMessage> messages = 79 Iterable<CollectedMessage> messages = filterMessagesByKinds([
82 filterMessagesByKinds( 80 Diagnostic.ERROR,
83 [Diagnostic.ERROR, 81 Diagnostic.WARNING,
84 Diagnostic.WARNING, 82 Diagnostic.HINT,
85 Diagnostic.HINT, 83 Diagnostic.INFO
86 Diagnostic.INFO]); 84 ]);
87 for (CollectedMessage message in messages) { 85 for (CollectedMessage message in messages) {
88 if (index >= expectedMessages.length) { 86 if (index >= expectedMessages.length) {
89 Expect.fail("Unexpected messages:\n " 87 Expect.fail("Unexpected messages:\n "
90 "${messages.skip(index).join('\n ')}"); 88 "${messages.skip(index).join('\n ')}");
91 } else { 89 } else {
92 Expected expected = expectedMessages[index]; 90 Expected expected = expectedMessages[index];
93 Expect.equals(expected.messageKind, message.messageKind, 91 Expect.equals(expected.messageKind, message.messageKind,
94 "Unexpected message kind in:\n ${messages.join('\n ')}"); 92 "Unexpected message kind in:\n ${messages.join('\n ')}");
95 Expect.equals(expected.diagnosticKind, message.kind, 93 Expect.equals(expected.diagnosticKind, message.kind,
96 "Unexpected diagnostic kind in\n ${messages.join('\n ')}"); 94 "Unexpected diagnostic kind in\n ${messages.join('\n ')}");
97 index++; 95 index++;
98 } 96 }
99 } 97 }
100 } 98 }
(...skipping 11 matching lines...) Expand all
112 const Expected.warning(MessageKind messageKind) 110 const Expected.warning(MessageKind messageKind)
113 : this(messageKind, Diagnostic.WARNING); 111 : this(messageKind, Diagnostic.WARNING);
114 112
115 const Expected.hint(MessageKind messageKind) 113 const Expected.hint(MessageKind messageKind)
116 : this(messageKind, Diagnostic.HINT); 114 : this(messageKind, Diagnostic.HINT);
117 115
118 const Expected.info(MessageKind messageKind) 116 const Expected.info(MessageKind messageKind)
119 : this(messageKind, Diagnostic.INFO); 117 : this(messageKind, Diagnostic.INFO);
120 } 118 }
121 119
122 120 void compareWarningKinds(String text, List expectedWarnings,
123 void compareWarningKinds(String text, 121 Iterable<CollectedMessage> foundWarnings) {
124 List expectedWarnings,
125 Iterable<CollectedMessage> foundWarnings) {
126 compareMessageKinds(text, expectedWarnings, foundWarnings, 'warning'); 122 compareMessageKinds(text, expectedWarnings, foundWarnings, 'warning');
127 } 123 }
128 124
129 /// [expectedMessages] must be a list of either [MessageKind] or [CheckMessage]. 125 /// [expectedMessages] must be a list of either [MessageKind] or [CheckMessage].
130 void compareMessageKinds(String text, 126 void compareMessageKinds(String text, List expectedMessages,
131 List expectedMessages, 127 Iterable<CollectedMessage> foundMessages, String kind) {
132 Iterable<CollectedMessage> foundMessages,
133 String kind) {
134 var fail = (message) => Expect.fail('$text: $message'); 128 var fail = (message) => Expect.fail('$text: $message');
135 HasNextIterator expectedIterator = 129 HasNextIterator expectedIterator =
136 new HasNextIterator(expectedMessages.iterator); 130 new HasNextIterator(expectedMessages.iterator);
137 HasNextIterator<CollectedMessage> foundIterator = 131 HasNextIterator<CollectedMessage> foundIterator =
138 new HasNextIterator(foundMessages.iterator); 132 new HasNextIterator(foundMessages.iterator);
139 while (expectedIterator.hasNext && foundIterator.hasNext) { 133 while (expectedIterator.hasNext && foundIterator.hasNext) {
140 var expected = expectedIterator.next(); 134 var expected = expectedIterator.next();
141 var found = foundIterator.next(); 135 var found = foundIterator.next();
142 if (expected is MessageKind) { 136 if (expected is MessageKind) {
143 Expect.equals(expected, found.message.kind); 137 Expect.equals(expected, found.message.kind);
(...skipping 30 matching lines...) Expand all
174 if (message == null) return '$kind'; 168 if (message == null) return '$kind';
175 if (message.kind != kind) return 'Expected message $kind, found $message.'; 169 if (message.kind != kind) return 'Expected message $kind, found $message.';
176 for (var key in arguments.keys) { 170 for (var key in arguments.keys) {
177 if (!message.arguments.containsKey(key)) { 171 if (!message.arguments.containsKey(key)) {
178 return 'Expected argument $key not found in $message.kind.'; 172 return 'Expected argument $key not found in $message.kind.';
179 } 173 }
180 String expectedValue = '${arguments[key]}'; 174 String expectedValue = '${arguments[key]}';
181 String foundValue = '${message.arguments[key]}'; 175 String foundValue = '${message.arguments[key]}';
182 if (expectedValue != foundValue) { 176 if (expectedValue != foundValue) {
183 return 'Expected argument $key with value $expectedValue, ' 177 return 'Expected argument $key with value $expectedValue, '
184 'found $foundValue.'; 178 'found $foundValue.';
185 } 179 }
186 } 180 }
187 return null; 181 return null;
188 }; 182 };
189 } 183 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/diagnose_ambiguous_test.dart ('k') | tests/compiler/dart2js/diagnostic_reporter_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698