| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 List<WarningMessage> infos; | 256 List<WarningMessage> infos; |
| 257 List<WarningMessage> crashes; | 257 List<WarningMessage> crashes; |
| 258 /// Expected number of warnings. If `null`, the number of warnings is | 258 /// Expected number of warnings. If `null`, the number of warnings is |
| 259 /// not checked. | 259 /// not checked. |
| 260 final int expectedWarnings; | 260 final int expectedWarnings; |
| 261 /// Expected number of errors. If `null`, the number of errors is not checked. | 261 /// Expected number of errors. If `null`, the number of errors is not checked. |
| 262 final int expectedErrors; | 262 final int expectedErrors; |
| 263 final Map<String, SourceFile> sourceFiles; | 263 final Map<String, SourceFile> sourceFiles; |
| 264 Node parsedTree; | 264 Node parsedTree; |
| 265 | 265 |
| 266 MockCompiler({String coreSource: DEFAULT_CORELIB, | 266 MockCompiler.internal( |
| 267 String helperSource: DEFAULT_HELPERLIB, | 267 {String coreSource: DEFAULT_CORELIB, |
| 268 String interceptorsSource: DEFAULT_INTERCEPTORSLIB, | 268 String helperSource: DEFAULT_HELPERLIB, |
| 269 String isolateHelperSource: DEFAULT_ISOLATE_HELPERLIB, | 269 String interceptorsSource: DEFAULT_INTERCEPTORSLIB, |
| 270 bool enableTypeAssertions: false, | 270 String isolateHelperSource: DEFAULT_ISOLATE_HELPERLIB, |
| 271 bool enableMinification: false, | 271 bool enableTypeAssertions: false, |
| 272 bool enableConcreteTypeInference: false, | 272 bool enableMinification: false, |
| 273 int maxConcreteTypeSize: 5, | 273 bool enableConcreteTypeInference: false, |
| 274 bool disableTypeInference: false, | 274 int maxConcreteTypeSize: 5, |
| 275 bool analyzeAll: false, | 275 bool disableTypeInference: false, |
| 276 bool analyzeOnly: false, | 276 bool analyzeAll: false, |
| 277 bool emitJavaScript: true, | 277 bool analyzeOnly: false, |
| 278 bool preserveComments: false, | 278 bool emitJavaScript: true, |
| 279 // Our unit tests check code generation output that is | 279 bool preserveComments: false, |
| 280 // affected by inlining support. | 280 // Our unit tests check code generation output that is |
| 281 bool disableInlining: true, | 281 // affected by inlining support. |
| 282 int this.expectedWarnings, | 282 bool disableInlining: true, |
| 283 int this.expectedErrors}) | 283 int this.expectedWarnings, |
| 284 int this.expectedErrors}) |
| 284 : sourceFiles = new Map<String, SourceFile>(), | 285 : sourceFiles = new Map<String, SourceFile>(), |
| 285 super(enableTypeAssertions: enableTypeAssertions, | 286 super(enableTypeAssertions: enableTypeAssertions, |
| 286 enableMinification: enableMinification, | 287 enableMinification: enableMinification, |
| 287 enableConcreteTypeInference: enableConcreteTypeInference, | 288 enableConcreteTypeInference: enableConcreteTypeInference, |
| 288 maxConcreteTypeSize: maxConcreteTypeSize, | 289 maxConcreteTypeSize: maxConcreteTypeSize, |
| 289 disableTypeInferenceFlag: disableTypeInference, | 290 disableTypeInferenceFlag: disableTypeInference, |
| 290 analyzeAllFlag: analyzeAll, | 291 analyzeAllFlag: analyzeAll, |
| 291 analyzeOnly: analyzeOnly, | 292 analyzeOnly: analyzeOnly, |
| 292 emitJavaScript: emitJavaScript, | 293 emitJavaScript: emitJavaScript, |
| 293 preserveComments: preserveComments, | 294 preserveComments: preserveComments, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 318 // dynamic invocation the ArgumentTypesRegistry eventually iterates over | 319 // dynamic invocation the ArgumentTypesRegistry eventually iterates over |
| 319 // the interfaces of the Object class which would be 'null' if the class | 320 // the interfaces of the Object class which would be 'null' if the class |
| 320 // wasn't resolved. | 321 // wasn't resolved. |
| 321 objectClass.ensureResolved(this); | 322 objectClass.ensureResolved(this); |
| 322 | 323 |
| 323 this.disableInlining = disableInlining; | 324 this.disableInlining = disableInlining; |
| 324 | 325 |
| 325 deferredLoadTask = new MockDeferredLoadTask(this); | 326 deferredLoadTask = new MockDeferredLoadTask(this); |
| 326 } | 327 } |
| 327 | 328 |
| 329 /// Initialize the mock compiler with an empty main library. |
| 330 Future init() { |
| 331 // Stub for initialization. |
| 332 return new Future.value(); |
| 333 } |
| 334 |
| 328 Future runCompiler(Uri uri) { | 335 Future runCompiler(Uri uri) { |
| 329 return super.runCompiler(uri).then((result) { | 336 return super.runCompiler(uri).then((result) { |
| 330 if (expectedErrors != null && | 337 if (expectedErrors != null && |
| 331 expectedErrors != errors.length) { | 338 expectedErrors != errors.length) { |
| 332 throw "unexpected error during compilation ${errors}"; | 339 throw "unexpected error during compilation ${errors}"; |
| 333 } else if (expectedWarnings != null && | 340 } else if (expectedWarnings != null && |
| 334 expectedWarnings != warnings.length) { | 341 expectedWarnings != warnings.length) { |
| 335 throw "unexpected warnings during compilation ${warnings}"; | 342 throw "unexpected warnings during compilation ${warnings}"; |
| 336 } else { | 343 } else { |
| 337 return result; | 344 return result; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 if (sourceFile == null) throw new ArgumentError(uri); | 474 if (sourceFile == null) throw new ArgumentError(uri); |
| 468 return new Future.value(new Script(uri, uri, sourceFile)); | 475 return new Future.value(new Script(uri, uri, sourceFile)); |
| 469 } | 476 } |
| 470 | 477 |
| 471 Element lookupElementIn(ScopeContainerElement container, name) { | 478 Element lookupElementIn(ScopeContainerElement container, name) { |
| 472 Element element = container.localLookup(name); | 479 Element element = container.localLookup(name); |
| 473 return element != null | 480 return element != null |
| 474 ? element | 481 ? element |
| 475 : new ErroneousElementX(null, null, name, container); | 482 : new ErroneousElementX(null, null, name, container); |
| 476 } | 483 } |
| 484 |
| 485 /// Create a new [MockCompiler] and apply it asynchronously to [f]. |
| 486 static Future create(f(MockCompiler compiler)) { |
| 487 MockCompiler compiler = new MockCompiler.internal(); |
| 488 return compiler.init().then((_) => f(compiler)); |
| 489 } |
| 477 } | 490 } |
| 478 | 491 |
| 479 /// A function the checks [message]. If the check fails or if [message] is | 492 /// A function the checks [message]. If the check fails or if [message] is |
| 480 /// `null`, an error string is returned. Otherwise `null` is returned. | 493 /// `null`, an error string is returned. Otherwise `null` is returned. |
| 481 typedef String CheckMessage(Message message); | 494 typedef String CheckMessage(Message message); |
| 482 | 495 |
| 483 CheckMessage checkMessage(MessageKind kind, Map arguments) { | 496 CheckMessage checkMessage(MessageKind kind, Map arguments) { |
| 484 return (Message message) { | 497 return (Message message) { |
| 485 if (message == null) return '$kind'; | 498 if (message == null) return '$kind'; |
| 486 if (message.kind != kind) return 'Expected message $kind, found $message.'; | 499 if (message.kind != kind) return 'Expected message $kind, found $message.'; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 616 |
| 604 class MockElement extends FunctionElementX { | 617 class MockElement extends FunctionElementX { |
| 605 MockElement(Element enclosingElement) | 618 MockElement(Element enclosingElement) |
| 606 : super('', ElementKind.FUNCTION, Modifiers.EMPTY, | 619 : super('', ElementKind.FUNCTION, Modifiers.EMPTY, |
| 607 enclosingElement, false); | 620 enclosingElement, false); |
| 608 | 621 |
| 609 get node => null; | 622 get node => null; |
| 610 | 623 |
| 611 parseNode(_) => null; | 624 parseNode(_) => null; |
| 612 } | 625 } |
| OLD | NEW |