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

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

Issue 338103004: Use metadata for patching. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/utils/dummy_compiler_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 '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 "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 expectHasBody(compiler, element); 100 expectHasBody(compiler, element);
101 } 101 }
102 } 102 }
103 Expect.isFalse(element.isPatched && element.isPatch); 103 Expect.isFalse(element.isPatched && element.isPatch);
104 return element; 104 return element;
105 } 105 }
106 106
107 testPatchFunction() { 107 testPatchFunction() {
108 asyncTest(() => applyPatch( 108 asyncTest(() => applyPatch(
109 "external test();", 109 "external test();",
110 "patch test() { return 'string'; } ").then((compiler) { 110 "@patch test() { return 'string'; } ").then((compiler) {
111 ensure(compiler, "test", compiler.coreLibrary.find, 111 ensure(compiler, "test", compiler.coreLibrary.find,
112 expectIsPatched: true, checkHasBody: true); 112 expectIsPatched: true, checkHasBody: true);
113 ensure(compiler, "test", compiler.coreLibrary.patch.find, 113 ensure(compiler, "test", compiler.coreLibrary.patch.find,
114 expectIsPatch: true, checkHasBody: true); 114 expectIsPatch: true, checkHasBody: true);
115 115
116 Expect.isTrue(compiler.warnings.isEmpty, 116 Expect.isTrue(compiler.warnings.isEmpty,
117 "Unexpected warnings: ${compiler.warnings}"); 117 "Unexpected warnings: ${compiler.warnings}");
118 Expect.isTrue(compiler.errors.isEmpty, 118 Expect.isTrue(compiler.errors.isEmpty,
119 "Unexpected errors: ${compiler.errors}"); 119 "Unexpected errors: ${compiler.errors}");
120 })); 120 }));
121 } 121 }
122 122
123 testPatchConstructor() { 123 testPatchConstructor() {
124 asyncTest(() => applyPatch( 124 asyncTest(() => applyPatch(
125 """ 125 """
126 class Class { 126 class Class {
127 external Class(); 127 external Class();
128 } 128 }
129 """, 129 """,
130 """ 130 """
131 patch class Class { 131 @patch class Class {
132 patch Class(); 132 @patch Class();
133 } 133 }
134 """).then((compiler) { 134 """).then((compiler) {
135 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 135 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
136 expectIsPatched: true); 136 expectIsPatched: true);
137 classOrigin.ensureResolved(compiler); 137 classOrigin.ensureResolved(compiler);
138 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 138 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
139 expectIsPatch: true); 139 expectIsPatch: true);
140 140
141 Expect.equals(classPatch, classOrigin.patch); 141 Expect.equals(classPatch, classOrigin.patch);
142 Expect.equals(classOrigin, classPatch.origin); 142 Expect.equals(classOrigin, classPatch.origin);
(...skipping 18 matching lines...) Expand all
161 testPatchRedirectingConstructor() { 161 testPatchRedirectingConstructor() {
162 asyncTest(() => applyPatch( 162 asyncTest(() => applyPatch(
163 """ 163 """
164 class Class { 164 class Class {
165 Class(x) : this._(x, false); 165 Class(x) : this._(x, false);
166 166
167 external Class._(x, y); 167 external Class._(x, y);
168 } 168 }
169 """, 169 """,
170 r""" 170 r"""
171 patch class Class { 171 @patch class Class {
172 patch Class._(x, y) { print('$x,$y'); } 172 @patch Class._(x, y) { print('$x,$y'); }
173 } 173 }
174 """).then((compiler) { 174 """).then((compiler) {
175 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find, 175 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
176 expectIsPatched: true); 176 expectIsPatched: true);
177 classOrigin.ensureResolved(compiler); 177 classOrigin.ensureResolved(compiler);
178 178
179 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find, 179 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
180 expectIsPatch: true); 180 expectIsPatch: true);
181 181
182 Expect.equals(classOrigin, classPatch.origin); 182 Expect.equals(classOrigin, classPatch.origin);
(...skipping 23 matching lines...) Expand all
206 } 206 }
207 207
208 testPatchMember() { 208 testPatchMember() {
209 asyncTest(() => applyPatch( 209 asyncTest(() => applyPatch(
210 """ 210 """
211 class Class { 211 class Class {
212 external String toString(); 212 external String toString();
213 } 213 }
214 """, 214 """,
215 """ 215 """
216 patch class Class { 216 @patch class Class {
217 patch String toString() => 'string'; 217 @patch String toString() => 'string';
218 } 218 }
219 """).then((compiler) { 219 """).then((compiler) {
220 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 220 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
221 expectIsPatched: true); 221 expectIsPatched: true);
222 container.parseNode(compiler); 222 container.parseNode(compiler);
223 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 223 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
224 expectIsPatch: true); 224 expectIsPatch: true);
225 225
226 ensure(compiler, "toString", container.lookupLocalMember, 226 ensure(compiler, "toString", container.lookupLocalMember,
227 expectIsPatched: true, checkHasBody: true); 227 expectIsPatched: true, checkHasBody: true);
228 ensure(compiler, "toString", container.patch.lookupLocalMember, 228 ensure(compiler, "toString", container.patch.lookupLocalMember,
229 expectIsPatch: true, checkHasBody: true); 229 expectIsPatch: true, checkHasBody: true);
230 230
231 Expect.isTrue(compiler.warnings.isEmpty, 231 Expect.isTrue(compiler.warnings.isEmpty,
232 "Unexpected warnings: ${compiler.warnings}"); 232 "Unexpected warnings: ${compiler.warnings}");
233 Expect.isTrue(compiler.errors.isEmpty, 233 Expect.isTrue(compiler.errors.isEmpty,
234 "Unexpected errors: ${compiler.errors}"); 234 "Unexpected errors: ${compiler.errors}");
235 })); 235 }));
236 } 236 }
237 237
238 testPatchGetter() { 238 testPatchGetter() {
239 asyncTest(() => applyPatch( 239 asyncTest(() => applyPatch(
240 """ 240 """
241 class Class { 241 class Class {
242 external int get field; 242 external int get field;
243 } 243 }
244 """, 244 """,
245 """ 245 """
246 patch class Class { 246 @patch class Class {
247 patch int get field => 5; 247 @patch int get field => 5;
248 } 248 }
249 """).then((compiler) { 249 """).then((compiler) {
250 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 250 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
251 expectIsPatched: true); 251 expectIsPatched: true);
252 container.parseNode(compiler); 252 container.parseNode(compiler);
253 ensure(compiler, 253 ensure(compiler,
254 "field", 254 "field",
255 container.lookupLocalMember, 255 container.lookupLocalMember,
256 expectIsGetter: true, 256 expectIsGetter: true,
257 expectIsPatched: true, 257 expectIsPatched: true,
(...skipping 13 matching lines...) Expand all
271 } 271 }
272 272
273 testRegularMember() { 273 testRegularMember() {
274 asyncTest(() => applyPatch( 274 asyncTest(() => applyPatch(
275 """ 275 """
276 class Class { 276 class Class {
277 void regular() {} 277 void regular() {}
278 } 278 }
279 """, 279 """,
280 """ 280 """
281 patch class Class { 281 @patch class Class {
282 } 282 }
283 """).then((compiler) { 283 """).then((compiler) {
284 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 284 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
285 expectIsPatched: true); 285 expectIsPatched: true);
286 container.parseNode(compiler); 286 container.parseNode(compiler);
287 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 287 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
288 expectIsPatch: true); 288 expectIsPatch: true);
289 289
290 ensure(compiler, "regular", container.lookupLocalMember, 290 ensure(compiler, "regular", container.lookupLocalMember,
291 checkHasBody: true, expectIsRegular: true); 291 checkHasBody: true, expectIsRegular: true);
292 ensure(compiler, "regular", container.patch.lookupLocalMember, 292 ensure(compiler, "regular", container.patch.lookupLocalMember,
293 checkHasBody: true, expectIsRegular: true); 293 checkHasBody: true, expectIsRegular: true);
294 294
295 Expect.isTrue(compiler.warnings.isEmpty, 295 Expect.isTrue(compiler.warnings.isEmpty,
296 "Unexpected warnings: ${compiler.warnings}"); 296 "Unexpected warnings: ${compiler.warnings}");
297 Expect.isTrue(compiler.errors.isEmpty, 297 Expect.isTrue(compiler.errors.isEmpty,
298 "Unexpected errors: ${compiler.errors}"); 298 "Unexpected errors: ${compiler.errors}");
299 })); 299 }));
300 } 300 }
301 301
302 testGhostMember() { 302 testGhostMember() {
303 asyncTest(() => applyPatch( 303 asyncTest(() => applyPatch(
304 """ 304 """
305 class Class { 305 class Class {
306 } 306 }
307 """, 307 """,
308 """ 308 """
309 patch class Class { 309 @patch class Class {
310 void ghost() {} 310 void ghost() {}
311 } 311 }
312 """).then((compiler) { 312 """).then((compiler) {
313 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 313 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
314 expectIsPatched: true); 314 expectIsPatched: true);
315 container.parseNode(compiler); 315 container.parseNode(compiler);
316 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 316 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
317 expectIsPatch: true); 317 expectIsPatch: true);
318 318
319 ensure(compiler, "ghost", container.lookupLocalMember, 319 ensure(compiler, "ghost", container.lookupLocalMember,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 external void method5({String str}); 359 external void method5({String str});
360 external void method6({String str}); 360 external void method6({String str});
361 external void method7([String s1]); 361 external void method7([String s1]);
362 external void method8({String s1}); 362 external void method8({String s1});
363 external void method9(String str); 363 external void method9(String str);
364 external void method10([String str]); 364 external void method10([String str]);
365 external void method11({String str}); 365 external void method11({String str});
366 } 366 }
367 """, 367 """,
368 """ 368 """
369 patch class Class { 369 @patch class Class {
370 patch int method1() => 0; 370 @patch int method1() => 0;
371 patch void method2() {} 371 @patch void method2() {}
372 patch void method3(String s2) {} 372 @patch void method3(String s2) {}
373 patch void method4([String str, int i]) {} 373 @patch void method4([String str, int i]) {}
374 patch void method5() {} 374 @patch void method5() {}
375 patch void method6([String str]) {} 375 @patch void method6([String str]) {}
376 patch void method7([String s2]) {} 376 @patch void method7([String s2]) {}
377 patch void method8({String s2}) {} 377 @patch void method8({String s2}) {}
378 patch void method9(int str) {} 378 @patch void method9(int str) {}
379 patch void method10([int str]) {} 379 @patch void method10([int str]) {}
380 patch void method11({int str}) {} 380 @patch void method11({int str}) {}
381 } 381 }
382 """).then((compiler) { 382 """).then((compiler) {
383 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 383 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
384 expectIsPatched: true); 384 expectIsPatched: true);
385 container.ensureResolved(compiler); 385 container.ensureResolved(compiler);
386 container.parseNode(compiler); 386 container.parseNode(compiler);
387 387
388 void expect(String methodName, List infos, List errors) { 388 void expect(String methodName, List infos, List errors) {
389 compiler.clearMessages(); 389 compiler.clearMessages();
390 compiler.resolver.resolveMethodElement( 390 compiler.resolver.resolveMethodElement(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]); 426 [MessageKind.PATCH_PARAMETER_TYPE_MISMATCH]);
427 })); 427 }));
428 } 428 }
429 429
430 testExternalWithoutImplementationTopLevel() { 430 testExternalWithoutImplementationTopLevel() {
431 asyncTest(() => applyPatch( 431 asyncTest(() => applyPatch(
432 """ 432 """
433 external void foo(); 433 external void foo();
434 """, 434 """,
435 """ 435 """
436 // patch void foo() {} 436 // @patch void foo() {}
437 """).then((compiler) { 437 """).then((compiler) {
438 var function = ensure(compiler, "foo", compiler.coreLibrary.find); 438 var function = ensure(compiler, "foo", compiler.coreLibrary.find);
439 compiler.resolver.resolve(function); 439 compiler.resolver.resolve(function);
440 Expect.isTrue(compiler.warnings.isEmpty, 440 Expect.isTrue(compiler.warnings.isEmpty,
441 "Unexpected warnings: ${compiler.warnings}"); 441 "Unexpected warnings: ${compiler.warnings}");
442 print('testExternalWithoutImplementationTopLevel:${compiler.errors}'); 442 print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
443 Expect.equals(1, compiler.errors.length); 443 Expect.equals(1, compiler.errors.length);
444 Expect.isTrue( 444 Expect.isTrue(
445 compiler.errors[0].message.kind == 445 compiler.errors[0].message.kind ==
446 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 446 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
447 Expect.stringEquals('External method without an implementation.', 447 Expect.stringEquals('External method without an implementation.',
448 compiler.errors[0].message.toString()); 448 compiler.errors[0].message.toString());
449 })); 449 }));
450 } 450 }
451 451
452 testExternalWithoutImplementationMember() { 452 testExternalWithoutImplementationMember() {
453 asyncTest(() => applyPatch( 453 asyncTest(() => applyPatch(
454 """ 454 """
455 class Class { 455 class Class {
456 external void foo(); 456 external void foo();
457 } 457 }
458 """, 458 """,
459 """ 459 """
460 patch class Class { 460 @patch class Class {
461 // patch void foo() {} 461 // @patch void foo() {}
462 } 462 }
463 """).then((compiler) { 463 """).then((compiler) {
464 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 464 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
465 expectIsPatched: true); 465 expectIsPatched: true);
466 container.parseNode(compiler); 466 container.parseNode(compiler);
467 467
468 compiler.warnings.clear(); 468 compiler.warnings.clear();
469 compiler.errors.clear(); 469 compiler.errors.clear();
470 compiler.resolver.resolveMethodElement( 470 compiler.resolver.resolveMethodElement(
471 ensure(compiler, "foo", container.lookupLocalMember)); 471 ensure(compiler, "foo", container.lookupLocalMember));
472 Expect.isTrue(compiler.warnings.isEmpty, 472 Expect.isTrue(compiler.warnings.isEmpty,
473 "Unexpected warnings: ${compiler.warnings}"); 473 "Unexpected warnings: ${compiler.warnings}");
474 print('testExternalWithoutImplementationMember:${compiler.errors}'); 474 print('testExternalWithoutImplementationMember:${compiler.errors}');
475 Expect.equals(1, compiler.errors.length); 475 Expect.equals(1, compiler.errors.length);
476 Expect.isTrue( 476 Expect.isTrue(
477 compiler.errors[0].message.kind == 477 compiler.errors[0].message.kind ==
478 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 478 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
479 Expect.stringEquals('External method without an implementation.', 479 Expect.stringEquals('External method without an implementation.',
480 compiler.errors[0].message.toString()); 480 compiler.errors[0].message.toString());
481 })); 481 }));
482 } 482 }
483 483
484 testIsSubclass() { 484 testIsSubclass() {
485 asyncTest(() => applyPatch( 485 asyncTest(() => applyPatch(
486 """ 486 """
487 class A {} 487 class A {}
488 """, 488 """,
489 """ 489 """
490 patch class A {} 490 @patch class A {}
491 """).then((compiler) { 491 """).then((compiler) {
492 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 492 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
493 expectIsPatched: true); 493 expectIsPatched: true);
494 ClassElement patch = cls.patch; 494 ClassElement patch = cls.patch;
495 Expect.isTrue(cls != patch); 495 Expect.isTrue(cls != patch);
496 Expect.isTrue(cls.isSubclassOf(patch)); 496 Expect.isTrue(cls.isSubclassOf(patch));
497 Expect.isTrue(patch.isSubclassOf(cls)); 497 Expect.isTrue(patch.isSubclassOf(cls));
498 })); 498 }));
499 } 499 }
500 500
501 testPatchNonExistingTopLevel() { 501 testPatchNonExistingTopLevel() {
502 asyncTest(() => applyPatch( 502 asyncTest(() => applyPatch(
503 """ 503 """
504 // class Class {} 504 // class Class {}
505 """, 505 """,
506 """ 506 """
507 patch class Class {} 507 @patch class Class {}
508 """).then((compiler) { 508 """).then((compiler) {
509 Expect.isTrue(compiler.warnings.isEmpty, 509 Expect.isTrue(compiler.warnings.isEmpty,
510 "Unexpected warnings: ${compiler.warnings}"); 510 "Unexpected warnings: ${compiler.warnings}");
511 print('testPatchNonExistingTopLevel:${compiler.errors}'); 511 print('testPatchNonExistingTopLevel:${compiler.errors}');
512 Expect.equals(1, compiler.errors.length); 512 Expect.equals(1, compiler.errors.length);
513 Expect.isTrue( 513 Expect.isTrue(
514 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 514 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
515 })); 515 }));
516 } 516 }
517 517
518 testPatchNonExistingMember() { 518 testPatchNonExistingMember() {
519 asyncTest(() => applyPatch( 519 asyncTest(() => applyPatch(
520 """ 520 """
521 class Class {} 521 class Class {}
522 """, 522 """,
523 """ 523 """
524 patch class Class { 524 @patch class Class {
525 patch void foo() {} 525 @patch void foo() {}
526 } 526 }
527 """).then((compiler) { 527 """).then((compiler) {
528 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 528 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
529 expectIsPatched: true); 529 expectIsPatched: true);
530 container.parseNode(compiler); 530 container.parseNode(compiler);
531 531
532 Expect.isTrue(compiler.warnings.isEmpty, 532 Expect.isTrue(compiler.warnings.isEmpty,
533 "Unexpected warnings: ${compiler.warnings}"); 533 "Unexpected warnings: ${compiler.warnings}");
534 print('testPatchNonExistingMember:${compiler.errors}'); 534 print('testPatchNonExistingMember:${compiler.errors}');
535 Expect.equals(1, compiler.errors.length); 535 Expect.equals(1, compiler.errors.length);
536 Expect.isTrue( 536 Expect.isTrue(
537 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); 537 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
538 })); 538 }));
539 } 539 }
540 540
541 testPatchNonPatchablePatch() { 541 testPatchNonPatchablePatch() {
542 asyncTest(() => applyPatch( 542 asyncTest(() => applyPatch(
543 """ 543 """
544 external get foo; 544 external get foo;
545 """, 545 """,
546 """ 546 """
547 patch var foo; 547 @patch var foo;
548 """).then((compiler) { 548 """).then((compiler) {
549 ensure(compiler, "foo", compiler.coreLibrary.find); 549 ensure(compiler, "foo", compiler.coreLibrary.find);
550 550
551 Expect.isTrue(compiler.warnings.isEmpty, 551 Expect.isTrue(compiler.warnings.isEmpty,
552 "Unexpected warnings: ${compiler.warnings}"); 552 "Unexpected warnings: ${compiler.warnings}");
553 print('testPatchNonPatchablePatch:${compiler.errors}'); 553 print('testPatchNonPatchablePatch:${compiler.errors}');
554 Expect.equals(1, compiler.errors.length); 554 Expect.equals(1, compiler.errors.length);
555 Expect.isTrue( 555 Expect.isTrue(
556 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); 556 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
557 })); 557 }));
558 } 558 }
559 559
560 testPatchNonPatchableOrigin() { 560 testPatchNonPatchableOrigin() {
561 asyncTest(() => applyPatch( 561 asyncTest(() => applyPatch(
562 """ 562 """
563 external var foo; 563 external var foo;
564 """, 564 """,
565 """ 565 """
566 patch get foo => 0; 566 @patch get foo => 0;
567 """).then((compiler) { 567 """).then((compiler) {
568 ensure(compiler, "foo", compiler.coreLibrary.find); 568 ensure(compiler, "foo", compiler.coreLibrary.find);
569 569
570 Expect.isTrue(compiler.warnings.isEmpty, 570 Expect.isTrue(compiler.warnings.isEmpty,
571 "Unexpected warnings: ${compiler.warnings}"); 571 "Unexpected warnings: ${compiler.warnings}");
572 print('testPatchNonPatchableOrigin:${compiler.errors}'); 572 print('testPatchNonPatchableOrigin:${compiler.errors}');
573 Expect.equals(2, compiler.errors.length); 573 Expect.equals(2, compiler.errors.length);
574 Expect.equals( 574 Expect.equals(
575 MessageKind.EXTRANEOUS_MODIFIER, compiler.errors[0].message.kind); 575 MessageKind.EXTRANEOUS_MODIFIER, compiler.errors[0].message.kind);
576 Expect.equals( 576 Expect.equals(
577 // TODO(ahe): Eventually, this error should be removed as it will be 577 // TODO(ahe): Eventually, this error should be removed as it will be
578 // handled by the regular parser. 578 // handled by the regular parser.
579 MessageKind.PATCH_NONPATCHABLE, compiler.errors[1].message.kind); 579 MessageKind.PATCH_NONPATCHABLE, compiler.errors[1].message.kind);
580 })); 580 }));
581 } 581 }
582 582
583 testPatchNonExternalTopLevel() { 583 testPatchNonExternalTopLevel() {
584 asyncTest(() => applyPatch( 584 asyncTest(() => applyPatch(
585 """ 585 """
586 void foo() {} 586 void foo() {}
587 """, 587 """,
588 """ 588 """
589 patch void foo() {} 589 @patch void foo() {}
590 """).then((compiler) { 590 """).then((compiler) {
591 print('testPatchNonExternalTopLevel.errors:${compiler.errors}'); 591 print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
592 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}'); 592 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
593 Expect.equals(1, compiler.errors.length); 593 Expect.equals(1, compiler.errors.length);
594 Expect.isTrue( 594 Expect.isTrue(
595 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 595 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
596 Expect.equals(0, compiler.warnings.length); 596 Expect.equals(0, compiler.warnings.length);
597 Expect.equals(1, compiler.infos.length); 597 Expect.equals(1, compiler.infos.length);
598 Expect.isTrue(compiler.infos[0].message.kind == 598 Expect.isTrue(compiler.infos[0].message.kind ==
599 MessageKind.PATCH_POINT_TO_FUNCTION); 599 MessageKind.PATCH_POINT_TO_FUNCTION);
600 })); 600 }));
601 } 601 }
602 602
603 testPatchNonExternalMember() { 603 testPatchNonExternalMember() {
604 asyncTest(() => applyPatch( 604 asyncTest(() => applyPatch(
605 """ 605 """
606 class Class { 606 class Class {
607 void foo() {} 607 void foo() {}
608 } 608 }
609 """, 609 """,
610 """ 610 """
611 patch class Class { 611 @patch class Class {
612 patch void foo() {} 612 @patch void foo() {}
613 } 613 }
614 """).then((compiler) { 614 """).then((compiler) {
615 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 615 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
616 expectIsPatched: true); 616 expectIsPatched: true);
617 container.parseNode(compiler); 617 container.parseNode(compiler);
618 618
619 print('testPatchNonExternalMember.errors:${compiler.errors}'); 619 print('testPatchNonExternalMember.errors:${compiler.errors}');
620 print('testPatchNonExternalMember.warnings:${compiler.warnings}'); 620 print('testPatchNonExternalMember.warnings:${compiler.warnings}');
621 Expect.equals(1, compiler.errors.length); 621 Expect.equals(1, compiler.errors.length);
622 Expect.isTrue( 622 Expect.isTrue(
623 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); 623 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
624 Expect.equals(0, compiler.warnings.length); 624 Expect.equals(0, compiler.warnings.length);
625 Expect.equals(1, compiler.infos.length); 625 Expect.equals(1, compiler.infos.length);
626 Expect.isTrue(compiler.infos[0].message.kind == 626 Expect.isTrue(compiler.infos[0].message.kind ==
627 MessageKind.PATCH_POINT_TO_FUNCTION); 627 MessageKind.PATCH_POINT_TO_FUNCTION);
628 })); 628 }));
629 } 629 }
630 630
631 testPatchNonClass() { 631 testPatchNonClass() {
632 asyncTest(() => applyPatch( 632 asyncTest(() => applyPatch(
633 """ 633 """
634 external void Class() {} 634 external void Class() {}
635 """, 635 """,
636 """ 636 """
637 patch class Class {} 637 @patch class Class {}
638 """).then((compiler) { 638 """).then((compiler) {
639 print('testPatchNonClass.errors:${compiler.errors}'); 639 print('testPatchNonClass.errors:${compiler.errors}');
640 print('testPatchNonClass.warnings:${compiler.warnings}'); 640 print('testPatchNonClass.warnings:${compiler.warnings}');
641 Expect.equals(1, compiler.errors.length); 641 Expect.equals(1, compiler.errors.length);
642 Expect.isTrue( 642 Expect.isTrue(
643 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS); 643 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
644 Expect.equals(0, compiler.warnings.length); 644 Expect.equals(0, compiler.warnings.length);
645 Expect.equals(1, compiler.infos.length); 645 Expect.equals(1, compiler.infos.length);
646 Expect.isTrue( 646 Expect.isTrue(
647 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS); 647 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
648 })); 648 }));
649 } 649 }
650 650
651 testPatchNonGetter() { 651 testPatchNonGetter() {
652 asyncTest(() => applyPatch( 652 asyncTest(() => applyPatch(
653 """ 653 """
654 external void foo() {} 654 external void foo() {}
655 """, 655 """,
656 """ 656 """
657 patch get foo => 0; 657 @patch get foo => 0;
658 """).then((compiler) { 658 """).then((compiler) {
659 print('testPatchNonClass.errors:${compiler.errors}'); 659 print('testPatchNonClass.errors:${compiler.errors}');
660 print('testPatchNonClass.warnings:${compiler.warnings}'); 660 print('testPatchNonClass.warnings:${compiler.warnings}');
661 Expect.equals(1, compiler.errors.length); 661 Expect.equals(1, compiler.errors.length);
662 Expect.isTrue( 662 Expect.isTrue(
663 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER); 663 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
664 Expect.equals(0, compiler.warnings.length); 664 Expect.equals(0, compiler.warnings.length);
665 Expect.equals(1, compiler.infos.length); 665 Expect.equals(1, compiler.infos.length);
666 Expect.isTrue( 666 Expect.isTrue(
667 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 667 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
668 })); 668 }));
669 } 669 }
670 670
671 testPatchNoGetter() { 671 testPatchNoGetter() {
672 asyncTest(() => applyPatch( 672 asyncTest(() => applyPatch(
673 """ 673 """
674 external set foo(var value) {} 674 external set foo(var value) {}
675 """, 675 """,
676 """ 676 """
677 patch get foo => 0; 677 @patch get foo => 0;
678 """).then((compiler) { 678 """).then((compiler) {
679 print('testPatchNonClass.errors:${compiler.errors}'); 679 print('testPatchNonClass.errors:${compiler.errors}');
680 print('testPatchNonClass.warnings:${compiler.warnings}'); 680 print('testPatchNonClass.warnings:${compiler.warnings}');
681 Expect.equals(1, compiler.errors.length); 681 Expect.equals(1, compiler.errors.length);
682 Expect.isTrue( 682 Expect.isTrue(
683 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER); 683 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
684 Expect.equals(0, compiler.warnings.length); 684 Expect.equals(0, compiler.warnings.length);
685 Expect.equals(1, compiler.infos.length); 685 Expect.equals(1, compiler.infos.length);
686 Expect.isTrue( 686 Expect.isTrue(
687 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); 687 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
688 })); 688 }));
689 } 689 }
690 690
691 testPatchNonSetter() { 691 testPatchNonSetter() {
692 asyncTest(() => applyPatch( 692 asyncTest(() => applyPatch(
693 """ 693 """
694 external void foo() {} 694 external void foo() {}
695 """, 695 """,
696 """ 696 """
697 patch set foo(var value) {} 697 @patch set foo(var value) {}
698 """).then((compiler) { 698 """).then((compiler) {
699 print('testPatchNonClass.errors:${compiler.errors}'); 699 print('testPatchNonClass.errors:${compiler.errors}');
700 print('testPatchNonClass.warnings:${compiler.warnings}'); 700 print('testPatchNonClass.warnings:${compiler.warnings}');
701 Expect.equals(1, compiler.errors.length); 701 Expect.equals(1, compiler.errors.length);
702 Expect.isTrue( 702 Expect.isTrue(
703 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER); 703 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
704 Expect.equals(0, compiler.warnings.length); 704 Expect.equals(0, compiler.warnings.length);
705 Expect.equals(1, compiler.infos.length); 705 Expect.equals(1, compiler.infos.length);
706 Expect.isTrue( 706 Expect.isTrue(
707 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 707 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
708 })); 708 }));
709 } 709 }
710 710
711 testPatchNoSetter() { 711 testPatchNoSetter() {
712 asyncTest(() => applyPatch( 712 asyncTest(() => applyPatch(
713 """ 713 """
714 external get foo; 714 external get foo;
715 """, 715 """,
716 """ 716 """
717 patch set foo(var value) {} 717 @patch set foo(var value) {}
718 """).then((compiler) { 718 """).then((compiler) {
719 print('testPatchNonClass.errors:${compiler.errors}'); 719 print('testPatchNonClass.errors:${compiler.errors}');
720 print('testPatchNonClass.warnings:${compiler.warnings}'); 720 print('testPatchNonClass.warnings:${compiler.warnings}');
721 Expect.equals(1, compiler.errors.length); 721 Expect.equals(1, compiler.errors.length);
722 Expect.isTrue( 722 Expect.isTrue(
723 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER); 723 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
724 Expect.equals(0, compiler.warnings.length); 724 Expect.equals(0, compiler.warnings.length);
725 Expect.equals(1, compiler.infos.length); 725 Expect.equals(1, compiler.infos.length);
726 Expect.isTrue( 726 Expect.isTrue(
727 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); 727 compiler.infos[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
728 })); 728 }));
729 } 729 }
730 730
731 testPatchNonFunction() { 731 testPatchNonFunction() {
732 asyncTest(() => applyPatch( 732 asyncTest(() => applyPatch(
733 """ 733 """
734 external get foo; 734 external get foo;
735 """, 735 """,
736 """ 736 """
737 patch void foo() {} 737 @patch void foo() {}
738 """).then((compiler) { 738 """).then((compiler) {
739 print('testPatchNonClass.errors:${compiler.errors}'); 739 print('testPatchNonClass.errors:${compiler.errors}');
740 print('testPatchNonClass.warnings:${compiler.warnings}'); 740 print('testPatchNonClass.warnings:${compiler.warnings}');
741 Expect.equals(1, compiler.errors.length); 741 Expect.equals(1, compiler.errors.length);
742 Expect.isTrue( 742 Expect.isTrue(
743 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION); 743 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
744 Expect.equals(0, compiler.warnings.length); 744 Expect.equals(0, compiler.warnings.length);
745 Expect.equals(1, compiler.infos.length); 745 Expect.equals(1, compiler.infos.length);
746 Expect.isTrue( 746 Expect.isTrue(
747 compiler.infos[0].message.kind == 747 compiler.infos[0].message.kind ==
748 MessageKind.PATCH_POINT_TO_FUNCTION); 748 MessageKind.PATCH_POINT_TO_FUNCTION);
749 })); 749 }));
750 } 750 }
751 751
752 testPatchAndSelector() { 752 testPatchAndSelector() {
753 asyncTest(() => applyPatch( 753 asyncTest(() => applyPatch(
754 """ 754 """
755 class A { 755 class A {
756 external void clear(); 756 external void clear();
757 } 757 }
758 class B extends A { 758 class B extends A {
759 } 759 }
760 """, 760 """,
761 """ 761 """
762 patch class A { 762 @patch class A {
763 int method() => 0; 763 int method() => 0;
764 patch void clear() {} 764 @patch void clear() {}
765 } 765 }
766 """).then((compiler) { 766 """).then((compiler) {
767 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find, 767 ClassElement cls = ensure(compiler, "A", compiler.coreLibrary.find,
768 expectIsPatched: true); 768 expectIsPatched: true);
769 cls.ensureResolved(compiler); 769 cls.ensureResolved(compiler);
770 770
771 ensure(compiler, "method", cls.patch.lookupLocalMember, 771 ensure(compiler, "method", cls.patch.lookupLocalMember,
772 checkHasBody: true, expectIsRegular: true); 772 checkHasBody: true, expectIsRegular: true);
773 773
774 ensure(compiler, "clear", cls.lookupLocalMember, 774 ensure(compiler, "clear", cls.lookupLocalMember,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 String s = 0; 832 String s = 0;
833 } 833 }
834 } 834 }
835 ''', 835 ''',
836 MessageKind.NOT_ASSIGNABLE); 836 MessageKind.NOT_ASSIGNABLE);
837 } 837 }
838 838
839 void testTypecheckPatchedMembers() { 839 void testTypecheckPatchedMembers() {
840 String originText = "external void method();"; 840 String originText = "external void method();";
841 String patchText = """ 841 String patchText = """
842 patch void method() { 842 @patch void method() {
843 String s = 0; 843 String s = 0;
844 } 844 }
845 """; 845 """;
846 asyncTest(() => applyPatch(originText, patchText, 846 asyncTest(() => applyPatch(originText, patchText,
847 analyzeAll: true, analyzeOnly: true).then((compiler) { 847 analyzeAll: true, analyzeOnly: true).then((compiler) {
848 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 848 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
849 return compiler.runCompiler(null).then((_) { 849 return compiler.runCompiler(null).then((_) {
850 compareWarningKinds(patchText, 850 compareWarningKinds(patchText,
851 [MessageKind.NOT_ASSIGNABLE], compiler.warnings); 851 [MessageKind.NOT_ASSIGNABLE], compiler.warnings);
852 }); 852 });
(...skipping 27 matching lines...) Expand all
880 testPatchNoGetter(); 880 testPatchNoGetter();
881 testPatchNonSetter(); 881 testPatchNonSetter();
882 testPatchNoSetter(); 882 testPatchNoSetter();
883 testPatchNonFunction(); 883 testPatchNonFunction();
884 884
885 testPatchAndSelector(); 885 testPatchAndSelector();
886 886
887 testAnalyzeAllInjectedMembers(); 887 testAnalyzeAllInjectedMembers();
888 testTypecheckPatchedMembers(); 888 testTypecheckPatchedMembers();
889 } 889 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/utils/dummy_compiler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698