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

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

Issue 23684057: Support new import rules. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/compiler/dart2js/diagnose_ambiguous_test.dart ('k') | no next file » | 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) 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 import 'dart:async';
9 9
10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show 10 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' show
11 Compiler, 11 Compiler,
12 MessageKind; 12 MessageKind;
13 13
14 import 'memory_compiler.dart'; 14 import 'memory_compiler.dart';
15 15
16 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; 16 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]';
17 17
18 Future<Compiler> check(MessageKind kind, Compiler cachedCompiler) { 18 Future<Compiler> check(MessageKind kind, Compiler cachedCompiler) {
19 Expect.isNotNull(kind.howToFix); 19 Expect.isNotNull(kind.howToFix);
20 Expect.isFalse(kind.examples.isEmpty); 20 Expect.isFalse(kind.examples.isEmpty);
21 21
22 for (String example in kind.examples) { 22 return Future.forEach(kind.examples, (example) {
23 if (example is String) {
24 example = {'main.dart': example};
25 } else {
26 Expect.isTrue(example is Map,
27 "Example must be either a String or a Map.");
28 Expect.isTrue(example.containsKey('main.dart'),
29 "Example map must contain a 'main.dart' entry.");
30 }
23 List<String> messages = <String>[]; 31 List<String> messages = <String>[];
24 void collect(Uri uri, int begin, int end, String message, kind) { 32 void collect(Uri uri, int begin, int end, String message, kind) {
25 if (kind.name == 'verbose info') { 33 if (kind.name == 'verbose info') {
26 return; 34 return;
27 } 35 }
28 messages.add(message); 36 messages.add(message);
29 } 37 }
30 38
31 Compiler compiler = compilerFor( 39 Compiler compiler = compilerFor(
32 {'main.dart': example}, 40 example,
33 diagnosticHandler: collect, 41 diagnosticHandler: collect,
34 options: ['--analyze-only'], 42 options: ['--analyze-only'],
35 cachedCompiler: cachedCompiler); 43 cachedCompiler: cachedCompiler);
36 44
37 return compiler.run(Uri.parse('memory:main.dart')).then((_) { 45 return compiler.run(Uri.parse('memory:main.dart')).then((_) {
38 46
39 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); 47 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""');
40 48
41 String expectedText = !kind.hasHowToFix 49 String expectedText = !kind.hasHowToFix
42 ? kind.template : '${kind.template}\n${kind.howToFix}'; 50 ? kind.template : '${kind.template}\n${kind.howToFix}';
43 String pattern = expectedText.replaceAllMapped( 51 String pattern = expectedText.replaceAllMapped(
44 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}'); 52 new RegExp(ESCAPE_REGEXP), (m) => '\\${m[0]}');
45 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*'); 53 pattern = pattern.replaceAll(new RegExp(r'#\\\{[^}]*\\\}'), '.*');
46 54
47 // TODO(johnniwinther): Extend MessageKind to contain information on 55 // TODO(johnniwinther): Extend MessageKind to contain information on
48 // where info messages are expected. 56 // where info messages are expected.
49 bool messageFound = false; 57 bool messageFound = false;
50 for (String message in messages) { 58 for (String message in messages) {
51 if (new RegExp('^$pattern\$').hasMatch(message)) { 59 if (new RegExp('^$pattern\$').hasMatch(message)) {
52 messageFound = true; 60 messageFound = true;
53 } 61 }
54 } 62 }
55 Expect.isTrue(messageFound, '"$pattern" does not match any in $messages'); 63 Expect.isTrue(messageFound, '"$pattern" does not match any in $messages');
56 return compiler; 64 cachedCompiler = compiler;
57 }); 65 });
58 } 66 }).then((_) => cachedCompiler);
59
60 return new Future<Compiler>.sync(cachedCompiler);
61 } 67 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/diagnose_ambiguous_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698