| 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'package:compiler/src/dart2jslib.dart' show | 8 import 'package:compiler/src/warnings.dart' show |
| 9 DualKind, | 9 MessageKind, |
| 10 MessageKind; | 10 MessageTemplate; |
| 11 | 11 |
| 12 import 'message_kind_helper.dart'; | 12 import 'message_kind_helper.dart'; |
| 13 | 13 |
| 14 import 'dart:mirrors'; | 14 main(List<String> arguments) { |
| 15 List<MessageTemplate> examples = <MessageTemplate>[]; |
| 16 for (MessageKind kind in MessageKind.values) { |
| 17 MessageTemplate template = MessageTemplate.TEMPLATES[kind]; |
| 18 Expect.isNotNull(template, "No template for $kind."); |
| 19 Expect.equals(kind, template.kind, |
| 20 "Invalid MessageTemplate.kind for $kind, found ${template.kind}."); |
| 15 | 21 |
| 16 main(List<String> arguments) { | 22 String name = '${kind.toString()}'.substring('MessageKind.'.length); |
| 17 ClassMirror cls = reflectClass(MessageKind); | |
| 18 Map<String, MessageKind> kinds = <String, MessageKind>{}; | |
| 19 cls.declarations.forEach((Symbol name, DeclarationMirror declaration) { | |
| 20 if (declaration is! VariableMirror) return; | |
| 21 VariableMirror variable = declaration; | |
| 22 if (variable.isStatic) { | |
| 23 var value = cls.getField(name).reflectee; | |
| 24 String variableName = MirrorSystem.getName(name); | |
| 25 if (variableName == 'IMPORT_EXPERIMENTAL_MIRRORS_PADDING') { | |
| 26 return; | |
| 27 } | |
| 28 if (value is MessageKind) { | |
| 29 kinds[variableName] = value; | |
| 30 } else { | |
| 31 Expect.fail("Weird static field: '${variableName}'."); | |
| 32 } | |
| 33 } | |
| 34 }); | |
| 35 List<String> names = kinds.keys.toList()..sort(); | |
| 36 List<String> examples = <String>[]; | |
| 37 for (String name in names) { | |
| 38 if (!arguments.isEmpty && !arguments.contains(name)) continue; | 23 if (!arguments.isEmpty && !arguments.contains(name)) continue; |
| 39 MessageKind kind = kinds[name]; | |
| 40 if (name == 'GENERIC' // Shouldn't be used. | 24 if (name == 'GENERIC' // Shouldn't be used. |
| 41 // We can't provoke a crash. | 25 // We can't provoke a crash. |
| 42 || name == 'COMPILER_CRASHED' | 26 || name == 'COMPILER_CRASHED' |
| 43 || name == 'PLEASE_REPORT_THE_CRASH' | 27 || name == 'PLEASE_REPORT_THE_CRASH' |
| 44 // We cannot provide examples for patch errors. | 28 // We cannot provide examples for patch errors. |
| 45 || name.startsWith('PATCH_')) continue; | 29 || name.startsWith('PATCH_')) continue; |
| 46 if (kind.examples != null) { | 30 if (template.examples != null) { |
| 47 examples.add(name); | 31 examples.add(template); |
| 48 } else { | 32 } else { |
| 49 print("No example in '$name'"); | 33 print("No example in '$name'"); |
| 50 } | 34 } |
| 51 }; | 35 }; |
| 52 var cachedCompiler; | 36 var cachedCompiler; |
| 53 asyncTest(() => Future.forEach(examples, (String name) { | 37 asyncTest(() => Future.forEach(examples, (MessageTemplate template) { |
| 54 print("Checking '$name'."); | 38 print("Checking '${template.kind}'."); |
| 55 Stopwatch sw = new Stopwatch()..start(); | 39 Stopwatch sw = new Stopwatch()..start(); |
| 56 return check(kinds[name], cachedCompiler).then((var compiler) { | 40 return check(template, cachedCompiler).then((var compiler) { |
| 57 cachedCompiler = compiler; | 41 cachedCompiler = compiler; |
| 58 sw.stop(); | 42 sw.stop(); |
| 59 print("Checked '$name' in ${sw.elapsedMilliseconds}ms."); | 43 print("Checked '${template.kind}' in ${sw.elapsedMilliseconds}ms."); |
| 60 }); | 44 }); |
| 61 })); | 45 })); |
| 62 } | 46 } |
| OLD | NEW |