OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 mock_compiler; | 5 library mock_compiler; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:compiler/compiler_new.dart' as api; | 10 import 'package:compiler/compiler_new.dart' as api; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 startResolution(); | 146 startResolution(); |
147 // We need to make sure the Object class is resolved. When registering a | 147 // We need to make sure the Object class is resolved. When registering a |
148 // dynamic invocation the ArgumentTypesRegistry eventually iterates over | 148 // dynamic invocation the ArgumentTypesRegistry eventually iterates over |
149 // the interfaces of the Object class which would be 'null' if the class | 149 // the interfaces of the Object class which would be 'null' if the class |
150 // wasn't resolved. | 150 // wasn't resolved. |
151 ClassElement objectClass = resolution.commonElements.objectClass; | 151 ClassElement objectClass = resolution.commonElements.objectClass; |
152 objectClass.ensureResolved(resolution); | 152 objectClass.ensureResolved(resolution); |
153 }).then((_) => uri); | 153 }).then((_) => uri); |
154 } | 154 } |
155 | 155 |
156 Future run(Uri uri, [String mainSource = ""]) { | 156 Future<bool> run(Uri uri, [String mainSource = ""]) { |
157 return init(mainSource).then((Uri mainUri) { | 157 return init(mainSource).then((Uri mainUri) { |
158 return super.run(uri == null ? mainUri : uri); | 158 return super.run(uri == null ? mainUri : uri); |
159 }).then((result) { | 159 }).then((result) { |
160 if (expectedErrors != null && | 160 if (expectedErrors != null && |
161 expectedErrors != diagnosticCollector.errors.length) { | 161 expectedErrors != diagnosticCollector.errors.length) { |
162 throw "unexpected error during compilation " | 162 throw "unexpected error during compilation " |
163 "${diagnosticCollector.errors}"; | 163 "${diagnosticCollector.errors}"; |
164 } else if (expectedWarnings != null && | 164 } else if (expectedWarnings != null && |
165 expectedWarnings != diagnosticCollector.warnings.length) { | 165 expectedWarnings != diagnosticCollector.warnings.length) { |
166 throw "unexpected warnings during compilation " | 166 throw "unexpected warnings during compilation " |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 | 284 |
285 /// Create a new [MockCompiler] and apply it asynchronously to [f]. | 285 /// Create a new [MockCompiler] and apply it asynchronously to [f]. |
286 static Future create(f(MockCompiler compiler)) { | 286 static Future create(f(MockCompiler compiler)) { |
287 MockCompiler compiler = new MockCompiler.internal(); | 287 MockCompiler compiler = new MockCompiler.internal(); |
288 return compiler.init().then((_) => f(compiler)); | 288 return compiler.init().then((_) => f(compiler)); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 class MockResolvedUriTranslator implements ResolvedUriTranslator { | 292 class MockResolvedUriTranslator implements ResolvedUriTranslator { |
293 static final _emptySet = new Set(); | 293 static final dynamic _emptySet = new Set(); |
294 | 294 |
295 Uri translate(LibraryElement importingLibrary, Uri resolvedUri, | 295 Uri translate(LibraryElement importingLibrary, Uri resolvedUri, |
296 Spannable spannable) => | 296 Spannable spannable) => |
297 resolvedUri; | 297 resolvedUri; |
298 Set<Uri> get disallowedLibraryUris => _emptySet; | 298 Set<Uri> get disallowedLibraryUris => _emptySet; |
299 bool get mockableLibraryUsed => false; | 299 bool get mockableLibraryUsed => false; |
300 Map<String, Uri> get sdkLibraries => const <String, Uri>{}; | 300 Map<String, Uri> get sdkLibraries => const <String, Uri>{}; |
301 } | 301 } |
302 | 302 |
303 class CollectingTreeElements extends TreeElementMapping { | 303 class CollectingTreeElements extends TreeElementMapping { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 trustTypeAnnotations: trustTypeAnnotations, | 394 trustTypeAnnotations: trustTypeAnnotations, |
395 enableTypeAssertions: enableTypeAssertions, | 395 enableTypeAssertions: enableTypeAssertions, |
396 enableUserAssertions: enableUserAssertions, | 396 enableUserAssertions: enableUserAssertions, |
397 expectedErrors: expectedErrors, | 397 expectedErrors: expectedErrors, |
398 expectedWarnings: expectedWarnings, | 398 expectedWarnings: expectedWarnings, |
399 outputProvider: outputProvider); | 399 outputProvider: outputProvider); |
400 compiler.registerSource(uri, code); | 400 compiler.registerSource(uri, code); |
401 compiler.diagnosticHandler = createHandler(compiler, code); | 401 compiler.diagnosticHandler = createHandler(compiler, code); |
402 return compiler; | 402 return compiler; |
403 } | 403 } |
OLD | NEW |