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

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

Issue 11864010: Improve checking of patches. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 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 "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 5 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 6 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
7 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 7 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
8 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
9 import "mock_compiler.dart"; 9 import "mock_compiler.dart";
10 import "parser_helper.dart"; 10 import "parser_helper.dart";
(...skipping 26 matching lines...) Expand all
37 Expect.isFalse(node.hasBody()); 37 Expect.isFalse(node.hasBody());
38 } 38 }
39 39
40 Element ensure(compiler, 40 Element ensure(compiler,
41 String name, 41 String name,
42 Element lookup(name), 42 Element lookup(name),
43 {bool expectIsPatched: false, 43 {bool expectIsPatched: false,
44 bool expectIsPatch: false, 44 bool expectIsPatch: false,
45 bool checkHasBody: false, 45 bool checkHasBody: false,
46 bool expectIsGetter: false, 46 bool expectIsGetter: false,
47 bool expectIsFound: true}) { 47 bool expectIsFound: true,
48 bool isRegular: false}) {
48 var element = lookup(buildSourceString(name)); 49 var element = lookup(buildSourceString(name));
49 if (!expectIsFound) { 50 if (!expectIsFound) {
50 Expect.isNull(element); 51 Expect.isNull(element);
51 return element; 52 return element;
52 } 53 }
53 Expect.isNotNull(element); 54 Expect.isNotNull(element);
54 if (expectIsGetter) { 55 if (expectIsGetter) {
55 Expect.isTrue(element is AbstractFieldElement); 56 Expect.isTrue(element is AbstractFieldElement);
56 Expect.isNotNull(element.getter); 57 Expect.isNotNull(element.getter);
57 element = element.getter; 58 element = element.getter;
(...skipping 21 matching lines...) Expand all
79 Expect.equals(element.origin, element.declaration); 80 Expect.equals(element.origin, element.declaration);
80 Expect.equals(element, element.implementation); 81 Expect.equals(element, element.implementation);
81 82
82 if (checkHasBody) { 83 if (checkHasBody) {
83 expectHasBody(compiler, element); 84 expectHasBody(compiler, element);
84 expectHasNoBody(compiler, element.origin); 85 expectHasNoBody(compiler, element.origin);
85 } 86 }
86 } else { 87 } else {
87 Expect.isTrue(element.isDeclaration); 88 Expect.isTrue(element.isDeclaration);
88 } 89 }
89 if (!(element.isPatched || element.isPatch)) { 90 if (isRegular) {
90 Expect.isNull(element.origin); 91 Expect.isNull(element.origin);
91 Expect.isNull(element.patch); 92 Expect.isNull(element.patch);
92 93
93 Expect.equals(element, element.declaration); 94 Expect.equals(element, element.declaration);
94 Expect.equals(element, element.implementation); 95 Expect.equals(element, element.implementation);
95 96
96 if (checkHasBody) { 97 if (checkHasBody) {
97 expectHasBody(compiler, element); 98 expectHasBody(compiler, element);
98 } 99 }
99 } 100 }
100 Expect.isFalse(element.isPatched && element.isPatch); 101 Expect.isFalse(element.isPatched && element.isPatch);
101 return element; 102 return element;
102 } 103 }
103 104
104 testPatchFunction() { 105 testPatchFunction() {
105 var compiler = applyPatch( 106 var compiler = applyPatch(
106 "external test();", 107 "external test();",
107 "patch test() { return 'string'; } "); 108 "patch test() { return 'string'; } ");
108 ensure(compiler, "test", compiler.coreLibrary.find, 109 ensure(compiler, "test", compiler.coreLibrary.find,
109 expectIsPatched: true, checkHasBody: true); 110 expectIsPatched: true, checkHasBody: true);
110 ensure(compiler, "test", compiler.coreLibrary.patch.find, 111 ensure(compiler, "test", compiler.coreLibrary.patch.find,
111 expectIsPatch: true, checkHasBody: true); 112 expectIsPatch: true, checkHasBody: true);
112 113
113 Expect.isTrue(compiler.warnings.isEmpty, 114 Expect.isTrue(compiler.warnings.isEmpty,
114 "Unexpected warnings: ${compiler.warnings}"); 115 "Unexpected warnings: ${compiler.warnings}");
115 Expect.isTrue(compiler.errors.isEmpty, 116 Expect.isTrue(compiler.errors.isEmpty,
116 "Unexpected errors: ${compiler.errors}"); 117 "Unexpected errors: ${compiler.errors}");
117 } 118 }
118 119
120 testPatchConstructor() {
121 var compiler = applyPatch(
122 """
123 class Class {
124 external Class();
125 }
126 """,
127 """
128 patch class Class {
129 patch Class();
130 }
131 """);
132 var classOrigin = ensure(compiler, "Class", compiler.coreLibrary.find,
133 expectIsPatched: true);
134 classOrigin.ensureResolved(compiler);
135 var classPatch = ensure(compiler, "Class", compiler.coreLibrary.patch.find,
136 expectIsPatch: true);
137
138 Expect.equals(classPatch, classOrigin.patch);
139 Expect.equals(classOrigin, classPatch.origin);
140
141 var constructorOrigin = ensure(compiler, "Class",
142 (name) => classOrigin.localLookup(name),
143 expectIsPatched: true);
144 var constructorPatch = ensure(compiler, "Class",
145 (name) => classPatch.localLookup(name),
146 expectIsPatch: true);
147
148 Expect.equals(constructorPatch, constructorOrigin.patch);
149 Expect.equals(constructorOrigin, constructorPatch.origin);
150
151 Expect.isTrue(compiler.warnings.isEmpty,
152 "Unexpected warnings: ${compiler.warnings}");
153 Expect.isTrue(compiler.errors.isEmpty,
154 "Unexpected errors: ${compiler.errors}");
155 }
156
119 testPatchMember() { 157 testPatchMember() {
120 var compiler = applyPatch( 158 var compiler = applyPatch(
121 """ 159 """
122 class Class { 160 class Class {
123 external String toString(); 161 external String toString();
124 } 162 }
125 """, 163 """,
126 """ 164 """
127 patch class Class { 165 patch class Class {
128 patch String toString() => 'string'; 166 patch String toString() => 'string';
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 patch class Class { 228 patch class Class {
191 } 229 }
192 """); 230 """);
193 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 231 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
194 expectIsPatched: true); 232 expectIsPatched: true);
195 container.parseNode(compiler); 233 container.parseNode(compiler);
196 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 234 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
197 expectIsPatch: true); 235 expectIsPatch: true);
198 236
199 ensure(compiler, "regular", container.lookupLocalMember, 237 ensure(compiler, "regular", container.lookupLocalMember,
200 checkHasBody: true); 238 checkHasBody: true, isRegular: true);
201 ensure(compiler, "regular", container.patch.lookupLocalMember, 239 ensure(compiler, "regular", container.patch.lookupLocalMember,
202 checkHasBody: true); 240 checkHasBody: true, isRegular: true);
203 241
204 Expect.isTrue(compiler.warnings.isEmpty, 242 Expect.isTrue(compiler.warnings.isEmpty,
205 "Unexpected warnings: ${compiler.warnings}"); 243 "Unexpected warnings: ${compiler.warnings}");
206 Expect.isTrue(compiler.errors.isEmpty, 244 Expect.isTrue(compiler.errors.isEmpty,
207 "Unexpected errors: ${compiler.errors}"); 245 "Unexpected errors: ${compiler.errors}");
208 } 246 }
209 247
210 testGhostMember() { 248 testGhostMember() {
211 var compiler = applyPatch( 249 var compiler = applyPatch(
212 """ 250 """
213 class Class { 251 class Class {
214 } 252 }
215 """, 253 """,
216 """ 254 """
217 patch class Class { 255 patch class Class {
218 void ghost() {} 256 void ghost() {}
219 } 257 }
220 """); 258 """);
221 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 259 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
222 expectIsPatched: true); 260 expectIsPatched: true);
223 container.parseNode(compiler); 261 container.parseNode(compiler);
224 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 262 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
225 expectIsPatch: true); 263 expectIsPatch: true);
226 264
227 ensure(compiler, "ghost", container.lookupLocalMember, 265 ensure(compiler, "ghost", container.lookupLocalMember,
228 expectIsFound: false); 266 expectIsFound: false);
229 ensure(compiler, "ghost", container.patch.lookupLocalMember, 267 ensure(compiler, "ghost", container.patch.lookupLocalMember,
230 checkHasBody: true); 268 checkHasBody: true, isRegular: true);
231 269
232 Expect.isTrue(compiler.warnings.isEmpty, 270 Expect.isTrue(compiler.warnings.isEmpty,
233 "Unexpected warnings: ${compiler.warnings}"); 271 "Unexpected warnings: ${compiler.warnings}");
234 Expect.isTrue(compiler.errors.isEmpty, 272 Expect.isTrue(compiler.errors.isEmpty,
235 "Unexpected errors: ${compiler.errors}"); 273 "Unexpected errors: ${compiler.errors}");
236 } 274 }
237 275
238 testInjectFunction() { 276 testInjectFunction() {
239 var compiler = applyPatch( 277 var compiler = applyPatch(
240 "", 278 "",
241 "int _function() => 5;"); 279 "int _function() => 5;");
242 ensure(compiler, 280 ensure(compiler,
243 "_function", 281 "_function",
244 compiler.coreLibrary.find, 282 compiler.coreLibrary.find,
245 expectIsFound: false); 283 expectIsFound: false);
246 ensure(compiler, 284 ensure(compiler,
247 "_function", 285 "_function",
248 compiler.coreLibrary.patch.find, 286 compiler.coreLibrary.patch.find,
249 checkHasBody: true); 287 checkHasBody: true, isRegular: true);
250 288
251 Expect.isTrue(compiler.warnings.isEmpty, 289 Expect.isTrue(compiler.warnings.isEmpty,
252 "Unexpected warnings: ${compiler.warnings}"); 290 "Unexpected warnings: ${compiler.warnings}");
253 Expect.isTrue(compiler.errors.isEmpty, 291 Expect.isTrue(compiler.errors.isEmpty,
254 "Unexpected errors: ${compiler.errors}"); 292 "Unexpected errors: ${compiler.errors}");
255 } 293 }
256 294
257 testPatchSignatureCheck() { 295 testPatchSignatureCheck() {
258 var compiler = applyPatch( 296 var compiler = applyPatch(
259 """ 297 """
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 "Unexpected warnings: ${compiler.warnings}"); 447 "Unexpected warnings: ${compiler.warnings}");
410 print('testExternalWithoutImplementationMember:${compiler.errors}'); 448 print('testExternalWithoutImplementationMember:${compiler.errors}');
411 Expect.equals(1, compiler.errors.length); 449 Expect.equals(1, compiler.errors.length);
412 Expect.isTrue( 450 Expect.isTrue(
413 compiler.errors[0].message.kind == 451 compiler.errors[0].message.kind ==
414 MessageKind.EXTERNAL_WITHOUT_IMPLEMENTATION); 452 MessageKind.EXTERNAL_WITHOUT_IMPLEMENTATION);
415 Expect.equals('External method without an implementation.', 453 Expect.equals('External method without an implementation.',
416 compiler.errors[0].message.toString()); 454 compiler.errors[0].message.toString());
417 } 455 }
418 456
457 testPatchNonExistingTopLevel() {
458 var compiler = applyPatch(
459 """
460 """,
461 """
462 patch class Class {}
463 """);
464 Expect.isTrue(compiler.warnings.isEmpty,
465 "Unexpected warnings: ${compiler.warnings}");
466 print('testPatchNonExistingTopLevel:${compiler.errors}');
467 Expect.equals(1, compiler.errors.length);
468 Expect.isTrue(
469 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
470 }
471
472 testPatchNonExistingMember() {
473 var compiler = applyPatch(
474 """
475 class Class {}
476 """,
477 """
478 patch class Class {
479 patch void foo() {}
480 }
481 """);
482 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
483 expectIsPatched: true);
484 container.parseNode(compiler);
485
486 Expect.isTrue(compiler.warnings.isEmpty,
487 "Unexpected warnings: ${compiler.warnings}");
488 print('testPatchNonExistingMember:${compiler.errors}');
489 Expect.equals(1, compiler.errors.length);
490 Expect.isTrue(
491 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING);
492 }
493
494 testPatchNonPatchablePatch() {
495 var compiler = applyPatch(
496 """
497 external get foo;
498 """,
499 """
500 patch var foo;
501 """);
502 ensure(compiler, "foo", compiler.coreLibrary.find);
503
504 Expect.isTrue(compiler.warnings.isEmpty,
505 "Unexpected warnings: ${compiler.warnings}");
506 print('testPatchNonPatchablePatch:${compiler.errors}');
507 Expect.equals(1, compiler.errors.length);
508 Expect.isTrue(
509 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
510 }
511
512 testPatchNonPatchableOrigin() {
513 var compiler = applyPatch(
514 """
515 external var foo;
516 """,
517 """
518 patch get foo => 0;
519 """);
520 ensure(compiler, "foo", compiler.coreLibrary.find);
521
522 Expect.isTrue(compiler.warnings.isEmpty,
523 "Unexpected warnings: ${compiler.warnings}");
524 print('testPatchNonPatchableOrigin:${compiler.errors}');
525 Expect.equals(1, compiler.errors.length);
526 Expect.isTrue(
527 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE);
528 }
529
530 testPatchNonExternalTopLevel() {
531 var compiler = applyPatch(
532 """
533 void foo() {}
534 """,
535 """
536 patch void foo() {}
537 """);
538 print('testPatchNonExternalTopLevel.errors:${compiler.errors}');
539 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}');
540 Expect.equals(1, compiler.errors.length);
541 Expect.isTrue(
542 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
543 Expect.equals(1, compiler.warnings.length);
544 Expect.isTrue(
545 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
546 }
547
548 testPatchNonExternalMember() {
549 var compiler = applyPatch(
550 """
551 class Class {
552 void foo() {}
553 }
554 """,
555 """
556 patch class Class {
557 patch void foo() {}
558 }
559 """);
560 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
561 expectIsPatched: true);
562 container.parseNode(compiler);
563
564 print('testPatchNonExternalMember.errors:${compiler.errors}');
565 print('testPatchNonExternalMember.warnings:${compiler.warnings}');
566 Expect.equals(1, compiler.errors.length);
567 Expect.isTrue(
568 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL);
569 Expect.equals(1, compiler.warnings.length);
570 Expect.isTrue(
571 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
572 }
573
574 testPatchNonClass() {
575 var compiler = applyPatch(
576 """
577 external void Class() {}
578 """,
579 """
580 patch class Class {}
581 """);
582 print('testPatchNonClass.errors:${compiler.errors}');
583 print('testPatchNonClass.warnings:${compiler.warnings}');
584 Expect.equals(1, compiler.errors.length);
585 Expect.isTrue(
586 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS);
587 Expect.equals(1, compiler.warnings.length);
588 Expect.isTrue(
589 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS);
590 }
591
592 testPatchNonGetter() {
593 var compiler = applyPatch(
594 """
595 external void foo() {}
596 """,
597 """
598 patch get foo => 0;
599 """);
600 print('testPatchNonClass.errors:${compiler.errors}');
601 print('testPatchNonClass.warnings:${compiler.warnings}');
602 Expect.equals(1, compiler.errors.length);
603 Expect.isTrue(
604 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER);
605 Expect.equals(1, compiler.warnings.length);
606 Expect.isTrue(
607 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
608 }
609
610 testPatchNoGetter() {
611 var compiler = applyPatch(
612 """
613 external set foo(var value) {}
614 """,
615 """
616 patch get foo => 0;
617 """);
618 print('testPatchNonClass.errors:${compiler.errors}');
619 print('testPatchNonClass.warnings:${compiler.warnings}');
620 Expect.equals(1, compiler.errors.length);
621 Expect.isTrue(
622 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER);
623 Expect.equals(1, compiler.warnings.length);
624 Expect.isTrue(
625 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER);
626 }
627
628 testPatchNonSetter() {
629 var compiler = applyPatch(
630 """
631 external void foo() {}
632 """,
633 """
634 patch set foo(var value) {}
635 """);
636 print('testPatchNonClass.errors:${compiler.errors}');
637 print('testPatchNonClass.warnings:${compiler.warnings}');
638 Expect.equals(1, compiler.errors.length);
639 Expect.isTrue(
640 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER);
641 Expect.equals(1, compiler.warnings.length);
642 Expect.isTrue(
643 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
644 }
645
646 testPatchNoSetter() {
647 var compiler = applyPatch(
648 """
649 external get foo;
650 """,
651 """
652 patch set foo(var value) {}
653 """);
654 print('testPatchNonClass.errors:${compiler.errors}');
655 print('testPatchNonClass.warnings:${compiler.warnings}');
656 Expect.equals(1, compiler.errors.length);
657 Expect.isTrue(
658 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER);
659 Expect.equals(1, compiler.warnings.length);
660 Expect.isTrue(
661 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER);
662 }
663
664 testPatchNonFunction() {
665 var compiler = applyPatch(
666 """
667 external get foo;
668 """,
669 """
670 patch void foo() {}
671 """);
672 print('testPatchNonClass.errors:${compiler.errors}');
673 print('testPatchNonClass.warnings:${compiler.warnings}');
674 Expect.equals(1, compiler.errors.length);
675 Expect.isTrue(
676 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION);
677 Expect.equals(1, compiler.warnings.length);
678 Expect.isTrue(
679 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION);
680 }
681
419 main() { 682 main() {
683 testPatchConstructor();
420 testPatchFunction(); 684 testPatchFunction();
421 testPatchMember(); 685 testPatchMember();
422 testPatchGetter(); 686 testPatchGetter();
423 testRegularMember(); 687 testRegularMember();
424 testGhostMember(); 688 testGhostMember();
425 testInjectFunction(); 689 testInjectFunction();
426 testPatchSignatureCheck(); 690 testPatchSignatureCheck();
427 691
428 testExternalWithoutImplementationTopLevel(); 692 testExternalWithoutImplementationTopLevel();
429 testExternalWithoutImplementationMember(); 693 testExternalWithoutImplementationMember();
694
695 testPatchNonExistingTopLevel();
696 testPatchNonExistingMember();
697 testPatchNonPatchablePatch();
698 testPatchNonPatchableOrigin();
699 testPatchNonExternalTopLevel();
700 testPatchNonExternalMember();
701 testPatchNonClass();
702 testPatchNonGetter();
703 testPatchNoGetter();
704 testPatchNonSetter();
705 testPatchNoSetter();
706 testPatchNonFunction();
430 } 707 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698