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

Side by Side 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: Updated cf. comments Created 7 years, 3 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
« no previous file with comments | « tests/compiler/dart2js/part_of_test.dart ('k') | tests/compiler/dart2js/private_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart";
6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
8 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 11 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
10 import "mock_compiler.dart"; 12 import "mock_compiler.dart";
11 import "parser_helper.dart"; 13 import "parser_helper.dart";
12 14
13 Compiler applyPatch(String script, String patch, 15 Future<Compiler> applyPatch(String script, String patch,
14 {bool analyzeAll: false, bool analyzeOnly: false}) { 16 {bool analyzeAll: false, bool analyzeOnly: false}) {
15 String core = "$DEFAULT_CORELIB\n$script"; 17 String core = "$DEFAULT_CORELIB\n$script";
16 MockCompiler compiler = new MockCompiler(coreSource: core, 18 MockCompiler compiler = new MockCompiler(coreSource: core,
17 analyzeAll: analyzeAll, 19 analyzeAll: analyzeAll,
18 analyzeOnly: analyzeOnly); 20 analyzeOnly: analyzeOnly);
19 var uri = Uri.parse("core.dartp"); 21 var uri = Uri.parse("core.dartp");
20 compiler.sourceFiles[uri.toString()] = new MockFile(patch); 22 compiler.sourceFiles[uri.toString()] = new MockFile(patch);
21 var handler = new LibraryDependencyHandler(compiler); 23 var handler = new LibraryDependencyHandler(compiler);
22 compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary); 24 return compiler.patchParser.patchLibrary(handler, uri, compiler.coreLibrary)
23 handler.computeExports(); 25 .then((_) {
24 return compiler; 26 handler.computeExports();
27 return compiler;
28 });
25 } 29 }
26 30
27 void expectHasBody(compiler, Element element) { 31 void expectHasBody(compiler, Element element) {
28 var node = element.parseNode(compiler); 32 var node = element.parseNode(compiler);
29 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 33 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
30 Expect.isNotNull(node.body); 34 Expect.isNotNull(node.body);
31 // If the element has a body it is either a Block or a Return statement, 35 // If the element has a body it is either a Block or a Return statement,
32 // both with different begin and end tokens. 36 // both with different begin and end tokens.
33 Expect.isTrue(node.body is Block || node.body is Return); 37 Expect.isTrue(node.body is Block || node.body is Return);
34 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken()); 38 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 103
100 if (checkHasBody) { 104 if (checkHasBody) {
101 expectHasBody(compiler, element); 105 expectHasBody(compiler, element);
102 } 106 }
103 } 107 }
104 Expect.isFalse(element.isPatched && element.isPatch); 108 Expect.isFalse(element.isPatched && element.isPatch);
105 return element; 109 return element;
106 } 110 }
107 111
108 testPatchFunction() { 112 testPatchFunction() {
109 var compiler = applyPatch( 113 asyncTest(() => applyPatch(
110 "external test();", 114 "external test();",
111 "patch test() { return 'string'; } "); 115 "patch test() { return 'string'; } ").then((compiler) {
112 ensure(compiler, "test", compiler.coreLibrary.find, 116 ensure(compiler, "test", compiler.coreLibrary.find,
113 expectIsPatched: true, checkHasBody: true); 117 expectIsPatched: true, checkHasBody: true);
114 ensure(compiler, "test", compiler.coreLibrary.patch.find, 118 ensure(compiler, "test", compiler.coreLibrary.patch.find,
115 expectIsPatch: true, checkHasBody: true); 119 expectIsPatch: true, checkHasBody: true);
116 120
117 Expect.isTrue(compiler.warnings.isEmpty, 121 Expect.isTrue(compiler.warnings.isEmpty,
118 "Unexpected warnings: ${compiler.warnings}"); 122 "Unexpected warnings: ${compiler.warnings}");
119 Expect.isTrue(compiler.errors.isEmpty, 123 Expect.isTrue(compiler.errors.isEmpty,
120 "Unexpected errors: ${compiler.errors}"); 124 "Unexpected errors: ${compiler.errors}");
125 }));
121 } 126 }
122 127
123 testPatchConstructor() { 128 testPatchConstructor() {
124 var compiler = applyPatch( 129 asyncTest(() => applyPatch(
125 """ 130 """
126 class Class { 131 class Class {
127 external Class(); 132 external Class();
128 } 133 }
129 """, 134 """,
130 """ 135 """
131 patch class Class { 136 patch class Class {
132 patch Class(); 137 patch Class();
133 } 138 }
134 """); 139 """).then((compiler) {
135 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 140 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
136 expectIsPatched: true); 141 expectIsPatched: true);
137 classOrigin.ensureResolved(compiler); 142 classOrigin.ensureResolved(compiler);
138 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 143 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
139 expectIsPatch: true); 144 expectIsPatch: true);
140 145
141 Expect.equals(classPatch, classOrigin.patch); 146 Expect.equals(classPatch, classOrigin.patch);
142 Expect.equals(classOrigin, classPatch.origin); 147 Expect.equals(classOrigin, classPatch.origin);
143 148
144 var constructorOrigin = ensure(compiler, "", 149 var constructorOrigin = ensure(compiler, "",
145 (name) => classOrigin.localLookup(name), 150 (name) => classOrigin.localLookup(name),
146 expectIsPatched: true); 151 expectIsPatched: true);
147 var constructorPatch = ensure(compiler, "", 152 var constructorPatch = ensure(compiler, "",
148 (name) => classPatch.localLookup(name), 153 (name) => classPatch.localLookup(name),
149 expectIsPatch: true); 154 expectIsPatch: true);
150 155
151 Expect.equals(constructorPatch, constructorOrigin.patch); 156 Expect.equals(constructorPatch, constructorOrigin.patch);
152 Expect.equals(constructorOrigin, constructorPatch.origin); 157 Expect.equals(constructorOrigin, constructorPatch.origin);
153 158
154 Expect.isTrue(compiler.warnings.isEmpty, 159 Expect.isTrue(compiler.warnings.isEmpty,
155 "Unexpected warnings: ${compiler.warnings}"); 160 "Unexpected warnings: ${compiler.warnings}");
156 Expect.isTrue(compiler.errors.isEmpty, 161 Expect.isTrue(compiler.errors.isEmpty,
157 "Unexpected errors: ${compiler.errors}"); 162 "Unexpected errors: ${compiler.errors}");
163 }));
158 } 164 }
159 165
160 testPatchMember() { 166 testPatchMember() {
161 var compiler = applyPatch( 167 asyncTest(() => applyPatch(
162 """ 168 """
163 class Class { 169 class Class {
164 external String toString(); 170 external String toString();
165 } 171 }
166 """, 172 """,
167 """ 173 """
168 patch class Class { 174 patch class Class {
169 patch String toString() => 'string'; 175 patch String toString() => 'string';
170 } 176 }
171 """); 177 """).then((compiler) {
172 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 178 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
173 expectIsPatched: true); 179 expectIsPatched: true);
174 container.parseNode(compiler); 180 container.parseNode(compiler);
175 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 181 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
176 expectIsPatch: true); 182 expectIsPatch: true);
177 183
178 ensure(compiler, "toString", container.lookupLocalMember, 184 ensure(compiler, "toString", container.lookupLocalMember,
179 expectIsPatched: true, checkHasBody: true); 185 expectIsPatched: true, checkHasBody: true);
180 ensure(compiler, "toString", container.patch.lookupLocalMember, 186 ensure(compiler, "toString", container.patch.lookupLocalMember,
181 expectIsPatch: true, checkHasBody: true); 187 expectIsPatch: true, checkHasBody: true);
182 188
183 Expect.isTrue(compiler.warnings.isEmpty, 189 Expect.isTrue(compiler.warnings.isEmpty,
184 "Unexpected warnings: ${compiler.warnings}"); 190 "Unexpected warnings: ${compiler.warnings}");
185 Expect.isTrue(compiler.errors.isEmpty, 191 Expect.isTrue(compiler.errors.isEmpty,
186 "Unexpected errors: ${compiler.errors}"); 192 "Unexpected errors: ${compiler.errors}");
193 }));
187 } 194 }
188 195
189 testPatchGetter() { 196 testPatchGetter() {
190 var compiler = applyPatch( 197 asyncTest(() => applyPatch(
191 """ 198 """
192 class Class { 199 class Class {
193 external int get field; 200 external int get field;
194 } 201 }
195 """, 202 """,
196 """ 203 """
197 patch class Class { 204 patch class Class {
198 patch int get field => 5; 205 patch int get field => 5;
199 } 206 }
200 """); 207 """).then((compiler) {
201 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 208 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
202 expectIsPatched: true); 209 expectIsPatched: true);
203 container.parseNode(compiler); 210 container.parseNode(compiler);
204 ensure(compiler, 211 ensure(compiler,
205 "field", 212 "field",
206 container.lookupLocalMember, 213 container.lookupLocalMember,
207 expectIsGetter: true, 214 expectIsGetter: true,
208 expectIsPatched: true, 215 expectIsPatched: true,
209 checkHasBody: true); 216 checkHasBody: true);
210 ensure(compiler, 217 ensure(compiler,
211 "field", 218 "field",
212 container.patch.lookupLocalMember, 219 container.patch.lookupLocalMember,
213 expectIsGetter: true, 220 expectIsGetter: true,
214 expectIsPatch: true, 221 expectIsPatch: true,
215 checkHasBody: true); 222 checkHasBody: true);
216 223
217 Expect.isTrue(compiler.warnings.isEmpty, 224 Expect.isTrue(compiler.warnings.isEmpty,
218 "Unexpected warnings: ${compiler.warnings}"); 225 "Unexpected warnings: ${compiler.warnings}");
219 Expect.isTrue(compiler.errors.isEmpty, 226 Expect.isTrue(compiler.errors.isEmpty,
220 "Unexpected errors: ${compiler.errors}"); 227 "Unexpected errors: ${compiler.errors}");
228 }));
221 } 229 }
222 230
223 testRegularMember() { 231 testRegularMember() {
224 var compiler = applyPatch( 232 asyncTest(() => applyPatch(
225 """ 233 """
226 class Class { 234 class Class {
227 void regular() {} 235 void regular() {}
228 } 236 }
229 """, 237 """,
230 """ 238 """
231 patch class Class { 239 patch class Class {
232 } 240 }
233 """); 241 """).then((compiler) {
234 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 242 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
235 expectIsPatched: true); 243 expectIsPatched: true);
236 container.parseNode(compiler); 244 container.parseNode(compiler);
237 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 245 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
238 expectIsPatch: true); 246 expectIsPatch: true);
239 247
240 ensure(compiler, "regular", container.lookupLocalMember, 248 ensure(compiler, "regular", container.lookupLocalMember,
241 checkHasBody: true, expectIsRegular: true); 249 checkHasBody: true, expectIsRegular: true);
242 ensure(compiler, "regular", container.patch.lookupLocalMember, 250 ensure(compiler, "regular", container.patch.lookupLocalMember,
243 checkHasBody: true, expectIsRegular: true); 251 checkHasBody: true, expectIsRegular: true);
244 252
245 Expect.isTrue(compiler.warnings.isEmpty, 253 Expect.isTrue(compiler.warnings.isEmpty,
246 "Unexpected warnings: ${compiler.warnings}"); 254 "Unexpected warnings: ${compiler.warnings}");
247 Expect.isTrue(compiler.errors.isEmpty, 255 Expect.isTrue(compiler.errors.isEmpty,
248 "Unexpected errors: ${compiler.errors}"); 256 "Unexpected errors: ${compiler.errors}");
257 }));
249 } 258 }
250 259
251 testGhostMember() { 260 testGhostMember() {
252 var compiler = applyPatch( 261 asyncTest(() => applyPatch(
253 """ 262 """
254 class Class { 263 class Class {
255 } 264 }
256 """, 265 """,
257 """ 266 """
258 patch class Class { 267 patch class Class {
259 void ghost() {} 268 void ghost() {}
260 } 269 }
261 """); 270 """).then((compiler) {
262 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 271 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
263 expectIsPatched: true); 272 expectIsPatched: true);
264 container.parseNode(compiler); 273 container.parseNode(compiler);
265 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 274 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
266 expectIsPatch: true); 275 expectIsPatch: true);
267 276
268 ensure(compiler, "ghost", container.lookupLocalMember, 277 ensure(compiler, "ghost", container.lookupLocalMember,
269 expectIsFound: false); 278 expectIsFound: false);
270 ensure(compiler, "ghost", container.patch.lookupLocalMember, 279 ensure(compiler, "ghost", container.patch.lookupLocalMember,
271 checkHasBody: true, expectIsRegular: true); 280 checkHasBody: true, expectIsRegular: true);
272 281
273 Expect.isTrue(compiler.warnings.isEmpty, 282 Expect.isTrue(compiler.warnings.isEmpty,
274 "Unexpected warnings: ${compiler.warnings}"); 283 "Unexpected warnings: ${compiler.warnings}");
275 Expect.isTrue(compiler.errors.isEmpty, 284 Expect.isTrue(compiler.errors.isEmpty,
276 "Unexpected errors: ${compiler.errors}"); 285 "Unexpected errors: ${compiler.errors}");
286 }));
277 } 287 }
278 288
279 testInjectFunction() { 289 testInjectFunction() {
280 var compiler = applyPatch( 290 asyncTest(() => applyPatch(
281 "", 291 "",
282 "int _function() => 5;"); 292 "int _function() => 5;").then((compiler) {
283 ensure(compiler, 293 ensure(compiler,
284 "_function", 294 "_function",
285 compiler.coreLibrary.find, 295 compiler.coreLibrary.find,
286 expectIsFound: false); 296 expectIsFound: false);
287 ensure(compiler, 297 ensure(compiler,
288 "_function", 298 "_function",
289 compiler.coreLibrary.patch.find, 299 compiler.coreLibrary.patch.find,
290 checkHasBody: true, expectIsRegular: true); 300 checkHasBody: true, expectIsRegular: true);
291 301
292 Expect.isTrue(compiler.warnings.isEmpty, 302 Expect.isTrue(compiler.warnings.isEmpty,
293 "Unexpected warnings: ${compiler.warnings}"); 303 "Unexpected warnings: ${compiler.warnings}");
294 Expect.isTrue(compiler.errors.isEmpty, 304 Expect.isTrue(compiler.errors.isEmpty,
295 "Unexpected errors: ${compiler.errors}"); 305 "Unexpected errors: ${compiler.errors}");
306 }));
296 } 307 }
297 308
298 testPatchSignatureCheck() { 309 testPatchSignatureCheck() {
299 var compiler = applyPatch( 310 asyncTest(() => applyPatch(
300 """ 311 """
301 class Class { 312 class Class {
302 external String method1(); 313 external String method1();
303 external void method2(String str); 314 external void method2(String str);
304 external void method3(String s1); 315 external void method3(String s1);
305 external void method4([String str]); 316 external void method4([String str]);
306 external void method5({String str}); 317 external void method5({String str});
307 external void method6({String str}); 318 external void method6({String str});
308 external void method7([String s1]); 319 external void method7([String s1]);
309 external void method8({String s1}); 320 external void method8({String s1});
310 external void method9(String str); 321 external void method9(String str);
311 external void method10([String str]); 322 external void method10([String str]);
312 external void method11({String str}); 323 external void method11({String str});
313 } 324 }
314 """, 325 """,
315 """ 326 """
316 patch class Class { 327 patch class Class {
317 patch int method1() => 0; 328 patch int method1() => 0;
318 patch void method2() {} 329 patch void method2() {}
319 patch void method3(String s2) {} 330 patch void method3(String s2) {}
320 patch void method4([String str, int i]) {} 331 patch void method4([String str, int i]) {}
321 patch void method5() {} 332 patch void method5() {}
322 patch void method6([String str]) {} 333 patch void method6([String str]) {}
323 patch void method7([String s2]) {} 334 patch void method7([String s2]) {}
324 patch void method8({String s2}) {} 335 patch void method8({String s2}) {}
325 patch void method9(int str) {} 336 patch void method9(int str) {}
326 patch void method10([int str]) {} 337 patch void method10([int str]) {}
327 patch void method11({int str}) {} 338 patch void method11({int str}) {}
328 } 339 }
329 """); 340 """).then((compiler) {
330 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 341 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
331 expectIsPatched: true); 342 expectIsPatched: true);
332 container.ensureResolved(compiler); 343 container.ensureResolved(compiler);
333 container.parseNode(compiler); 344 container.parseNode(compiler);
334 345
335 void expect(String methodName, List warnings, List errors) { 346 void expect(String methodName, List warnings, List errors) {
336 compiler.warnings.clear(); 347 compiler.warnings.clear();
337 compiler.errors.clear(); 348 compiler.errors.clear();
338 compiler.resolver.resolveMethodElement( 349 compiler.resolver.resolveMethodElement(
339 ensure(compiler, methodName, container.lookupLocalMember, 350 ensure(compiler, methodName, container.lookupLocalMember,
340 expectIsPatched: true, checkHasBody: true)); 351 expectIsPatched: true, checkHasBody: true));
341 Expect.equals(warnings.length, compiler.warnings.length, 352 Expect.equals(warnings.length, compiler.warnings.length,
342 "Unexpected warnings: ${compiler.warnings} on $methodName"); 353 "Unexpected warnings: ${compiler.warnings} on $methodName");
343 for (int i = 0 ; i < warnings.length ; i++) { 354 for (int i = 0 ; i < warnings.length ; i++) {
344 Expect.equals(warnings[i], compiler.warnings[i].message.kind); 355 Expect.equals(warnings[i], compiler.warnings[i].message.kind);
356 }
357 Expect.equals(errors.length, compiler.errors.length,
358 "Unexpected errors: ${compiler.errors} on $methodName");
359 for (int i = 0 ; i < errors.length ; i++) {
360 Expect.equals(errors[i], compiler.errors[i].message.kind);
361 }
345 } 362 }
346 Expect.equals(errors.length, compiler.errors.length,
347 "Unexpected errors: ${compiler.errors} on $methodName");
348 for (int i = 0 ; i < errors.length ; i++) {
349 Expect.equals(errors[i], compiler.errors[i].message.kind);
350 }
351 }
352 363
353 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]); 364 expect("method1", [], [MessageKind.PATCH_RETURN_TYPE_MISMATCH]);
354 expect("method2", [], [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]); 365 expect("method2", [],
355 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER], 366 [MessageKind.PATCH_REQUIRED_PARAMETER_COUNT_MISMATCH]);
356 [MessageKind.PATCH_PARAMETER_MISMATCH]); 367 expect("method3", [MessageKind.PATCH_POINT_TO_PARAMETER],
357 expect("method4", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); 368 [MessageKind.PATCH_PARAMETER_MISMATCH]);
358 expect("method5", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]); 369 expect("method4", [],
359 expect("method6", [], [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]); 370 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
360 expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER], 371 expect("method5", [],
361 [MessageKind.PATCH_PARAMETER_MISMATCH]); 372 [MessageKind.PATCH_OPTIONAL_PARAMETER_COUNT_MISMATCH]);
362 expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER], 373 expect("method6", [],
363 [MessageKind.PATCH_PARAMETER_MISMATCH]); 374 [MessageKind.PATCH_OPTIONAL_PARAMETER_NAMED_MISMATCH]);
364 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER], 375 expect("method7", [MessageKind.PATCH_POINT_TO_PARAMETER],
365 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 376 [MessageKind.PATCH_PARAMETER_MISMATCH]);
366 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER], 377 expect("method8", [MessageKind.PATCH_POINT_TO_PARAMETER],
367 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 378 [MessageKind.PATCH_PARAMETER_MISMATCH]);
368 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER], 379 expect("method9", [MessageKind.PATCH_POINT_TO_PARAMETER],
369 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 380 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
381 expect("method10", [MessageKind.PATCH_POINT_TO_PARAMETER],
382 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
383 expect("method11", [MessageKind.PATCH_POINT_TO_PARAMETER],
384 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
385 }));
370 } 386 }
371 387
372 testExternalWithoutImplementationTopLevel() { 388 testExternalWithoutImplementationTopLevel() {
373 var compiler = applyPatch( 389 asyncTest(() => applyPatch(
374 """ 390 """
375 external void foo(); 391 external void foo();
376 """, 392 """,
377 """ 393 """
378 // patch void foo() {} 394 // patch void foo() {}
379 """); 395 """).then((compiler) {
380 var function = ensure(compiler, "foo", compiler.coreLibrary.find); 396 var function = ensure(compiler, "foo", compiler.coreLibrary.find);
381 compiler.resolver.resolve(function); 397 compiler.resolver.resolve(function);
382 Expect.isTrue(compiler.warnings.isEmpty, 398 Expect.isTrue(compiler.warnings.isEmpty,
383 "Unexpected warnings: ${compiler.warnings}"); 399 "Unexpected warnings: ${compiler.warnings}");
384 print('testExternalWithoutImplementationTopLevel:${compiler.errors}'); 400 print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
385 Expect.equals(1, compiler.errors.length); 401 Expect.equals(1, compiler.errors.length);
386 Expect.isTrue( 402 Expect.isTrue(
387 compiler.errors[0].message.kind == 403 compiler.errors[0].message.kind ==
388 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 404 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
389 Expect.stringEquals('Error: External method without an implementation.', 405 Expect.stringEquals('Error: External method without an implementation.',
390 compiler.errors[0].message.toString()); 406 compiler.errors[0].message.toString());
407 }));
391 } 408 }
392 409
393 testExternalWithoutImplementationMember() { 410 testExternalWithoutImplementationMember() {
394 var compiler = applyPatch( 411 asyncTest(() => applyPatch(
395 """ 412 """
396 class Class { 413 class Class {
397 external void foo(); 414 external void foo();
398 } 415 }
399 """, 416 """,
400 """ 417 """
401 patch class Class { 418 patch class Class {
402 // patch void foo() {} 419 // patch void foo() {}
403 } 420 }
404 """); 421 """).then((compiler) {
405 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 422 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
406 expectIsPatched: true); 423 expectIsPatched: true);
407 container.parseNode(compiler); 424 container.parseNode(compiler);
408 425
409 compiler.warnings.clear(); 426 compiler.warnings.clear();
410 compiler.errors.clear(); 427 compiler.errors.clear();
411 compiler.resolver.resolveMethodElement( 428 compiler.resolver.resolveMethodElement(
412 ensure(compiler, "foo", container.lookupLocalMember)); 429 ensure(compiler, "foo", container.lookupLocalMember));
413 Expect.isTrue(compiler.warnings.isEmpty, 430 Expect.isTrue(compiler.warnings.isEmpty,
414 "Unexpected warnings: ${compiler.warnings}"); 431 "Unexpected warnings: ${compiler.warnings}");
415 print('testExternalWithoutImplementationMember:${compiler.errors}'); 432 print('testExternalWithoutImplementationMember:${compiler.errors}');
416 Expect.equals(1, compiler.errors.length); 433 Expect.equals(1, compiler.errors.length);
417 Expect.isTrue( 434 Expect.isTrue(
418 compiler.errors[0].message.kind == 435 compiler.errors[0].message.kind ==
419 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 436 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
420 Expect.stringEquals('Error: External method without an implementation.', 437 Expect.stringEquals('Error: External method without an implementation.',
421 compiler.errors[0].message.toString()); 438 compiler.errors[0].message.toString());
439 }));
422 } 440 }
423 441
424 testIsSubclass() { 442 testIsSubclass() {
425 var compiler = applyPatch( 443 asyncTest(() => applyPatch(
426 """ 444 """
427 class A {} 445 class A {}
428 """, 446 """,
429 """ 447 """
430 patch class A {} 448 patch class A {}
431 """); 449 """).then((compiler) {
432 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 450 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
433 expectIsPatched: true); 451 expectIsPatched: true);
434 ClassElement patch = cls.patch; 452 ClassElement patch = cls.patch;
435 Expect.isTrue(cls != patch); 453 Expect.isTrue(cls != patch);
436 Expect.isTrue(cls.isSubclassOf(patch)); 454 Expect.isTrue(cls.isSubclassOf(patch));
437 Expect.isTrue(patch.isSubclassOf(cls)); 455 Expect.isTrue(patch.isSubclassOf(cls));
456 }));
438 } 457 }
439 458
440 testPatchNonExistingTopLevel() { 459 testPatchNonExistingTopLevel() {
441 var compiler = applyPatch( 460 asyncTest(() => applyPatch(
442 """ 461 """
443 // class Class {} 462 // class Class {}
444 """, 463 """,
445 """ 464 """
446 patch class Class {} 465 patch class Class {}
447 """); 466 """).then((compiler) {
448 Expect.isTrue(compiler.warnings.isEmpty, 467 Expect.isTrue(compiler.warnings.isEmpty,
449 "Unexpected warnings: ${compiler.warnings}"); 468 "Unexpected warnings: ${compiler.warnings}");
450 print('testPatchNonExistingTopLevel:${compiler.errors}'); 469 print('testPatchNonExistingTopLevel:${compiler.errors}');
451 Expect.equals(1, compiler.errors.length); 470 Expect.equals(1, compiler.errors.length);
452 Expect.isTrue( 471 Expect.isTrue(
453 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 472 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
473 }));
454 } 474 }
455 475
456 testPatchNonExistingMember() { 476 testPatchNonExistingMember() {
457 var compiler = applyPatch( 477 asyncTest(() => applyPatch(
458 """ 478 """
459 class Class {} 479 class Class {}
460 """, 480 """,
461 """ 481 """
462 patch class Class { 482 patch class Class {
463 patch void foo() {} 483 patch void foo() {}
464 } 484 }
465 """); 485 """).then((compiler) {
466 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 486 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
467 expectIsPatched: true); 487 expectIsPatched: true);
468 container.parseNode(compiler); 488 container.parseNode(compiler);
469 489
470 Expect.isTrue(compiler.warnings.isEmpty, 490 Expect.isTrue(compiler.warnings.isEmpty,
471 "Unexpected warnings: ${compiler.warnings}"); 491 "Unexpected warnings: ${compiler.warnings}");
472 print('testPatchNonExistingMember:${compiler.errors}'); 492 print('testPatchNonExistingMember:${compiler.errors}');
473 Expect.equals(1, compiler.errors.length); 493 Expect.equals(1, compiler.errors.length);
474 Expect.isTrue( 494 Expect.isTrue(
475 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 495 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
496 }));
476 } 497 }
477 498
478 testPatchNonPatchablePatch() { 499 testPatchNonPatchablePatch() {
479 var compiler = applyPatch( 500 asyncTest(() => applyPatch(
480 """ 501 """
481 external get foo; 502 external get foo;
482 """, 503 """,
483 """ 504 """
484 patch var foo; 505 patch var foo;
485 """); 506 """).then((compiler) {
486 ensure(compiler, "foo", compiler.coreLibrary.find); 507 ensure(compiler, "foo", compiler.coreLibrary.find);
487 508
488 Expect.isTrue(compiler.warnings.isEmpty, 509 Expect.isTrue(compiler.warnings.isEmpty,
489 "Unexpected warnings: ${compiler.warnings}"); 510 "Unexpected warnings: ${compiler.warnings}");
490 print('testPatchNonPatchablePatch:${compiler.errors}'); 511 print('testPatchNonPatchablePatch:${compiler.errors}');
491 Expect.equals(1, compiler.errors.length); 512 Expect.equals(1, compiler.errors.length);
492 Expect.isTrue( 513 Expect.isTrue(
493 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); 514 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
515 }));
494 } 516 }
495 517
496 testPatchNonPatchableOrigin() { 518 testPatchNonPatchableOrigin() {
497 var compiler = applyPatch( 519 asyncTest(() => applyPatch(
498 """ 520 """
499 external var foo; 521 external var foo;
500 """, 522 """,
501 """ 523 """
502 patch get foo => 0; 524 patch get foo => 0;
503 """); 525 """).then((compiler) {
504 ensure(compiler, "foo", compiler.coreLibrary.find); 526 ensure(compiler, "foo", compiler.coreLibrary.find);
505 527
506 Expect.isTrue(compiler.warnings.isEmpty, 528 Expect.isTrue(compiler.warnings.isEmpty,
507 "Unexpected warnings: ${compiler.warnings}"); 529 "Unexpected warnings: ${compiler.warnings}");
508 print('testPatchNonPatchableOrigin:${compiler.errors}'); 530 print('testPatchNonPatchableOrigin:${compiler.errors}');
509 Expect.equals(2, compiler.errors.length); 531 Expect.equals(2, compiler.errors.length);
510 Expect.equals( 532 Expect.equals(
511 MessageKind.EXTRANEOUS_MODIFIER, compiler.errors[0].message.kind); 533 MessageKind.EXTRANEOUS_MODIFIER, compiler.errors[0].message.kind);
512 Expect.equals( 534 Expect.equals(
513 // TODO(ahe): Eventually, this error should be removed as it will be 535 // TODO(ahe): Eventually, this error should be removed as it will be
514 // handled by the regular parser. 536 // handled by the regular parser.
515 MessageKind.PATCH_NONPATCHABLE, compiler.errors[1].message.kind); 537 MessageKind.PATCH_NONPATCHABLE, compiler.errors[1].message.kind);
538 }));
516 } 539 }
517 540
518 testPatchNonExternalTopLevel() { 541 testPatchNonExternalTopLevel() {
519 var compiler = applyPatch( 542 asyncTest(() => applyPatch(
520 """ 543 """
521 void foo() {} 544 void foo() {}
522 """, 545 """,
523 """ 546 """
524 patch void foo() {} 547 patch void foo() {}
525 """); 548 """).then((compiler) {
526 print('testPatchNonExternalTopLevel.errors:${compiler.errors}'); 549 print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
527 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}'); 550 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
528 Expect.equals(1, compiler.errors.length); 551 Expect.equals(1, compiler.errors.length);
529 Expect.isTrue( 552 Expect.isTrue(
530 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 553 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
531 Expect.equals(1, compiler.warnings.length); 554 Expect.equals(1, compiler.warnings.length);
532 Expect.isTrue( 555 Expect.isTrue(compiler.warnings[0].message.kind ==
533 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 556 MessageKind.PATCH_POINT_TO_FUNCTION);
557 }));
534 } 558 }
535 559
536 testPatchNonExternalMember() { 560 testPatchNonExternalMember() {
537 var compiler = applyPatch( 561 asyncTest(() => applyPatch(
538 """ 562 """
539 class Class { 563 class Class {
540 void foo() {} 564 void foo() {}
541 } 565 }
542 """, 566 """,
543 """ 567 """
544 patch class Class { 568 patch class Class {
545 patch void foo() {} 569 patch void foo() {}
546 } 570 }
547 """); 571 """).then((compiler) {
548 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 572 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
549 expectIsPatched: true); 573 expectIsPatched: true);
550 container.parseNode(compiler); 574 container.parseNode(compiler);
551 575
552 print('testPatchNonExternalMember.errors:${compiler.errors}'); 576 print('testPatchNonExternalMember.errors:${compiler.errors}');
553 print('testPatchNonExternalMember.warnings:${compiler.warnings}'); 577 print('testPatchNonExternalMember.warnings:${compiler.warnings}');
554 Expect.equals(1, compiler.errors.length); 578 Expect.equals(1, compiler.errors.length);
555 Expect.isTrue( 579 Expect.isTrue(
556 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 580 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
557 Expect.equals(1, compiler.warnings.length); 581 Expect.equals(1, compiler.warnings.length);
558 Expect.isTrue( 582 Expect.isTrue(compiler.warnings[0].message.kind ==
559 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 583 MessageKind.PATCH_POINT_TO_FUNCTION);
584 }));
560 } 585 }
561 586
562 testPatchNonClass() { 587 testPatchNonClass() {
563 var compiler = applyPatch( 588 asyncTest(() => applyPatch(
564 """ 589 """
565 external void Class() {} 590 external void Class() {}
566 """, 591 """,
567 """ 592 """
568 patch class Class {} 593 patch class Class {}
569 """); 594 """).then((compiler) {
570 print('testPatchNonClass.errors:${compiler.errors}'); 595 print('testPatchNonClass.errors:${compiler.errors}');
571 print('testPatchNonClass.warnings:${compiler.warnings}'); 596 print('testPatchNonClass.warnings:${compiler.warnings}');
572 Expect.equals(1, compiler.errors.length); 597 Expect.equals(1, compiler.errors.length);
573 Expect.isTrue( 598 Expect.isTrue(
574 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS); 599 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
575 Expect.equals(1, compiler.warnings.length); 600 Expect.equals(1, compiler.warnings.length);
576 Expect.isTrue( 601 Expect.isTrue(
577 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS); 602 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
603 }));
578 } 604 }
579 605
580 testPatchNonGetter() { 606 testPatchNonGetter() {
581 var compiler = applyPatch( 607 asyncTest(() => applyPatch(
582 """ 608 """
583 external void foo() {} 609 external void foo() {}
584 """, 610 """,
585 """ 611 """
586 patch get foo => 0; 612 patch get foo => 0;
587 """); 613 """).then((compiler) {
588 print('testPatchNonClass.errors:${compiler.errors}'); 614 print('testPatchNonClass.errors:${compiler.errors}');
589 print('testPatchNonClass.warnings:${compiler.warnings}'); 615 print('testPatchNonClass.warnings:${compiler.warnings}');
590 Expect.equals(1, compiler.errors.length); 616 Expect.equals(1, compiler.errors.length);
591 Expect.isTrue( 617 Expect.isTrue(
592 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER); 618 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
593 Expect.equals(1, compiler.warnings.length); 619 Expect.equals(1, compiler.warnings.length);
594 Expect.isTrue( 620 Expect.isTrue(
595 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 621 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
622 }));
596 } 623 }
597 624
598 testPatchNoGetter() { 625 testPatchNoGetter() {
599 var compiler = applyPatch( 626 asyncTest(() => applyPatch(
600 """ 627 """
601 external set foo(var value) {} 628 external set foo(var value) {}
602 """, 629 """,
603 """ 630 """
604 patch get foo => 0; 631 patch get foo => 0;
605 """); 632 """).then((compiler) {
606 print('testPatchNonClass.errors:${compiler.errors}'); 633 print('testPatchNonClass.errors:${compiler.errors}');
607 print('testPatchNonClass.warnings:${compiler.warnings}'); 634 print('testPatchNonClass.warnings:${compiler.warnings}');
608 Expect.equals(1, compiler.errors.length); 635 Expect.equals(1, compiler.errors.length);
609 Expect.isTrue( 636 Expect.isTrue(
610 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER); 637 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
611 Expect.equals(1, compiler.warnings.length); 638 Expect.equals(1, compiler.warnings.length);
612 Expect.isTrue( 639 Expect.isTrue(
613 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 640 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
641 }));
614 } 642 }
615 643
616 testPatchNonSetter() { 644 testPatchNonSetter() {
617 var compiler = applyPatch( 645 asyncTest(() => applyPatch(
618 """ 646 """
619 external void foo() {} 647 external void foo() {}
620 """, 648 """,
621 """ 649 """
622 patch set foo(var value) {} 650 patch set foo(var value) {}
623 """); 651 """).then((compiler) {
624 print('testPatchNonClass.errors:${compiler.errors}'); 652 print('testPatchNonClass.errors:${compiler.errors}');
625 print('testPatchNonClass.warnings:${compiler.warnings}'); 653 print('testPatchNonClass.warnings:${compiler.warnings}');
626 Expect.equals(1, compiler.errors.length); 654 Expect.equals(1, compiler.errors.length);
627 Expect.isTrue( 655 Expect.isTrue(
628 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER); 656 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
629 Expect.equals(1, compiler.warnings.length); 657 Expect.equals(1, compiler.warnings.length);
630 Expect.isTrue( 658 Expect.isTrue(
631 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 659 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
660 }));
632 } 661 }
633 662
634 testPatchNoSetter() { 663 testPatchNoSetter() {
635 var compiler = applyPatch( 664 asyncTest(() => applyPatch(
636 """ 665 """
637 external get foo; 666 external get foo;
638 """, 667 """,
639 """ 668 """
640 patch set foo(var value) {} 669 patch set foo(var value) {}
641 """); 670 """).then((compiler) {
642 print('testPatchNonClass.errors:${compiler.errors}'); 671 print('testPatchNonClass.errors:${compiler.errors}');
643 print('testPatchNonClass.warnings:${compiler.warnings}'); 672 print('testPatchNonClass.warnings:${compiler.warnings}');
644 Expect.equals(1, compiler.errors.length); 673 Expect.equals(1, compiler.errors.length);
645 Expect.isTrue( 674 Expect.isTrue(
646 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER); 675 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
647 Expect.equals(1, compiler.warnings.length); 676 Expect.equals(1, compiler.warnings.length);
648 Expect.isTrue( 677 Expect.isTrue(
649 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 678 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
679 }));
650 } 680 }
651 681
652 testPatchNonFunction() { 682 testPatchNonFunction() {
653 var compiler = applyPatch( 683 asyncTest(() => applyPatch(
654 """ 684 """
655 external get foo; 685 external get foo;
656 """, 686 """,
657 """ 687 """
658 patch void foo() {} 688 patch void foo() {}
659 """); 689 """).then((compiler) {
660 print('testPatchNonClass.errors:${compiler.errors}'); 690 print('testPatchNonClass.errors:${compiler.errors}');
661 print('testPatchNonClass.warnings:${compiler.warnings}'); 691 print('testPatchNonClass.warnings:${compiler.warnings}');
662 Expect.equals(1, compiler.errors.length); 692 Expect.equals(1, compiler.errors.length);
663 Expect.isTrue( 693 Expect.isTrue(
664 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION); 694 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
665 Expect.equals(1, compiler.warnings.length); 695 Expect.equals(1, compiler.warnings.length);
666 Expect.isTrue( 696 Expect.isTrue(
667 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); 697 compiler.warnings[0].message.kind ==
698 MessageKind.PATCH_POINT_TO_FUNCTION);
699 }));
668 } 700 }
669 701
670 testPatchAndSelector() { 702 testPatchAndSelector() {
671 var compiler = applyPatch( 703 asyncTest(() => applyPatch(
672 """ 704 """
673 class A { 705 class A {
674 external void clear(); 706 external void clear();
675 } 707 }
676 class B extends A { 708 class B extends A {
677 } 709 }
678 """, 710 """,
679 """ 711 """
680 patch class A { 712 patch class A {
681 int method() => 0; 713 int method() => 0;
682 patch void clear() {} 714 patch void clear() {}
683 } 715 }
684 """); 716 """).then((compiler) {
685 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 717 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
686 expectIsPatched: true); 718 expectIsPatched: true);
687 cls.ensureResolved(compiler); 719 cls.ensureResolved(compiler);
688 720
689 ensure(compiler, "method", cls.patch.lookupLocalMember, 721 ensure(compiler, "method", cls.patch.lookupLocalMember,
690 checkHasBody: true, expectIsRegular: true); 722 checkHasBody: true, expectIsRegular: true);
691 723
692 ensure(compiler, "clear", cls.lookupLocalMember, 724 ensure(compiler, "clear", cls.lookupLocalMember,
693 checkHasBody: true, expectIsPatched: true); 725 checkHasBody: true, expectIsPatched: true);
694 726
695 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 727 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
696 728
697 // Check that a method just in the patch class is a target for a 729 // Check that a method just in the patch class is a target for a
698 // typed selector. 730 // typed selector.
699 var selector = new Selector.call( 731 var selector = new Selector.call(
700 buildSourceString('method'), compiler.coreLibrary, 0); 732 buildSourceString('method'), compiler.coreLibrary, 0);
701 var typedSelector = new TypedSelector.exact(cls.rawType, selector); 733 var typedSelector = new TypedSelector.exact(cls.rawType, selector);
702 Element method = 734 Element method =
703 cls.implementation.lookupLocalMember(buildSourceString('method')); 735 cls.implementation.lookupLocalMember(buildSourceString('method'));
704 Expect.isTrue(selector.applies(method, compiler)); 736 Expect.isTrue(selector.applies(method, compiler));
705 Expect.isTrue(typedSelector.applies(method, compiler)); 737 Expect.isTrue(typedSelector.applies(method, compiler));
706 738
707 // Check that the declaration method in the declaration class is a target 739 // Check that the declaration method in the declaration class is a target
708 // for a typed selector. 740 // for a typed selector.
709 selector = new Selector.call( 741 selector = new Selector.call(
710 buildSourceString('clear'), compiler.coreLibrary, 0); 742 buildSourceString('clear'), compiler.coreLibrary, 0);
711 typedSelector = new TypedSelector.exact(cls.rawType, selector); 743 typedSelector = new TypedSelector.exact(cls.rawType, selector);
712 method = cls.lookupLocalMember(buildSourceString('clear')); 744 method = cls.lookupLocalMember(buildSourceString('clear'));
713 Expect.isTrue(selector.applies(method, compiler)); 745 Expect.isTrue(selector.applies(method, compiler));
714 Expect.isTrue(typedSelector.applies(method, compiler)); 746 Expect.isTrue(typedSelector.applies(method, compiler));
715 747
716 // Check that the declaration method in the declaration class is a target 748 // Check that the declaration method in the declaration class is a target
717 // for a typed selector on a subclass. 749 // for a typed selector on a subclass.
718 cls = ensure(compiler, "B", compiler.coreLibrary.find); 750 cls = ensure(compiler, "B", compiler.coreLibrary.find);
719 cls.ensureResolved(compiler); 751 cls.ensureResolved(compiler);
720 typedSelector = new TypedSelector.exact(cls.rawType, selector); 752 typedSelector = new TypedSelector.exact(cls.rawType, selector);
721 Expect.isTrue(selector.applies(method, compiler)); 753 Expect.isTrue(selector.applies(method, compiler));
722 Expect.isTrue(typedSelector.applies(method, compiler)); 754 Expect.isTrue(typedSelector.applies(method, compiler));
755 }));
723 } 756 }
724 757
725 void testAnalyzeAllInjectedMembers() { 758 void testAnalyzeAllInjectedMembers() {
726 void expect(String patchText, [expectedWarnings]) { 759 void expect(String patchText, [expectedWarnings]) {
727 if (expectedWarnings == null) expectedWarnings = []; 760 if (expectedWarnings == null) expectedWarnings = [];
728 if (expectedWarnings is! List) { 761 if (expectedWarnings is! List) {
729 expectedWarnings = <MessageKind>[expectedWarnings]; 762 expectedWarnings = <MessageKind>[expectedWarnings];
730 } 763 }
731 764
732 var compiler = applyPatch('', patchText, 765 asyncTest(() => applyPatch('', patchText, analyzeAll: true,
733 analyzeAll: true, analyzeOnly: true); 766 analyzeOnly: true).then((compiler) {
734 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 767 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
735 compiler.runCompiler(null); 768 return compiler.runCompiler(null).then((_) {
736 compareWarningKinds(patchText, expectedWarnings, compiler.warnings); 769 compareWarningKinds(patchText, expectedWarnings, compiler.warnings);
770 });
771 }));
737 } 772 }
738 773
739 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE.warning); 774 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE.warning);
740 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE.warning); 775 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE.warning);
741 expect(''' 776 expect('''
742 class Class { 777 class Class {
743 String s = 0; 778 String s = 0;
744 } 779 }
745 ''', 780 ''',
746 MessageKind.NOT_ASSIGNABLE.warning); 781 MessageKind.NOT_ASSIGNABLE.warning);
747 expect(''' 782 expect('''
748 class Class { 783 class Class {
749 void method() { 784 void method() {
750 String s = 0; 785 String s = 0;
751 } 786 }
752 } 787 }
753 ''', 788 ''',
754 MessageKind.NOT_ASSIGNABLE.warning); 789 MessageKind.NOT_ASSIGNABLE.warning);
755 } 790 }
756 791
757 void testTypecheckPatchedMembers() { 792 void testTypecheckPatchedMembers() {
758 String originText = "external void method();"; 793 String originText = "external void method();";
759 String patchText = """ 794 String patchText = """
760 patch void method() { 795 patch void method() {
761 String s = 0; 796 String s = 0;
762 } 797 }
763 """; 798 """;
764 var compiler = applyPatch(originText, patchText, 799 asyncTest(() => applyPatch(originText, patchText,
765 analyzeAll: true, analyzeOnly: true); 800 analyzeAll: true, analyzeOnly: true).then((compiler) {
766 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 801 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
767 compiler.runCompiler(null); 802 return compiler.runCompiler(null).then((_) {
768 compareWarningKinds(patchText, 803 compareWarningKinds(patchText,
769 [MessageKind.NOT_ASSIGNABLE.warning], compiler.warnings); 804 [MessageKind.NOT_ASSIGNABLE.warning], compiler.warnings);
805 });
806 }));
770 } 807 }
771 808
772 main() { 809 main() {
773 testPatchConstructor(); 810 testPatchConstructor();
774 testPatchFunction(); 811 testPatchFunction();
775 testPatchMember(); 812 testPatchMember();
776 testPatchGetter(); 813 testPatchGetter();
777 testRegularMember(); 814 testRegularMember();
778 testGhostMember(); 815 testGhostMember();
779 testInjectFunction(); 816 testInjectFunction();
(...skipping 15 matching lines...) Expand all
795 testPatchNoGetter(); 832 testPatchNoGetter();
796 testPatchNonSetter(); 833 testPatchNonSetter();
797 testPatchNoSetter(); 834 testPatchNoSetter();
798 testPatchNonFunction(); 835 testPatchNonFunction();
799 836
800 testPatchAndSelector(); 837 testPatchAndSelector();
801 838
802 testAnalyzeAllInjectedMembers(); 839 testAnalyzeAllInjectedMembers();
803 testTypecheckPatchedMembers(); 840 testTypecheckPatchedMembers();
804 } 841 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/part_of_test.dart ('k') | tests/compiler/dart2js/private_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698