| 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 dart2js.test.message_kind_helper; | 5 library dart2js.test.message_kind_helper; |
| 6 | 6 |
| 7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 8 import 'dart:async'; |
| 8 | 9 |
| 9 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show | 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show |
| 10 Compiler, | 11 Compiler, |
| 11 MessageKind; | 12 MessageKind; |
| 12 | 13 |
| 13 import 'memory_compiler.dart'; | 14 import 'memory_compiler.dart'; |
| 14 | 15 |
| 15 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; | 16 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; |
| 16 | 17 |
| 17 Compiler check(MessageKind kind, Compiler cachedCompiler, | 18 Future<Compiler> check(MessageKind kind, Compiler cachedCompiler, |
| 18 {bool expectNoHowToFix: false}) { | 19 {bool expectNoHowToFix: false}) { |
| 19 if (expectNoHowToFix) { | 20 if (expectNoHowToFix) { |
| 20 Expect.isNull(kind.howToFix); | 21 Expect.isNull(kind.howToFix); |
| 21 } else { | 22 } else { |
| 22 Expect.isNotNull(kind.howToFix); | 23 Expect.isNotNull(kind.howToFix); |
| 23 } | 24 } |
| 24 Expect.isFalse(kind.examples.isEmpty); | 25 Expect.isFalse(kind.examples.isEmpty); |
| 25 | 26 |
| 26 for (String example in kind.examples) { | 27 for (String example in kind.examples) { |
| 27 List<String> messages = <String>[]; | 28 List<String> messages = <String>[]; |
| 28 void collect(Uri uri, int begin, int end, String message, kind) { | 29 void collect(Uri uri, int begin, int end, String message, kind) { |
| 29 if (kind.name == 'verbose info') { | 30 if (kind.name == 'verbose info') { |
| 30 return; | 31 return; |
| 31 } | 32 } |
| 32 messages.add(message); | 33 messages.add(message); |
| 33 } | 34 } |
| 34 | 35 |
| 35 Compiler compiler = compilerFor( | 36 Compiler compiler = compilerFor( |
| 36 {'main.dart': example}, | 37 {'main.dart': example}, |
| 37 diagnosticHandler: collect, | 38 diagnosticHandler: collect, |
| 38 options: ['--analyze-only'], | 39 options: ['--analyze-only'], |
| 39 cachedCompiler: cachedCompiler); | 40 cachedCompiler: cachedCompiler); |
| 40 | 41 |
| 41 compiler.run(Uri.parse('memory:main.dart')); | 42 return compiler.run(Uri.parse('memory:main.dart')).then((_) { |
| 42 | 43 |
| 43 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); | 44 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); |
| 44 | 45 |
| 45 String expectedText = kind.howToFix == null | 46 String expectedText = kind.howToFix == null |
| 46 ? kind.template : '${kind.template}\n${kind.howToFix}'; | 47 ? kind.template : '${kind.template}\n${kind.howToFix}'; |
| 47 String pattern = expectedText.replaceAllMapped( | 48 String pattern = expectedText.replaceAllMapped( |
| 48 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); | 49 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); |
| 49 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); | 50 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); |
| 50 | 51 |
| 51 for (String message in messages) { | 52 for (String message in messages) { |
| 52 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), | 53 Expect.isTrue(new RegExp('^$pattern\$').hasMatch(message), |
| 53 '"$pattern" does not match "$message"'); | 54 '"$pattern" does not match "$message"'); |
| 54 } | 55 } |
| 55 return compiler; | 56 return compiler; |
| 57 }); |
| 56 } | 58 } |
| 57 } | 59 } |
| OLD | NEW |