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 import 'dart:async'; |
9 | 9 |
10 import 'package:compiler/src/commandline_options.dart'; | 10 import 'package:compiler/src/commandline_options.dart'; |
11 import 'package:compiler/src/compiler.dart' show | 11 import 'package:compiler/src/compiler.dart' show |
12 Compiler; | 12 Compiler; |
13 import 'package:compiler/src/dart_backend/dart_backend.dart' show | |
14 DartBackend; | |
15 import 'package:compiler/src/diagnostics/messages.dart' show | 13 import 'package:compiler/src/diagnostics/messages.dart' show |
16 MessageKind, | 14 MessageKind, |
17 MessageTemplate; | 15 MessageTemplate; |
18 import 'package:compiler/compiler_new.dart' show | 16 import 'package:compiler/compiler_new.dart' show |
19 Diagnostic; | 17 Diagnostic; |
20 | 18 |
21 import 'memory_compiler.dart'; | 19 import 'memory_compiler.dart'; |
22 | 20 |
23 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; | 21 const String ESCAPE_REGEXP = r'[[\]{}()*+?.\\^$|]'; |
24 | 22 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 if (example is String) { | 62 if (example is String) { |
65 example = {'main.dart': example}; | 63 example = {'main.dart': example}; |
66 } else { | 64 } else { |
67 Expect.isTrue(example is Map, | 65 Expect.isTrue(example is Map, |
68 "Example must be either a String or a Map."); | 66 "Example must be either a String or a Map."); |
69 Expect.isTrue(example.containsKey('main.dart'), | 67 Expect.isTrue(example.containsKey('main.dart'), |
70 "Example map must contain a 'main.dart' entry."); | 68 "Example map must contain a 'main.dart' entry."); |
71 } | 69 } |
72 DiagnosticCollector collector = new DiagnosticCollector(); | 70 DiagnosticCollector collector = new DiagnosticCollector(); |
73 | 71 |
74 bool oldBackendIsDart; | |
75 if (cachedCompiler != null) { | |
76 oldBackendIsDart = cachedCompiler.backend is DartBackend; | |
77 } | |
78 bool newBackendIsDart = template.options.contains('--output-type=dart'); | |
79 | |
80 Compiler compiler = compilerFor( | 72 Compiler compiler = compilerFor( |
81 memorySourceFiles: example, | 73 memorySourceFiles: example, |
82 diagnosticHandler: collector, | 74 diagnosticHandler: collector, |
83 options: [Flags.analyzeOnly, | 75 options: [Flags.analyzeOnly, |
84 Flags.enableExperimentalMirrors]..addAll(template.options), | 76 Flags.enableExperimentalMirrors]..addAll(template.options), |
85 cachedCompiler: | 77 cachedCompiler: cachedCompiler); |
86 // TODO(johnniwinther): Remove this restriction when constant | |
87 // values can be computed directly from the expressions. | |
88 oldBackendIsDart == newBackendIsDart ? cachedCompiler : null); | |
89 | 78 |
90 return compiler.run(Uri.parse('memory:main.dart')).then((_) { | 79 return compiler.run(Uri.parse('memory:main.dart')).then((_) { |
91 Iterable<CollectedMessage> messages = collector.filterMessagesByKinds( | 80 Iterable<CollectedMessage> messages = collector.filterMessagesByKinds( |
92 [Diagnostic.ERROR, | 81 [Diagnostic.ERROR, |
93 Diagnostic.WARNING, | 82 Diagnostic.WARNING, |
94 Diagnostic.HINT, | 83 Diagnostic.HINT, |
95 Diagnostic.CRASH]); | 84 Diagnostic.CRASH]); |
96 | 85 |
97 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); | 86 Expect.isFalse(messages.isEmpty, 'No messages in """$example"""'); |
98 | 87 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 kindsWithPendingClasses.contains(template)); | 143 kindsWithPendingClasses.contains(template)); |
155 | 144 |
156 if (!pendingStuff) { | 145 if (!pendingStuff) { |
157 // If there is pending stuff, or the compiler was cancelled, we | 146 // If there is pending stuff, or the compiler was cancelled, we |
158 // shouldn't reuse the compiler. | 147 // shouldn't reuse the compiler. |
159 cachedCompiler = compiler; | 148 cachedCompiler = compiler; |
160 } | 149 } |
161 }); | 150 }); |
162 }).then((_) => cachedCompiler); | 151 }).then((_) => cachedCompiler); |
163 } | 152 } |
OLD | NEW |