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

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

Issue 1885523002: Add summary to analyze_* tests. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update cf. comments. Created 4 years, 8 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
« no previous file with comments | « no previous file | tests/compiler/dart2js/analyze_test_test.dart » ('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 (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyze_helper; 5 library analyze_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:compiler/compiler.dart' as api; 9 import 'package:compiler/compiler.dart' as api;
10 import 'package:compiler/src/apiimpl.dart'; 10 import 'package:compiler/src/apiimpl.dart';
11 import 'package:compiler/src/commandline_options.dart'; 11 import 'package:compiler/src/commandline_options.dart';
12 import 'package:compiler/src/diagnostics/messages.dart' show 12 import 'package:compiler/src/diagnostics/messages.dart' show
13 Message, 13 Message,
14 MessageKind; 14 MessageKind;
15 import 'package:compiler/src/filenames.dart'; 15 import 'package:compiler/src/filenames.dart';
16 import 'package:compiler/src/options.dart' show 16 import 'package:compiler/src/options.dart' show
17 CompilerOptions; 17 CompilerOptions;
18 import 'package:compiler/src/source_file_provider.dart'; 18 import 'package:compiler/src/source_file_provider.dart';
19 import 'package:compiler/src/util/uri_extras.dart'; 19 import 'package:compiler/src/util/uri_extras.dart';
20 import 'diagnostic_helper.dart';
20 21
21 /// Option for hiding whitelisted messages. 22 /// Option for hiding whitelisted messages.
22 const String HIDE_WHITELISTED = '--hide-whitelisted'; 23 const String HIDE_WHITELISTED = '--hide-whitelisted';
23 24
24 /** 25 /**
25 * Map of whitelisted warnings and errors. 26 * Map of whitelisted warnings and errors.
26 * 27 *
27 * Only add a whitelisting together with a bug report to dartbug.com and add 28 * Only add a whitelisting together with a bug report to dartbug.com and add
28 * the bug issue number as a comment on the whitelisting. 29 * the bug issue number as a comment on the whitelisting.
29 * 30 *
30 * Use an identifiable suffix of the file uri as key. Use a fixed substring of 31 * Use an identifiable suffix of the file uri as key. Use a fixed substring of
31 * the error/warning message in the list of whitelistings for each file. 32 * the error/warning message in the list of whitelistings for each file.
32 */ 33 */
33 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as 34 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as
34 // values. 35 // values.
35 36
36 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { 37 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler {
37 bool hasWarnings = false; 38 bool hasWarnings = false;
38 bool hasHint = false; 39 bool hasHint = false;
39 bool hasErrors = false; 40 bool hasErrors = false;
40 bool lastWasWhitelisted = false; 41 bool lastWasWhitelisted = false;
41 bool showWhitelisted = true; 42 bool showWhitelisted = true;
42 43
43 Map<String, Map<dynamic/*String|MessageKind*/, int>> whiteListMap 44 Map<String, Map<dynamic/*String|MessageKind*/, int>> whiteListMap
44 = new Map<String, Map<dynamic/*String|MessageKind*/, int>>(); 45 = new Map<String, Map<dynamic/*String|MessageKind*/, int>>();
45 List<MessageKind> skipList; 46 List<MessageKind> skipList;
47 List<CollectedMessage> collectedMessages = <CollectedMessage>[];
46 48
47 CollectingDiagnosticHandler( 49 CollectingDiagnosticHandler(
48 Map<String, List/*<String|MessageKind>*/> whiteList, 50 Map<String, List/*<String|MessageKind>*/> whiteList,
49 this.skipList, 51 this.skipList,
50 SourceFileProvider provider) 52 SourceFileProvider provider)
51 : super(provider) { 53 : super(provider) {
52 whiteList.forEach((String file, List/*<String|MessageKind>*/ messageParts) { 54 whiteList.forEach((String file, List/*<String|MessageKind>*/ messageParts) {
53 var useMap = new Map<dynamic/*String|MessageKind*/, int>(); 55 var useMap = new Map<dynamic/*String|MessageKind*/, int>();
54 for (var messagePart in messageParts) { 56 for (var messagePart in messageParts) {
55 useMap[messagePart] = 0; 57 useMap[messagePart] = 0;
56 } 58 }
57 whiteListMap[file] = useMap; 59 whiteListMap[file] = useMap;
58 }); 60 });
59 } 61 }
60 62
61 bool checkResults() { 63 bool checkResults() {
62 bool validWhiteListUse = checkWhiteListUse(); 64 bool validWhiteListUse = checkWhiteListUse();
63 reportWhiteListUse(); 65 reportWhiteListUse();
66 reportCollectedMessages();
64 return !hasWarnings && !hasHint && !hasErrors && validWhiteListUse; 67 return !hasWarnings && !hasHint && !hasErrors && validWhiteListUse;
65 } 68 }
66 69
67 bool checkWhiteListUse() { 70 bool checkWhiteListUse() {
68 bool allUsed = true; 71 bool allUsed = true;
69 for (String file in whiteListMap.keys) { 72 for (String file in whiteListMap.keys) {
70 for (var messagePart in whiteListMap[file].keys) { 73 for (var messagePart in whiteListMap[file].keys) {
71 if (whiteListMap[file][messagePart] == 0) { 74 if (whiteListMap[file][messagePart] == 0) {
72 print("Whitelisting '$messagePart' is unused in '$file'. " 75 print("Whitelisting '$messagePart' is unused in '$file'. "
73 "Remove the whitelisting from the whitelist map."); 76 "Remove the whitelisting from the whitelist map.");
74 allUsed = false; 77 allUsed = false;
75 } 78 }
76 } 79 }
77 } 80 }
78 return allUsed; 81 return allUsed;
79 } 82 }
80 83
84 void reportCollectedMessages() {
85 if (collectedMessages.isNotEmpty) {
86 print('----------------------------------------------------------------');
87 print('Unexpected messages:');
88 print('----------------------------------------------------------------');
89 for (CollectedMessage message in collectedMessages) {
90 super.report(message.message, message.uri, message.begin,
91 message.end, message.text, message.kind);
92 }
93 print('----------------------------------------------------------------');
94 }
95 }
96
81 void reportWhiteListUse() { 97 void reportWhiteListUse() {
82 for (String file in whiteListMap.keys) { 98 for (String file in whiteListMap.keys) {
83 for (var messagePart in whiteListMap[file].keys) { 99 for (var messagePart in whiteListMap[file].keys) {
84 int useCount = whiteListMap[file][messagePart]; 100 int useCount = whiteListMap[file][messagePart];
85 print("Whitelisted message '$messagePart' suppressed $useCount " 101 print("Whitelisted message '$messagePart' suppressed $useCount "
86 "time(s) in '$file'."); 102 "time(s) in '$file'.");
87 } 103 }
88 } 104 }
89 } 105 }
90 106
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 super.report(message, uri, begin, end, text, kind); 165 super.report(message, uri, begin, end, text, kind);
150 } 166 }
151 return; 167 return;
152 } 168 }
153 hasErrors = true; 169 hasErrors = true;
154 } 170 }
155 if (kind == api.Diagnostic.INFO && lastWasWhitelisted) { 171 if (kind == api.Diagnostic.INFO && lastWasWhitelisted) {
156 return; 172 return;
157 } 173 }
158 lastWasWhitelisted = false; 174 lastWasWhitelisted = false;
175 if (kind != api.Diagnostic.VERBOSE_INFO) {
176 collectedMessages.add(new CollectedMessage(
177 message, uri, begin, end, text, kind));
178 }
159 super.report(message, uri, begin, end, text, kind); 179 super.report(message, uri, begin, end, text, kind);
160 } 180 }
161 } 181 }
162 182
163 typedef bool CheckResults(CompilerImpl compiler, 183 typedef bool CheckResults(CompilerImpl compiler,
164 CollectingDiagnosticHandler handler); 184 CollectingDiagnosticHandler handler);
165 185
166 enum AnalysisMode { 186 enum AnalysisMode {
167 /// Analyze all declarations in all libraries in one go. 187 /// Analyze all declarations in all libraries in one go.
168 ALL, 188 ALL,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (checkResults != null) { 280 if (checkResults != null) {
261 result = checkResults(compiler, handler); 281 result = checkResults(compiler, handler);
262 } else { 282 } else {
263 result = handler.checkResults(); 283 result = handler.checkResults();
264 } 284 }
265 if (!result) { 285 if (!result) {
266 print(MESSAGE); 286 print(MESSAGE);
267 exit(1); 287 exit(1);
268 } 288 }
269 } 289 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/analyze_test_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698