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

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

Issue 11864010: Improve checking of patches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 720c85dd479edd31e61b2fc087c2d66afd0b668a..81f02d951e1acda5a997bc0c19b784b5029caf9c 100644
--- a/tests/compiler/dart2js/patch_test.dart
+++ b/tests/compiler/dart2js/patch_test.dart
@@ -44,7 +44,8 @@ Element ensure(compiler,
bool isPatch: false,
bool isMethod: true,
bool isGetter: false,
- bool isFound: true}) {
+ bool isFound: true,
+ bool isRegular: false}) {
ngeoffray 2013/01/11 11:46:12 What's 'isRegular'? Maybe add a comment.
Johnni Winther 2013/01/29 09:30:56 A regular member is one that is neither patched no
var element = lookup(buildSourceString(name));
if (!isFound) {
Expect.isNull(element);
@@ -86,7 +87,7 @@ Element ensure(compiler,
} else {
Expect.isTrue(element.isDeclaration);
}
- if (!(element.isPatched || element.isPatch)) {
+ if (isRegular) {
Expect.isNull(element.origin);
Expect.isNull(element.patch);
@@ -114,6 +115,37 @@ testPatchFunction() {
"Unexpected errors: ${compiler.errors}");
}
+testPatchConstructor() {
+ var compiler = applyPatch(
+ """
+ class Class {
+ external Class();
+ }
+ """,
+ """
+ patch class Class {
+ patch Class();
+ }
+ """);
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ isMethod: false, isPatched: true);
+ container.parseNode(compiler);
+ ensure(compiler, "Class", compiler.coreLibrary.patch.find,
+ isMethod: false, isPatch: true);
+
+
+
+ ensure(compiler, "Class", (name) => container.localScope[name],
+ isMethod: false, isPatched: true);
+ ensure(compiler, "Class", (name) => container.patch.localScope[name],
+ isMethod: false, isPatch: true);
+
+ Expect.isTrue(compiler.warnings.isEmpty,
+ "Unexpected warnings: ${compiler.warnings}");
+ Expect.isTrue(compiler.errors.isEmpty,
+ "Unexpected errors: ${compiler.errors}");
+}
+
testPatchMember() {
var compiler = applyPatch(
"""
@@ -192,8 +224,9 @@ testRegularMember() {
ensure(compiler, "Class", compiler.coreLibrary.patch.find,
isMethod: false, isPatch: true);
- ensure(compiler, "regular", container.lookupLocalMember);
- ensure(compiler, "regular", container.patch.lookupLocalMember);
+ ensure(compiler, "regular", container.lookupLocalMember, isRegular: true);
+ ensure(compiler, "regular", container.patch.lookupLocalMember,
+ isRegular: true);
Expect.isTrue(compiler.warnings.isEmpty,
"Unexpected warnings: ${compiler.warnings}");
@@ -219,7 +252,8 @@ testGhostMember() {
isMethod: false, isPatch: true);
ensure(compiler, "ghost", container.lookupLocalMember, isFound: false);
- ensure(compiler, "ghost", container.patch.lookupLocalMember);
+ ensure(compiler, "ghost", container.patch.lookupLocalMember,
+ isRegular: true);
Expect.isTrue(compiler.warnings.isEmpty,
"Unexpected warnings: ${compiler.warnings}");
@@ -237,7 +271,8 @@ testInjectFunction() {
isFound: false);
ensure(compiler,
"_function",
- compiler.coreLibrary.patch.find);
+ compiler.coreLibrary.patch.find,
+ isRegular: true);
Expect.isTrue(compiler.warnings.isEmpty,
"Unexpected warnings: ${compiler.warnings}");
@@ -355,7 +390,233 @@ testPatchSignatureCheck() {
print('method8:${compiler.errors}');
}
+testPatchNonExistingTopLevel() {
+ var compiler = applyPatch(
+ """
ahe 2013/01/21 10:53:35 Why a multiline string?
Johnni Winther 2013/01/29 09:30:56 Expanded with the missing class declaration.
+ """,
+ """
+ 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);
ahe 2013/01/21 10:53:35 I don't think you're testing the positions. This a
+}
+
+testPatchNonExistingMember() {
+ var compiler = applyPatch(
+ """
+ class Class {}
+ """,
+ """
+ patch class Class {
+ patch void foo() {}
+ }
+ """);
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ isMethod: false, isPatched: 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(
+ """
+ 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);
ahe 2013/01/21 10:53:35 This, and many tests below, do not test that you g
Johnni Winther 2013/01/29 09:30:56 Generally a good idea, but not easy currently.
+}
+
+testPatchNonPatchableOrigin() {
+ var compiler = applyPatch(
+ """
+ external var foo;
+ """,
+ """
+ patch get foo => 0;
+ """);
+ ensure(compiler, "foo", compiler.coreLibrary.find, isMethod: false);
+
+ 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(
+ """
+ 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);
+}
+
+testPatchNonExternalMember() {
+ var compiler = applyPatch(
+ """
+ class Class {
+ void foo() {}
+ }
+ """,
+ """
+ patch class Class {
+ patch void foo() {}
+ }
+ """);
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find,
+ isMethod: false, isPatched: 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(
+ """
+ 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);
+}
+
+testPatchNonGetter() {
+ var compiler = 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);
+}
+
+testPatchNoGetter() {
+ var compiler = 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);
+}
+
+testPatchNonSetter() {
+ var compiler = 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);
+}
+
+testPatchNoSetter() {
+ var compiler = 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);
+}
+
+testPatchNonFunction() {
+ var compiler = 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);
+}
+
main() {
+ testPatchConstructor();
testPatchFunction();
testPatchMember();
testPatchGetter();
@@ -363,4 +624,17 @@ main() {
testGhostMember();
testInjectFunction();
testPatchSignatureCheck();
+
+ testPatchNonExistingTopLevel();
+ testPatchNonExistingMember();
+ testPatchNonPatchablePatch();
+ testPatchNonPatchableOrigin();
+ testPatchNonExternalTopLevel();
+ testPatchNonExternalMember();
+ testPatchNonClass();
+ testPatchNonGetter();
+ testPatchNoGetter();
+ testPatchNonSetter();
+ testPatchNoSetter();
+ testPatchNonFunction();
}

Powered by Google App Engine
This is Rietveld 408576698