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

Side by Side Diff: tests/compiler/dart2js/patch_test.dart

Issue 886773004: Supported versioned patching. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import "package:compiler/src/dart2jslib.dart"; 8 import "package:compiler/src/dart2jslib.dart";
9 import "package:compiler/src/elements/elements.dart"; 9 import "package:compiler/src/elements/elements.dart";
10 import "package:compiler/src/tree/tree.dart"; 10 import "package:compiler/src/tree/tree.dart";
11 import "mock_compiler.dart"; 11 import "mock_compiler.dart";
12 import "mock_libraries.dart"; 12 import "mock_libraries.dart";
13 import 'package:compiler/src/elements/modelx.dart'; 13 import 'package:compiler/src/elements/modelx.dart';
14 14
15 Future<Compiler> applyPatch(String script, String patch, 15 Future<Compiler> applyPatch(String script, String patch,
16 {bool analyzeAll: false, bool analyzeOnly: false, 16 {bool analyzeAll: false,
17 bool runCompiler: false, String main: ""}) { 17 bool analyzeOnly: false,
18 bool runCompiler: false,
19 String main: "",
20 String patchVersion}) {
18 Map<String, String> core = <String, String>{'script': script}; 21 Map<String, String> core = <String, String>{'script': script};
19 MockCompiler compiler = new MockCompiler.internal(coreSource: core, 22 MockCompiler compiler = new MockCompiler.internal(coreSource: core,
20 analyzeAll: analyzeAll, 23 analyzeAll: analyzeAll,
21 analyzeOnly: analyzeOnly); 24 analyzeOnly: analyzeOnly,
25 patchVersion: patchVersion);
26 compiler.diagnosticHandler = createHandler(compiler, '');
22 var uri = Uri.parse("patch:core"); 27 var uri = Uri.parse("patch:core");
23 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch"); 28 compiler.registerSource(uri, "$DEFAULT_PATCH_CORE_SOURCE\n$patch");
24 var future; 29 var future;
25 if (runCompiler) { 30 if (runCompiler) {
26 future = compiler.runCompiler(null, main); 31 future = compiler.runCompiler(null, main);
27 } else { 32 } else {
28 future = compiler.init(main); 33 future = compiler.init(main);
29 } 34 }
30 return future.then((_) => compiler); 35 return future.then((_) => compiler);
31 } 36 }
(...skipping 27 matching lines...) Expand all
59 if (!expectIsFound) { 64 if (!expectIsFound) {
60 Expect.isNull(element); 65 Expect.isNull(element);
61 return element; 66 return element;
62 } 67 }
63 Expect.isNotNull(element); 68 Expect.isNotNull(element);
64 if (expectIsGetter) { 69 if (expectIsGetter) {
65 Expect.isTrue(element is AbstractFieldElement); 70 Expect.isTrue(element is AbstractFieldElement);
66 Expect.isNotNull(element.getter); 71 Expect.isNotNull(element.getter);
67 element = element.getter; 72 element = element.getter;
68 } 73 }
69 Expect.equals(expectIsPatched, element.isPatched); 74 Expect.equals(expectIsPatched, element.isPatched,
75 'Unexpected: $element.isPatched = ${element.isPatched}');
70 if (expectIsPatched) { 76 if (expectIsPatched) {
71 Expect.isNull(element.origin); 77 Expect.isNull(element.origin);
72 Expect.isNotNull(element.patch); 78 Expect.isNotNull(element.patch);
73 79
74 Expect.equals(element, element.declaration); 80 Expect.equals(element, element.declaration);
75 Expect.equals(element.patch, element.implementation); 81 Expect.equals(element.patch, element.implementation);
76 82
77 if (checkHasBody) { 83 if (checkHasBody) {
78 expectHasNoBody(compiler, element); 84 expectHasNoBody(compiler, element);
79 expectHasBody(compiler, element.patch); 85 expectHasBody(compiler, element.patch);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ensure(compiler, "test", compiler.coreLibrary.patch.find, 126 ensure(compiler, "test", compiler.coreLibrary.patch.find,
121 expectIsPatch: true, checkHasBody: true); 127 expectIsPatch: true, checkHasBody: true);
122 128
123 Expect.isTrue(compiler.warnings.isEmpty, 129 Expect.isTrue(compiler.warnings.isEmpty,
124 "Unexpected warnings: ${compiler.warnings}"); 130 "Unexpected warnings: ${compiler.warnings}");
125 Expect.isTrue(compiler.errors.isEmpty, 131 Expect.isTrue(compiler.errors.isEmpty,
126 "Unexpected errors: ${compiler.errors}"); 132 "Unexpected errors: ${compiler.errors}");
127 })); 133 }));
128 } 134 }
129 135
136
137 testPatchVersioned() {
138 String oldPatch = "test(){return 'string';}";
139 String newPatch = "test(){return 'new and improved string';}";
140
141 String patchSource =
142 """
143 @patch_old $oldPatch
144 @patch_new $newPatch
145 """;
146
147 test(String patchVersion,
148 {String patchText,
149 bool expectIsPatched: true,
150 String expectedError,
151 String defaultPatch: '',
152 String expectedInternalError}) {
153 asyncTest(() => applyPatch(
154 "external test();",
155 """
156 $defaultPatch
157 $patchSource
158 """,
159 patchVersion: patchVersion).then((compiler) {
160 Element origin =
161 ensure(compiler, "test", compiler.coreLibrary.find,
162 expectIsPatched: expectIsPatched, checkHasBody: true);
163 if (expectIsPatched) {
164 AstElement patch =
165 ensure(compiler, "test", compiler.coreLibrary.patch.find,
166 expectIsPatch: true, checkHasBody: true);
167 Expect.equals(origin.patch, patch);
168 Expect.equals(patch.origin, origin);
169 Expect.equals(patchText, patch.node.toString());
170 }
171
172 compiler.analyzeElement(origin);
173 compiler.enqueuer.resolution.emptyDeferredTaskQueue();
174
175 Expect.isTrue(compiler.warnings.isEmpty,
176 "Unexpected warnings: ${compiler.warnings}");
177 if (expectedError != null) {
178 Expect.equals(expectedError,
179 compiler.errors[0].message.toString());
180 } else {
181 Expect.isTrue(compiler.errors.isEmpty,
182 "Unexpected errors: ${compiler.errors}");
183 }
184 }).catchError((error) {
185 if (expectedInternalError != null) {
186 Expect.equals(
187 'Internal Error: $expectedInternalError', error.toString());
188 } else {
189 throw error;
190 }
191 }));
192 }
193
194 test('old', patchText: oldPatch);
195 test('new', patchText: newPatch);
196 test('unknown', expectIsPatched: false,
197 expectedError: 'External method without an implementation.');
198 test('old',
199 defaultPatch: "@patch test(){}",
200 expectedInternalError: "Trying to patch a function more than once.");
201 }
202
130 testPatchConstructor() { 203 testPatchConstructor() {
131 asyncTest(() => applyPatch( 204 asyncTest(() => applyPatch(
132 """ 205 """
133 class Class { 206 class Class {
134 external Class(); 207 external Class();
135 } 208 }
136 """, 209 """,
137 """ 210 """
138 @patch class Class { 211 @patch class Class {
139 @patch Class(); 212 @patch Class();
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 class B extends A { 937 class B extends A {
865 B() : super(); 938 B() : super();
866 external B.patchTarget(); 939 external B.patchTarget();
867 external factory B.reflectBack(); 940 external factory B.reflectBack();
868 B.originTarget() : super(); 941 B.originTarget() : super();
869 } 942 }
870 """; 943 """;
871 String patch = """ 944 String patch = """
872 @patch class B { 945 @patch class B {
873 B.patchTarget() : super(); 946 B.patchTarget() : super();
874 factory B.reflectBack() : B.originTarget; 947 factory B.reflectBack() = B.originTarget;
875 } 948 }
876 """; 949 """;
877 950
878 asyncTest(() => applyPatch(origin, patch, analyzeAll: true, 951 asyncTest(() => applyPatch(origin, patch, analyzeAll: true,
879 analyzeOnly: true, runCompiler: true).then((compiler) { 952 analyzeOnly: true, runCompiler: true).then((compiler) {
880 ClassElement clsA = compiler.coreLibrary.find("A"); 953 ClassElement clsA = compiler.coreLibrary.find("A");
881 ClassElement clsB = compiler.coreLibrary.find("B"); 954 ClassElement clsB = compiler.coreLibrary.find("B");
882 955
883 Selector forwardCall = new Selector.callConstructor("forward", 956 Selector forwardCall = new Selector.callConstructor("forward",
884 compiler.coreLibrary); 957 compiler.coreLibrary);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 testPatchConstructor(); 991 testPatchConstructor();
919 testPatchRedirectingConstructor(); 992 testPatchRedirectingConstructor();
920 testPatchFunction(); 993 testPatchFunction();
921 testPatchMember(); 994 testPatchMember();
922 testPatchGetter(); 995 testPatchGetter();
923 testRegularMember(); 996 testRegularMember();
924 testGhostMember(); 997 testGhostMember();
925 testInjectFunction(); 998 testInjectFunction();
926 testPatchSignatureCheck(); 999 testPatchSignatureCheck();
927 1000
1001 testPatchVersioned();
1002
928 testExternalWithoutImplementationTopLevel(); 1003 testExternalWithoutImplementationTopLevel();
929 testExternalWithoutImplementationMember(); 1004 testExternalWithoutImplementationMember();
930 1005
931 testIsSubclass(); 1006 testIsSubclass();
932 1007
933 testPatchNonExistingTopLevel(); 1008 testPatchNonExistingTopLevel();
934 testPatchNonExistingMember(); 1009 testPatchNonExistingMember();
935 testPatchNonPatchablePatch(); 1010 testPatchNonPatchablePatch();
936 testPatchNonPatchableOrigin(); 1011 testPatchNonPatchableOrigin();
937 testPatchNonExternalTopLevel(); 1012 testPatchNonExternalTopLevel();
938 testPatchNonExternalMember(); 1013 testPatchNonExternalMember();
939 testPatchNonClass(); 1014 testPatchNonClass();
940 testPatchNonGetter(); 1015 testPatchNonGetter();
941 testPatchNoGetter(); 1016 testPatchNoGetter();
942 testPatchNonSetter(); 1017 testPatchNonSetter();
943 testPatchNoSetter(); 1018 testPatchNoSetter();
944 testPatchNonFunction(); 1019 testPatchNonFunction();
945 1020
946 testPatchAndSelector(); 1021 testPatchAndSelector();
947 1022
948 testEffectiveTarget(); /// bug: ok 1023 testEffectiveTarget(); /// bug: ok
949 1024
950 testAnalyzeAllInjectedMembers(); 1025 testAnalyzeAllInjectedMembers();
951 testTypecheckPatchedMembers(); 1026 testTypecheckPatchedMembers();
952 } 1027 }
OLDNEW
« pkg/compiler/lib/src/js_backend/js_backend.dart ('K') | « tests/compiler/dart2js/mock_libraries.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698