| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | |
| 8 import 'dart:async'; | 7 import 'dart:async'; |
| 9 import 'dart:io'; | 8 import 'dart:io'; |
| 10 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 9 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 11 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart'; |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 13 hide Compiler; | 12 hide Compiler; |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 15 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; |
| 15 import '../../../sdk/lib/_internal/compiler/implementation/util/uri_extras.dart'
; |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Map of whitelisted warnings and errors. | 18 * Map of whitelisted warnings and errors. |
| 19 * | 19 * |
| 20 * Only add a whitelisting together with a bug report to dartbug.com and add | 20 * Only add a whitelisting together with a bug report to dartbug.com and add |
| 21 * the bug issue number as a comment on the whitelisting. | 21 * the bug issue number as a comment on the whitelisting. |
| 22 * | 22 * |
| 23 * Use an identifiable suffix of the file uri as key. Use a fixed substring of | 23 * Use an identifiable suffix of the file uri as key. Use a fixed substring of |
| 24 * the error/warning message in the list of whitelistings for each file. | 24 * the error/warning message in the list of whitelistings for each file. |
| 25 */ | 25 */ |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 : super(provider) { | 39 : super(provider) { |
| 40 whiteList.forEach((String file, List<String> messageParts) { | 40 whiteList.forEach((String file, List<String> messageParts) { |
| 41 var useMap = new Map<String,int>(); | 41 var useMap = new Map<String,int>(); |
| 42 for (String messagePart in messageParts) { | 42 for (String messagePart in messageParts) { |
| 43 useMap[messagePart] = 0; | 43 useMap[messagePart] = 0; |
| 44 } | 44 } |
| 45 whiteListMap[file] = useMap; | 45 whiteListMap[file] = useMap; |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void checkResults() { | 49 bool checkResults() { |
| 50 Expect.isFalse(hasWarnings); | 50 bool validWhiteListUse = checkWhiteListUse(); |
| 51 Expect.isFalse(hasHint); | |
| 52 Expect.isFalse(hasErrors); | |
| 53 Expect.isTrue(checkWhiteListUse()); | |
| 54 reportWhiteListUse(); | 51 reportWhiteListUse(); |
| 52 return !hasWarnings && !hasHint && !hasErrors && validWhiteListUse; |
| 55 } | 53 } |
| 56 | 54 |
| 57 bool checkWhiteListUse() { | 55 bool checkWhiteListUse() { |
| 58 bool allUsed = true; | 56 bool allUsed = true; |
| 59 for (String file in whiteListMap.keys) { | 57 for (String file in whiteListMap.keys) { |
| 60 for (String messagePart in whiteListMap[file].keys) { | 58 for (String messagePart in whiteListMap[file].keys) { |
| 61 if (whiteListMap[file][messagePart] == 0) { | 59 if (whiteListMap[file][messagePart] == 0) { |
| 62 print("Whitelisting '$messagePart' is unused in '$file'. " | 60 print("Whitelisting '$messagePart' is unused in '$file'. " |
| 63 "Remove the whitelisting from the whitelist map."); | 61 "Remove the whitelisting from the whitelist map."); |
| 64 allUsed = false; | 62 allUsed = false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 } | 117 } |
| 120 hasErrors = true; | 118 hasErrors = true; |
| 121 } | 119 } |
| 122 super.diagnosticHandler(uri, begin, end, message, kind); | 120 super.diagnosticHandler(uri, begin, end, message, kind); |
| 123 } | 121 } |
| 124 } | 122 } |
| 125 | 123 |
| 126 Future analyze(List<Uri> uriList, | 124 Future analyze(List<Uri> uriList, |
| 127 Map<String, List<String>> whiteList, | 125 Map<String, List<String>> whiteList, |
| 128 {bool analyzeAll: true}) { | 126 {bool analyzeAll: true}) { |
| 127 String testFileName = |
| 128 relativize(Uri.base, Platform.script, Platform.isWindows); |
| 129 |
| 130 print(""" |
| 131 |
| 132 |
| 133 === |
| 134 === NOTE: If this test fails, update [WHITE_LIST] in $testFileName |
| 135 === |
| 136 |
| 137 |
| 138 """); |
| 139 |
| 129 var libraryRoot = currentDirectory.resolve('sdk/'); | 140 var libraryRoot = currentDirectory.resolve('sdk/'); |
| 130 var provider = new CompilerSourceFileProvider(); | 141 var provider = new CompilerSourceFileProvider(); |
| 131 var handler = new CollectingDiagnosticHandler(whiteList, provider); | 142 var handler = new CollectingDiagnosticHandler(whiteList, provider); |
| 132 var options = <String>['--analyze-only', '--categories=Client,Server']; | 143 var options = <String>['--analyze-only', '--categories=Client,Server']; |
| 133 if (analyzeAll) options.add('--analyze-all'); | 144 if (analyzeAll) options.add('--analyze-all'); |
| 134 var compiler = new Compiler( | 145 var compiler = new Compiler( |
| 135 provider.readStringFromUri, | 146 provider.readStringFromUri, |
| 136 null, | 147 null, |
| 137 handler.diagnosticHandler, | 148 handler.diagnosticHandler, |
| 138 libraryRoot, libraryRoot, | 149 libraryRoot, libraryRoot, |
| 139 options, | 150 options, |
| 140 {}); | 151 {}); |
| 152 String MESSAGE = """ |
| 153 |
| 154 |
| 155 === |
| 156 === ERROR: Unexpected result of analysis. |
| 157 === |
| 158 === Please update [WHITE_LIST] in $testFileName |
| 159 === |
| 160 """; |
| 161 |
| 162 void onCompletion(_) { |
| 163 bool result = handler.checkResults(); |
| 164 if (!result) { |
| 165 print(MESSAGE); |
| 166 exit(1); |
| 167 } |
| 168 } |
| 141 if (analyzeAll) { | 169 if (analyzeAll) { |
| 142 compiler.librariesToAnalyzeWhenRun = uriList; | 170 compiler.librariesToAnalyzeWhenRun = uriList; |
| 143 return compiler.run(null).then((_) { | 171 return compiler.run(null).then(onCompletion); |
| 144 handler.checkResults(); | |
| 145 }); | |
| 146 } else { | 172 } else { |
| 147 return compiler.run(uriList.single).then((_) { | 173 return compiler.run(uriList.single).then(onCompletion); |
| 148 handler.checkResults(); | |
| 149 }); | |
| 150 } | 174 } |
| 151 } | 175 } |
| OLD | NEW |