OLD | NEW |
---|---|
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 Loading... | |
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 isPatched: false, | 43 {bool isPatched: false, |
44 bool isPatch: false, | 44 bool isPatch: false, |
45 bool isMethod: true, | 45 bool isMethod: true, |
46 bool isGetter: false, | 46 bool isGetter: false, |
47 bool isFound: true}) { | 47 bool isFound: true, |
48 bool isRegular: false}) { | |
ngeoffray
2013/01/11 11:46:12
What's 'isRegular'? Maybe add a comment.
Johnni Winther
2013/01/29 09:30:56
A regular member is one that is neither patched no
| |
48 var element = lookup(buildSourceString(name)); | 49 var element = lookup(buildSourceString(name)); |
49 if (!isFound) { | 50 if (!isFound) { |
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 (isGetter) { | 55 if (isGetter) { |
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 Loading... | |
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 (isMethod) { | 83 if (isMethod) { |
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 (isMethod) { | 97 if (isMethod) { |
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, isPatched: true); | 109 ensure(compiler, "test", compiler.coreLibrary.find, isPatched: true); |
109 ensure(compiler, "test", compiler.coreLibrary.patch.find, isPatch: true); | 110 ensure(compiler, "test", compiler.coreLibrary.patch.find, isPatch: true); |
110 | 111 |
111 Expect.isTrue(compiler.warnings.isEmpty, | 112 Expect.isTrue(compiler.warnings.isEmpty, |
112 "Unexpected warnings: ${compiler.warnings}"); | 113 "Unexpected warnings: ${compiler.warnings}"); |
113 Expect.isTrue(compiler.errors.isEmpty, | 114 Expect.isTrue(compiler.errors.isEmpty, |
114 "Unexpected errors: ${compiler.errors}"); | 115 "Unexpected errors: ${compiler.errors}"); |
115 } | 116 } |
116 | 117 |
118 testPatchConstructor() { | |
119 var compiler = applyPatch( | |
120 """ | |
121 class Class { | |
122 external Class(); | |
123 } | |
124 """, | |
125 """ | |
126 patch class Class { | |
127 patch Class(); | |
128 } | |
129 """); | |
130 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | |
131 isMethod: false, isPatched: true); | |
132 container.parseNode(compiler); | |
133 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | |
134 isMethod: false, isPatch: true); | |
135 | |
136 | |
137 | |
138 ensure(compiler, "Class", (name) => container.localScope[name], | |
139 isMethod: false, isPatched: true); | |
140 ensure(compiler, "Class", (name) => container.patch.localScope[name], | |
141 isMethod: false, isPatch: true); | |
142 | |
143 Expect.isTrue(compiler.warnings.isEmpty, | |
144 "Unexpected warnings: ${compiler.warnings}"); | |
145 Expect.isTrue(compiler.errors.isEmpty, | |
146 "Unexpected errors: ${compiler.errors}"); | |
147 } | |
148 | |
117 testPatchMember() { | 149 testPatchMember() { |
118 var compiler = applyPatch( | 150 var compiler = applyPatch( |
119 """ | 151 """ |
120 class Class { | 152 class Class { |
121 external String toString(); | 153 external String toString(); |
122 } | 154 } |
123 """, | 155 """, |
124 """ | 156 """ |
125 patch class Class { | 157 patch class Class { |
126 patch String toString() => 'string'; | 158 patch String toString() => 'string'; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 """ | 217 """ |
186 patch class Class { | 218 patch class Class { |
187 } | 219 } |
188 """); | 220 """); |
189 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 221 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
190 isMethod: false, isPatched: true); | 222 isMethod: false, isPatched: true); |
191 container.parseNode(compiler); | 223 container.parseNode(compiler); |
192 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 224 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
193 isMethod: false, isPatch: true); | 225 isMethod: false, isPatch: true); |
194 | 226 |
195 ensure(compiler, "regular", container.lookupLocalMember); | 227 ensure(compiler, "regular", container.lookupLocalMember, isRegular: true); |
196 ensure(compiler, "regular", container.patch.lookupLocalMember); | 228 ensure(compiler, "regular", container.patch.lookupLocalMember, |
229 isRegular: true); | |
197 | 230 |
198 Expect.isTrue(compiler.warnings.isEmpty, | 231 Expect.isTrue(compiler.warnings.isEmpty, |
199 "Unexpected warnings: ${compiler.warnings}"); | 232 "Unexpected warnings: ${compiler.warnings}"); |
200 Expect.isTrue(compiler.errors.isEmpty, | 233 Expect.isTrue(compiler.errors.isEmpty, |
201 "Unexpected errors: ${compiler.errors}"); | 234 "Unexpected errors: ${compiler.errors}"); |
202 } | 235 } |
203 | 236 |
204 testGhostMember() { | 237 testGhostMember() { |
205 var compiler = applyPatch( | 238 var compiler = applyPatch( |
206 """ | 239 """ |
207 class Class { | 240 class Class { |
208 } | 241 } |
209 """, | 242 """, |
210 """ | 243 """ |
211 patch class Class { | 244 patch class Class { |
212 void ghost() {} | 245 void ghost() {} |
213 } | 246 } |
214 """); | 247 """); |
215 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | 248 var container = ensure(compiler, "Class", compiler.coreLibrary.find, |
216 isMethod: false, isPatched: true); | 249 isMethod: false, isPatched: true); |
217 container.parseNode(compiler); | 250 container.parseNode(compiler); |
218 ensure(compiler, "Class", compiler.coreLibrary.patch.find, | 251 ensure(compiler, "Class", compiler.coreLibrary.patch.find, |
219 isMethod: false, isPatch: true); | 252 isMethod: false, isPatch: true); |
220 | 253 |
221 ensure(compiler, "ghost", container.lookupLocalMember, isFound: false); | 254 ensure(compiler, "ghost", container.lookupLocalMember, isFound: false); |
222 ensure(compiler, "ghost", container.patch.lookupLocalMember); | 255 ensure(compiler, "ghost", container.patch.lookupLocalMember, |
256 isRegular: true); | |
223 | 257 |
224 Expect.isTrue(compiler.warnings.isEmpty, | 258 Expect.isTrue(compiler.warnings.isEmpty, |
225 "Unexpected warnings: ${compiler.warnings}"); | 259 "Unexpected warnings: ${compiler.warnings}"); |
226 Expect.isTrue(compiler.errors.isEmpty, | 260 Expect.isTrue(compiler.errors.isEmpty, |
227 "Unexpected errors: ${compiler.errors}"); | 261 "Unexpected errors: ${compiler.errors}"); |
228 } | 262 } |
229 | 263 |
230 testInjectFunction() { | 264 testInjectFunction() { |
231 var compiler = applyPatch( | 265 var compiler = applyPatch( |
232 "", | 266 "", |
233 "int _function() => 5;"); | 267 "int _function() => 5;"); |
234 ensure(compiler, | 268 ensure(compiler, |
235 "_function", | 269 "_function", |
236 compiler.coreLibrary.find, | 270 compiler.coreLibrary.find, |
237 isFound: false); | 271 isFound: false); |
238 ensure(compiler, | 272 ensure(compiler, |
239 "_function", | 273 "_function", |
240 compiler.coreLibrary.patch.find); | 274 compiler.coreLibrary.patch.find, |
275 isRegular: true); | |
241 | 276 |
242 Expect.isTrue(compiler.warnings.isEmpty, | 277 Expect.isTrue(compiler.warnings.isEmpty, |
243 "Unexpected warnings: ${compiler.warnings}"); | 278 "Unexpected warnings: ${compiler.warnings}"); |
244 Expect.isTrue(compiler.errors.isEmpty, | 279 Expect.isTrue(compiler.errors.isEmpty, |
245 "Unexpected errors: ${compiler.errors}"); | 280 "Unexpected errors: ${compiler.errors}"); |
246 } | 281 } |
247 | 282 |
248 testPatchSignatureCheck() { | 283 testPatchSignatureCheck() { |
249 var compiler = applyPatch( | 284 var compiler = applyPatch( |
250 """ | 285 """ |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 compiler.errors.clear(); | 383 compiler.errors.clear(); |
349 compiler.resolver.resolveMethodElement( | 384 compiler.resolver.resolveMethodElement( |
350 ensure(compiler, "method8", container.lookupLocalMember, | 385 ensure(compiler, "method8", container.lookupLocalMember, |
351 isPatched: true)); | 386 isPatched: true)); |
352 Expect.isTrue(compiler.warnings.isEmpty, | 387 Expect.isTrue(compiler.warnings.isEmpty, |
353 "Unexpected warnings: ${compiler.warnings}"); | 388 "Unexpected warnings: ${compiler.warnings}"); |
354 Expect.isFalse(compiler.errors.isEmpty); | 389 Expect.isFalse(compiler.errors.isEmpty); |
355 print('method8:${compiler.errors}'); | 390 print('method8:${compiler.errors}'); |
356 } | 391 } |
357 | 392 |
393 testPatchNonExistingTopLevel() { | |
394 var compiler = applyPatch( | |
395 """ | |
ahe
2013/01/21 10:53:35
Why a multiline string?
Johnni Winther
2013/01/29 09:30:56
Expanded with the missing class declaration.
| |
396 """, | |
397 """ | |
398 patch class Class {} | |
399 """); | |
400 Expect.isTrue(compiler.warnings.isEmpty, | |
401 "Unexpected warnings: ${compiler.warnings}"); | |
402 print('testPatchNonExistingTopLevel:${compiler.errors}'); | |
403 Expect.equals(1, compiler.errors.length); | |
404 Expect.isTrue( | |
405 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); | |
ahe
2013/01/21 10:53:35
I don't think you're testing the positions. This a
| |
406 } | |
407 | |
408 testPatchNonExistingMember() { | |
409 var compiler = applyPatch( | |
410 """ | |
411 class Class {} | |
412 """, | |
413 """ | |
414 patch class Class { | |
415 patch void foo() {} | |
416 } | |
417 """); | |
418 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | |
419 isMethod: false, isPatched: true); | |
420 container.parseNode(compiler); | |
421 | |
422 Expect.isTrue(compiler.warnings.isEmpty, | |
423 "Unexpected warnings: ${compiler.warnings}"); | |
424 print('testPatchNonExistingMember:${compiler.errors}'); | |
425 Expect.equals(1, compiler.errors.length); | |
426 Expect.isTrue( | |
427 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXISTING); | |
428 } | |
429 | |
430 testPatchNonPatchablePatch() { | |
431 var compiler = applyPatch( | |
432 """ | |
433 external get foo; | |
434 """, | |
435 """ | |
436 patch var foo; | |
437 """); | |
438 ensure(compiler, "foo", compiler.coreLibrary.find); | |
439 | |
440 Expect.isTrue(compiler.warnings.isEmpty, | |
441 "Unexpected warnings: ${compiler.warnings}"); | |
442 print('testPatchNonPatchablePatch:${compiler.errors}'); | |
443 Expect.equals(1, compiler.errors.length); | |
444 Expect.isTrue( | |
445 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); | |
ahe
2013/01/21 10:53:35
This, and many tests below, do not test that you g
Johnni Winther
2013/01/29 09:30:56
Generally a good idea, but not easy currently.
| |
446 } | |
447 | |
448 testPatchNonPatchableOrigin() { | |
449 var compiler = applyPatch( | |
450 """ | |
451 external var foo; | |
452 """, | |
453 """ | |
454 patch get foo => 0; | |
455 """); | |
456 ensure(compiler, "foo", compiler.coreLibrary.find, isMethod: false); | |
457 | |
458 Expect.isTrue(compiler.warnings.isEmpty, | |
459 "Unexpected warnings: ${compiler.warnings}"); | |
460 print('testPatchNonPatchableOrigin:${compiler.errors}'); | |
461 Expect.equals(1, compiler.errors.length); | |
462 Expect.isTrue( | |
463 compiler.errors[0].message.kind == MessageKind.PATCH_NONPATCHABLE); | |
464 } | |
465 | |
466 testPatchNonExternalTopLevel() { | |
467 var compiler = applyPatch( | |
468 """ | |
469 void foo() {} | |
470 """, | |
471 """ | |
472 patch void foo() {} | |
473 """); | |
474 print('testPatchNonExternalTopLevel.errors:${compiler.errors}'); | |
475 print('testPatchNonExternalTopLevel.warnings:${compiler.warnings}'); | |
476 Expect.equals(1, compiler.errors.length); | |
477 Expect.isTrue( | |
478 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); | |
479 Expect.equals(1, compiler.warnings.length); | |
480 Expect.isTrue( | |
481 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); | |
482 } | |
483 | |
484 testPatchNonExternalMember() { | |
485 var compiler = applyPatch( | |
486 """ | |
487 class Class { | |
488 void foo() {} | |
489 } | |
490 """, | |
491 """ | |
492 patch class Class { | |
493 patch void foo() {} | |
494 } | |
495 """); | |
496 var container = ensure(compiler, "Class", compiler.coreLibrary.find, | |
497 isMethod: false, isPatched: true); | |
498 container.parseNode(compiler); | |
499 | |
500 print('testPatchNonExternalMember.errors:${compiler.errors}'); | |
501 print('testPatchNonExternalMember.warnings:${compiler.warnings}'); | |
502 Expect.equals(1, compiler.errors.length); | |
503 Expect.isTrue( | |
504 compiler.errors[0].message.kind == MessageKind.PATCH_NON_EXTERNAL); | |
505 Expect.equals(1, compiler.warnings.length); | |
506 Expect.isTrue( | |
507 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); | |
508 } | |
509 | |
510 testPatchNonClass() { | |
511 var compiler = applyPatch( | |
512 """ | |
513 external void Class() {} | |
514 """, | |
515 """ | |
516 patch class Class {} | |
517 """); | |
518 print('testPatchNonClass.errors:${compiler.errors}'); | |
519 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
520 Expect.equals(1, compiler.errors.length); | |
521 Expect.isTrue( | |
522 compiler.errors[0].message.kind == MessageKind.PATCH_NON_CLASS); | |
523 Expect.equals(1, compiler.warnings.length); | |
524 Expect.isTrue( | |
525 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_CLASS); | |
526 } | |
527 | |
528 testPatchNonGetter() { | |
529 var compiler = applyPatch( | |
530 """ | |
531 external void foo() {} | |
532 """, | |
533 """ | |
534 patch get foo => 0; | |
535 """); | |
536 print('testPatchNonClass.errors:${compiler.errors}'); | |
537 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
538 Expect.equals(1, compiler.errors.length); | |
539 Expect.isTrue( | |
540 compiler.errors[0].message.kind == MessageKind.PATCH_NON_GETTER); | |
541 Expect.equals(1, compiler.warnings.length); | |
542 Expect.isTrue( | |
543 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); | |
544 } | |
545 | |
546 testPatchNoGetter() { | |
547 var compiler = applyPatch( | |
548 """ | |
549 external set foo(var value) {} | |
550 """, | |
551 """ | |
552 patch get foo => 0; | |
553 """); | |
554 print('testPatchNonClass.errors:${compiler.errors}'); | |
555 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
556 Expect.equals(1, compiler.errors.length); | |
557 Expect.isTrue( | |
558 compiler.errors[0].message.kind == MessageKind.PATCH_NO_GETTER); | |
559 Expect.equals(1, compiler.warnings.length); | |
560 Expect.isTrue( | |
561 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_GETTER); | |
562 } | |
563 | |
564 testPatchNonSetter() { | |
565 var compiler = applyPatch( | |
566 """ | |
567 external void foo() {} | |
568 """, | |
569 """ | |
570 patch set foo(var value) {} | |
571 """); | |
572 print('testPatchNonClass.errors:${compiler.errors}'); | |
573 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
574 Expect.equals(1, compiler.errors.length); | |
575 Expect.isTrue( | |
576 compiler.errors[0].message.kind == MessageKind.PATCH_NON_SETTER); | |
577 Expect.equals(1, compiler.warnings.length); | |
578 Expect.isTrue( | |
579 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); | |
580 } | |
581 | |
582 testPatchNoSetter() { | |
583 var compiler = applyPatch( | |
584 """ | |
585 external get foo; | |
586 """, | |
587 """ | |
588 patch set foo(var value) {} | |
589 """); | |
590 print('testPatchNonClass.errors:${compiler.errors}'); | |
591 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
592 Expect.equals(1, compiler.errors.length); | |
593 Expect.isTrue( | |
594 compiler.errors[0].message.kind == MessageKind.PATCH_NO_SETTER); | |
595 Expect.equals(1, compiler.warnings.length); | |
596 Expect.isTrue( | |
597 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_SETTER); | |
598 } | |
599 | |
600 testPatchNonFunction() { | |
601 var compiler = applyPatch( | |
602 """ | |
603 external get foo; | |
604 """, | |
605 """ | |
606 patch void foo() {} | |
607 """); | |
608 print('testPatchNonClass.errors:${compiler.errors}'); | |
609 print('testPatchNonClass.warnings:${compiler.warnings}'); | |
610 Expect.equals(1, compiler.errors.length); | |
611 Expect.isTrue( | |
612 compiler.errors[0].message.kind == MessageKind.PATCH_NON_FUNCTION); | |
613 Expect.equals(1, compiler.warnings.length); | |
614 Expect.isTrue( | |
615 compiler.warnings[0].message.kind == MessageKind.PATCH_POINT_TO_FUNCTION); | |
616 } | |
617 | |
358 main() { | 618 main() { |
619 testPatchConstructor(); | |
359 testPatchFunction(); | 620 testPatchFunction(); |
360 testPatchMember(); | 621 testPatchMember(); |
361 testPatchGetter(); | 622 testPatchGetter(); |
362 testRegularMember(); | 623 testRegularMember(); |
363 testGhostMember(); | 624 testGhostMember(); |
364 testInjectFunction(); | 625 testInjectFunction(); |
365 testPatchSignatureCheck(); | 626 testPatchSignatureCheck(); |
627 | |
628 testPatchNonExistingTopLevel(); | |
629 testPatchNonExistingMember(); | |
630 testPatchNonPatchablePatch(); | |
631 testPatchNonPatchableOrigin(); | |
632 testPatchNonExternalTopLevel(); | |
633 testPatchNonExternalMember(); | |
634 testPatchNonClass(); | |
635 testPatchNonGetter(); | |
636 testPatchNoGetter(); | |
637 testPatchNonSetter(); | |
638 testPatchNoSetter(); | |
639 testPatchNonFunction(); | |
366 } | 640 } |
OLD | NEW |