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

Unified Diff: tests/compiler/dart2js/patch_test.dart

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: tests/compiler/dart2js/patch_test.dart
diff --git a/tests/compiler/dart2js/patch_test.dart b/tests/compiler/dart2js/patch_test.dart
index f476e1e77b9cd2167e8692c742aadb8180f4a7ae..4d17b23ab728dab37d8500c9182ef190a9a4f69b 100644
--- a/tests/compiler/dart2js/patch_test.dart
+++ b/tests/compiler/dart2js/patch_test.dart
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'dart:async';
import "package:expect/expect.dart";
import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart";
@@ -10,8 +11,8 @@ import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
import "mock_compiler.dart";
import "parser_helper.dart";
-Compiler applyPatch(String script, String patch,
- {bool analyzeAll: false, bool analyzeOnly: false}) {
+Future<Compiler> applyPatch(String script, String patch,
+ {bool analyzeAll: false, bool analyzeOnly: false}) {
String core = "$DEFAULT_CORELIB\n$script";
MockCompiler compiler = new MockCompiler(coreSource: core,
analyzeAll: analyzeAll,
@@ -19,9 +20,11 @@ Compiler applyPatch(String script, String patch,
var uri = Uri.parse("core.dartp");
compiler.sourceFiles[uri.toString()] = new MockFile(patch);
var handler = new LibraryDependencyHandler(compiler);
- compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary);
- handler.computeExports();
- return compiler;
+ return compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary)
+ .then((_) {
+ handler.computeExports();
+ return compiler;
+ });
}
void expectHasBody(compiler, Element element) {
@@ -106,22 +109,23 @@ Element ensure(compiler,
}
testPatchFunction() {
- var compiler = applyPatch(
+ applyPatch(
"external test();",
- "patch test() { return 'string'; } ");
- ensure(compiler, "test", compiler.coreLibrary.find,
- expectIsPatched: true, checkHasBody: true);
- ensure(compiler, "test", compiler.coreLibrary.patch.find,
- expectIsPatch: true, checkHasBody: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ "patch test() { return 'string'; } ").then((compiler) {
+ ensure(compiler, "test", compiler.coreLibrary.find,
+ expectIsPatched: true, checkHasBody: true);
+ ensure(compiler, "test", compiler.coreLibrary.patch.find,
+ expectIsPatch: true, checkHasBody: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testPatchConstructor() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
external Class();
@@ -131,34 +135,35 @@ testPatchConstructor() {
patch class Class {
patch Class();
}
- """);
- var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- classOrigin.ensureResolved(compiler);
- var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
- expectIsPatch: true);
-
- Expect.equals(classPatch, classOrigin.patch);
- Expect.equals(classOrigin, classPatch.origin);
-
- var constructorOrigin = ensure(compiler, "Class",
- (name) => classOrigin.localLookup(name),
- expectIsPatched: true);
- var constructorPatch = ensure(compiler, "Class",
- (name) => classPatch.localLookup(name),
- expectIsPatch: true);
-
- Expect.equals(constructorPatch, constructorOrigin.patch);
- Expect.equals(constructorOrigin, constructorPatch.origin);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ """).then((compiler) {
+ var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ classOrigin.ensureResolved(compiler);
+ var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
+ expectIsPatch: true);
+
+ Expect.equals(classPatch, classOrigin.patch);
+ Expect.equals(classOrigin, classPatch.origin);
+
+ var constructorOrigin = ensure(compiler, "Class",
+ (name) => classOrigin.localLookup(name),
+ expectIsPatched: true);
+ var constructorPatch = ensure(compiler, "Class",
+ (name) => classPatch.localLookup(name),
+ expectIsPatch: true);
+
+ Expect.equals(constructorPatch, constructorOrigin.patch);
+ Expect.equals(constructorOrigin, constructorPatch.origin);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testPatchMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
external String toString();
@@ -168,26 +173,27 @@ testPatchMember() {
patch class Class {
patch String toString() => 'string';
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
- ensure(compiler, "Class", compiler.coreLibrary.patch.find,
- expectIsPatch: true);
-
- ensure(compiler, "toString", container.lookupLocalMember,
- expectIsPatched: true, checkHasBody: true);
- ensure(compiler, "toString", container.patch.lookupLocalMember,
- expectIsPatch: true, checkHasBody: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+ ensure(compiler, "Class", compiler.coreLibrary.patch.find,
+ expectIsPatch: true);
+
+ ensure(compiler, "toString", container.lookupLocalMember,
+ expectIsPatched: true, checkHasBody: true);
+ ensure(compiler, "toString", container.patch.lookupLocalMember,
+ expectIsPatch: true, checkHasBody: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testPatchGetter() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
external int get field;
@@ -197,31 +203,32 @@ testPatchGetter() {
patch class Class {
patch int get field => 5;
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
- ensure(compiler,
- "field",
- container.lookupLocalMember,
- expectIsGetter: true,
- expectIsPatched: true,
- checkHasBody: true);
- ensure(compiler,
- "field",
- container.patch.lookupLocalMember,
- expectIsGetter: true,
- expectIsPatch: true,
- checkHasBody: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+ ensure(compiler,
+ "field",
+ container.lookupLocalMember,
+ expectIsGetter: true,
+ expectIsPatched: true,
+ checkHasBody: true);
+ ensure(compiler,
+ "field",
+ container.patch.lookupLocalMember,
+ expectIsGetter: true,
+ expectIsPatch: true,
+ checkHasBody: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testRegularMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
void regular() {}
@@ -230,26 +237,27 @@ testRegularMember() {
"""
patch class Class {
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
- ensure(compiler, "Class", compiler.coreLibrary.patch.find,
- expectIsPatch: true);
-
- ensure(compiler, "regular", container.lookupLocalMember,
- checkHasBody: true, expectIsRegular: true);
- ensure(compiler, "regular", container.patch.lookupLocalMember,
- checkHasBody: true, expectIsRegular: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+ ensure(compiler, "Class", compiler.coreLibrary.patch.find,
+ expectIsPatch: true);
+
+ ensure(compiler, "regular", container.lookupLocalMember,
+ checkHasBody: true, expectIsRegular: true);
+ ensure(compiler, "regular", container.patch.lookupLocalMember,
+ checkHasBody: true, expectIsRegular: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testGhostMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
}
@@ -258,45 +266,47 @@ testGhostMember() {
patch class Class {
void ghost() {}
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
- ensure(compiler, "Class", compiler.coreLibrary.patch.find,
- expectIsPatch: true);
-
- ensure(compiler, "ghost", container.lookupLocalMember,
- expectIsFound: false);
- ensure(compiler, "ghost", container.patch.lookupLocalMember,
- checkHasBody: true, expectIsRegular: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+ ensure(compiler, "Class", compiler.coreLibrary.patch.find,
+ expectIsPatch: true);
+
+ ensure(compiler, "ghost", container.lookupLocalMember,
+ expectIsFound: false);
+ ensure(compiler, "ghost", container.patch.lookupLocalMember,
+ checkHasBody: true, expectIsRegular: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testInjectFunction() {
- var compiler = applyPatch(
+ applyPatch(
"",
- "int _function() => 5;");
- ensure(compiler,
- "_function",
- compiler.coreLibrary.find,
- expectIsFound: false);
- ensure(compiler,
- "_function",
- compiler.coreLibrary.patch.find,
- checkHasBody: true, expectIsRegular: true);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- Expect.isTrue(compiler.errors.isEmpty,
- "Unexpected errors: ${compiler.errors}");
+ "int _function() => 5;").then((compiler) {
+ ensure(compiler,
+ "_function",
+ compiler.coreLibrary.find,
+ expectIsFound: false);
+ ensure(compiler,
+ "_function",
+ compiler.coreLibrary.patch.find,
+ checkHasBody: true, expectIsRegular: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+ });
}
testPatchSignatureCheck() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
external String method1();
@@ -326,72 +336,78 @@ testPatchSignatureCheck() {
patch void method10([int str]) {}
patch void method11({int str}) {}
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.ensureResolved(compiler);
- container.parseNode(compiler);
-
- void expect(String methodName, List warnings, List errors) {
- compiler.warnings.clear();
- compiler.errors.clear();
- compiler.resolver.resolveMethodElement(
- ensure(compiler, methodName, container.lookupLocalMember,
- expectIsPatched: true, checkHasBody: true));
- Expect.equals(warnings.length, compiler.warnings.length,
- "Unexpected warnings: ${compiler.warnings} on $methodName");
- for (int i = 0 ; i < warnings.length ; i++) {
- Expect.equals(warnings[i], compiler.warnings[i].message.kind);
- }
- Expect.equals(errors.length, compiler.errors.length,
- "Unexpected errors: ${compiler.errors} on $methodName");
- for (int i = 0 ; i < errors.length ; i++) {
- Expect.equals(errors[i], compiler.errors[i].message.kind);
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.ensureResolved(compiler);
+ container.parseNode(compiler);
+
+ void expect(String methodName, List warnings, List errors) {
+ compiler.warnings.clear();
+ compiler.errors.clear();
+ compiler.resolver.resolveMethodElement(
+ ensure(compiler, methodName, container.lookupLocalMember,
+ expectIsPatched: true, checkHasBody: true));
+ Expect.equals(warnings.length, compiler.warnings.length,
+ "Unexpected warnings: ${compiler.warnings} on $methodName");
+ for (int i = 0 ; i < warnings.length ; i++) {
+ Expect.equals(warnings[i], compiler.warnings[i].message.kind);
+ }
+ Expect.equals(errors.length, compiler.errors.length,
+ "Unexpected errors: ${compiler.errors} on $methodName");
+ for (int i = 0 ; i < errors.length ; i++) {
+ Expect.equals(errors[i], compiler.errors[i].message.kind);
+ }
}
- }
- expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]);
- expect("method2", [], [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]);
- expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_MISMATCH]);
- expect("method4", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
- expect("method5", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
- expect("method6", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]);
- expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_MISMATCH]);
- expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_MISMATCH]);
- expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
- expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
- expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER],
- [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
+ expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]);
+ expect("method2", [],
+ [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]);
+ expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_MISMATCH]);
+ expect("method4", [],
+ [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
+ expect("method5", [],
+ [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
+ expect("method6", [],
+ [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]);
+ expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_MISMATCH]);
+ expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_MISMATCH]);
+ expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
+ expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
+ expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER],
+ [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
+ });
}
testExternalWithoutImplementationTopLevel() {
- var compiler = applyPatch(
+ applyPatch(
"""
external void foo();
""",
"""
// patch void foo() {}
- """);
- var function = ensure(compiler, "foo", compiler.coreLibrary.find);
- compiler.resolver.resolve(function);
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind ==
- MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
- Expect.equals('External method without an implementation.',
- compiler.errors[0].message.toString());
+ """).then((compiler) {
+ var function = ensure(compiler, "foo", compiler.coreLibrary.find);
+ compiler.resolver.resolve(function);
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind ==
+ MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
+ Expect.equals('External method without an implementation.',
+ compiler.errors[0].message.toString());
+ });
}
testExternalWithoutImplementationMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
external void foo();
@@ -401,60 +417,63 @@ testExternalWithoutImplementationMember() {
patch class Class {
// patch void foo() {}
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
-
- compiler.warnings.clear();
- compiler.errors.clear();
- compiler.resolver.resolveMethodElement(
- ensure(compiler, "foo", container.lookupLocalMember));
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testExternalWithoutImplementationMember:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind ==
- MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
- Expect.equals('External method without an implementation.',
- compiler.errors[0].message.toString());
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+
+ compiler.warnings.clear();
+ compiler.errors.clear();
+ compiler.resolver.resolveMethodElement(
+ ensure(compiler, "foo", container.lookupLocalMember));
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testExternalWithoutImplementationMember:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind ==
+ MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
+ Expect.equals('External method without an implementation.',
+ compiler.errors[0].message.toString());
+ });
}
testIsSubclass() {
- var compiler = applyPatch(
+ applyPatch(
"""
class A {}
""",
"""
patch class A {}
- """);
- ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
- expectIsPatched: true);
- ClassElement patch = cls.patch;
- Expect.isTrue(cls != patch);
- Expect.isTrue(cls.isSubclassOf(patch));
- Expect.isTrue(patch.isSubclassOf(cls));
+ """).then((compiler) {
+ ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ ClassElement patch = cls.patch;
+ Expect.isTrue(cls != patch);
+ Expect.isTrue(cls.isSubclassOf(patch));
+ Expect.isTrue(patch.isSubclassOf(cls));
+ });
}
testPatchNonExistingTopLevel() {
- var compiler = applyPatch(
+ applyPatch(
"""
// class Class {}
""",
"""
patch class Class {}
- """);
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testPatchNonExistingTopLevel:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
+ """).then((compiler) {
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testPatchNonExistingTopLevel:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
+ });
}
testPatchNonExistingMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {}
""",
@@ -462,75 +481,79 @@ testPatchNonExistingMember() {
patch class Class {
patch void foo() {}
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testPatchNonExistingMember:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testPatchNonExistingMember:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
+ });
}
testPatchNonPatchablePatch() {
- var compiler = applyPatch(
+ applyPatch(
"""
external get foo;
""",
"""
patch var foo;
- """);
- ensure(compiler, "foo", compiler.coreLibrary.find);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testPatchNonPatchablePatch:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
+ """).then((compiler) {
+ ensure(compiler, "foo", compiler.coreLibrary.find);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testPatchNonPatchablePatch:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
+ });
}
testPatchNonPatchableOrigin() {
- var compiler = applyPatch(
+ applyPatch(
"""
external var foo;
""",
"""
patch get foo => 0;
- """);
- ensure(compiler, "foo", compiler.coreLibrary.find);
-
- Expect.isTrue(compiler.warnings.isEmpty,
- "Unexpected warnings: ${compiler.warnings}");
- print('testPatchNonPatchableOrigin:${compiler.errors}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
+ """).then((compiler) {
+ ensure(compiler, "foo", compiler.coreLibrary.find);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ print('testPatchNonPatchableOrigin:${compiler.errors}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
+ });
}
testPatchNonExternalTopLevel() {
- var compiler = applyPatch(
+ applyPatch(
"""
void foo() {}
""",
"""
patch void foo() {}
- """);
- print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
- print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
+ """).then((compiler) {
+ print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
+ print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(compiler.warnings[0].message.kind ==
+ MessageKind.PATCH_POINT_TO_FUNCTION);
+ });
}
testPatchNonExternalMember() {
- var compiler = applyPatch(
+ applyPatch(
"""
class Class {
void foo() {}
@@ -540,131 +563,138 @@ testPatchNonExternalMember() {
patch class Class {
patch void foo() {}
}
- """);
- var container = ensure(compiler, "Class", compiler.coreLibrary.find,
- expectIsPatched: true);
- container.parseNode(compiler);
-
- print('testPatchNonExternalMember.errors:${compiler.errors}');
- print('testPatchNonExternalMember.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
+ """).then((compiler) {
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ container.parseNode(compiler);
+
+ print('testPatchNonExternalMember.errors:${compiler.errors}');
+ print('testPatchNonExternalMember.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(compiler.warnings[0].message.kind ==
+ MessageKind.PATCH_POINT_TO_FUNCTION);
+ });
}
testPatchNonClass() {
- var compiler = applyPatch(
+ applyPatch(
"""
external void Class() {}
""",
"""
patch class Class {}
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
+ });
}
testPatchNonGetter() {
- var compiler = applyPatch(
+ applyPatch(
"""
external void foo() {}
""",
"""
patch get foo => 0;
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
+ });
}
testPatchNoGetter() {
- var compiler = applyPatch(
+ applyPatch(
"""
external set foo(var value) {}
""",
"""
patch get foo => 0;
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
+ });
}
testPatchNonSetter() {
- var compiler = applyPatch(
+ applyPatch(
"""
external void foo() {}
""",
"""
patch set foo(var value) {}
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
+ });
}
testPatchNoSetter() {
- var compiler = applyPatch(
+ applyPatch(
"""
external get foo;
""",
"""
patch set foo(var value) {}
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
+ });
}
testPatchNonFunction() {
- var compiler = applyPatch(
+ applyPatch(
"""
external get foo;
""",
"""
patch void foo() {}
- """);
- print('testPatchNonClass.errors:${compiler.errors}');
- print('testPatchNonClass.warnings:${compiler.warnings}');
- Expect.equals(1, compiler.errors.length);
- Expect.isTrue(
- compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
- Expect.equals(1, compiler.warnings.length);
- Expect.isTrue(
- compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
+ """).then((compiler) {
+ print('testPatchNonClass.errors:${compiler.errors}');
+ print('testPatchNonClass.warnings:${compiler.warnings}');
+ Expect.equals(1, compiler.errors.length);
+ Expect.isTrue(
+ compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
+ Expect.equals(1, compiler.warnings.length);
+ Expect.isTrue(
+ compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
+ });
}
testPatchAndSelector() {
- var compiler = applyPatch(
+ applyPatch(
"""
class A {
external void clear();
@@ -677,45 +707,46 @@ testPatchAndSelector() {
int method() => 0;
patch void clear() {}
}
- """);
- ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
- expectIsPatched: true);
- cls.ensureResolved(compiler);
-
- ensure(compiler, "method", cls.patch.lookupLocalMember,
- checkHasBody: true, expectIsRegular: true);
-
- ensure(compiler, "clear", cls.lookupLocalMember,
- checkHasBody: true, expectIsPatched: true);
-
- compiler.phase = Compiler.PHASE_DONE_RESOLVING;
-
- // Check that a method just in the patch class is a target for a
- // typed selector.
- var selector = new Selector.call(
- buildSourceString('method'), compiler.coreLibrary, 0);
- var typedSelector = new TypedSelector.exact(cls.rawType, selector);
- Element method =
- cls.implementation.lookupLocalMember(buildSourceString('method'));
- Expect.isTrue(selector.applies(method, compiler));
- Expect.isTrue(typedSelector.applies(method, compiler));
-
- // Check that the declaration method in the declaration class is a target
- // for a typed selector.
- selector = new Selector.call(
- buildSourceString('clear'), compiler.coreLibrary, 0);
- typedSelector = new TypedSelector.exact(cls.rawType, selector);
- method = cls.lookupLocalMember(buildSourceString('clear'));
- Expect.isTrue(selector.applies(method, compiler));
- Expect.isTrue(typedSelector.applies(method, compiler));
-
- // Check that the declaration method in the declaration class is a target
- // for a typed selector on a subclass.
- cls = ensure(compiler, "B", compiler.coreLibrary.find);
- cls.ensureResolved(compiler);
- typedSelector = new TypedSelector.exact(cls.rawType, selector);
- Expect.isTrue(selector.applies(method, compiler));
- Expect.isTrue(typedSelector.applies(method, compiler));
+ """).then((compiler) {
+ ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
+ expectIsPatched: true);
+ cls.ensureResolved(compiler);
+
+ ensure(compiler, "method", cls.patch.lookupLocalMember,
+ checkHasBody: true, expectIsRegular: true);
+
+ ensure(compiler, "clear", cls.lookupLocalMember,
+ checkHasBody: true, expectIsPatched: true);
+
+ compiler.phase = Compiler.PHASE_DONE_RESOLVING;
+
+ // Check that a method just in the patch class is a target for a
+ // typed selector.
+ var selector = new Selector.call(
+ buildSourceString('method'), compiler.coreLibrary, 0);
+ var typedSelector = new TypedSelector.exact(cls.rawType, selector);
+ Element method =
+ cls.implementation.lookupLocalMember(buildSourceString('method'));
+ Expect.isTrue(selector.applies(method, compiler));
+ Expect.isTrue(typedSelector.applies(method, compiler));
+
+ // Check that the declaration method in the declaration class is a target
+ // for a typed selector.
+ selector = new Selector.call(
+ buildSourceString('clear'), compiler.coreLibrary, 0);
+ typedSelector = new TypedSelector.exact(cls.rawType, selector);
+ method = cls.lookupLocalMember(buildSourceString('clear'));
+ Expect.isTrue(selector.applies(method, compiler));
+ Expect.isTrue(typedSelector.applies(method, compiler));
+
+ // Check that the declaration method in the declaration class is a target
+ // for a typed selector on a subclass.
+ cls = ensure(compiler, "B", compiler.coreLibrary.find);
+ cls.ensureResolved(compiler);
+ typedSelector = new TypedSelector.exact(cls.rawType, selector);
+ Expect.isTrue(selector.applies(method, compiler));
+ Expect.isTrue(typedSelector.applies(method, compiler));
+ });
}
void testAnalyzeAllInjectedMembers() {
@@ -723,11 +754,13 @@ void testAnalyzeAllInjectedMembers() {
if (expectedWarnings == null) expectedWarnings = [];
if (expectedWarnings is! List) expectedWarnings = [expectedWarnings];
- var compiler = applyPatch('', patchText,
- analyzeAll: true, analyzeOnly: true);
- compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
- compiler.runCompiler(null);
- compareWarningKinds(patchText, expectedWarnings, compiler.warnings);
+ applyPatch('', patchText, analyzeAll: true,
+ analyzeOnly: true).then((compiler) {
+ compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
+ return compiler.runCompiler(null).then((_) {
+ compareWarningKinds(patchText, expectedWarnings, compiler.warnings);
+ });
+ });
}
expect('String s = 0;', MessageKind.NOT_ASSIGNABLE);
@@ -755,12 +788,14 @@ void testTypecheckPatchedMembers() {
String s = 0;
}
""";
- var compiler = applyPatch(originText, patchText,
- analyzeAll: true, analyzeOnly: true);
- compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
- compiler.runCompiler(null);
- compareWarningKinds(patchText,
- [MessageKind.NOT_ASSIGNABLE], compiler.warnings);
+ applyPatch(originText, patchText,
+ analyzeAll: true, analyzeOnly: true).then((compiler) {
+ compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
+ return compiler.runCompiler(null).then((_) {
+ compareWarningKinds(patchText,
+ [MessageKind.NOT_ASSIGNABLE], compiler.warnings);
+ });
+ });
}
main() {

Powered by Google App Engine
This is Rietveld 408576698