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

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

Issue 1892183002: Refactor Parsing to remove compiler dependency (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/parser_helper.dart ('k') | tests/compiler/dart2js/resolver_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 'package:compiler/src/compiler.dart'; 8 import 'package:compiler/src/compiler.dart';
9 import 'package:compiler/src/diagnostics/messages.dart' show 9 import 'package:compiler/src/diagnostics/messages.dart' show
10 MessageKind; 10 MessageKind;
(...skipping 27 matching lines...) Expand all
38 var future; 38 var future;
39 if (runCompiler) { 39 if (runCompiler) {
40 future = compiler.run(null, main); 40 future = compiler.run(null, main);
41 } else { 41 } else {
42 future = compiler.init(main); 42 future = compiler.init(main);
43 } 43 }
44 return future.then((_) => compiler); 44 return future.then((_) => compiler);
45 } 45 }
46 46
47 void expectHasBody(compiler, ElementX element) { 47 void expectHasBody(compiler, ElementX element) {
48 var node = element.parseNode(compiler.parsing); 48 var node = element.parseNode(compiler.parsingContext);
49 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 49 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
50 Expect.isNotNull(node.body); 50 Expect.isNotNull(node.body);
51 // If the element has a body it is either a Block or a Return statement, 51 // If the element has a body it is either a Block or a Return statement,
52 // both with different begin and end tokens. 52 // both with different begin and end tokens.
53 Expect.isTrue(node.body is Block || node.body is Return); 53 Expect.isTrue(node.body is Block || node.body is Return);
54 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken()); 54 Expect.notEquals(node.body.getBeginToken(), node.body.getEndToken());
55 } 55 }
56 56
57 void expectHasNoBody(compiler, ElementX element) { 57 void expectHasNoBody(compiler, ElementX element) {
58 var node = element.parseNode(compiler.parsing); 58 var node = element.parseNode(compiler.parsingContext);
59 Expect.isNotNull(node, "Element isn't parseable, when a body was expected"); 59 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
60 Expect.isFalse(node.hasBody); 60 Expect.isFalse(node.hasBody);
61 } 61 }
62 62
63 Element ensure(compiler, 63 Element ensure(compiler,
64 String name, 64 String name,
65 Element lookup(name), 65 Element lookup(name),
66 {bool expectIsPatched: false, 66 {bool expectIsPatched: false,
67 bool expectIsPatch: false, 67 bool expectIsPatch: false,
68 bool checkHasBody: false, 68 bool checkHasBody: false,
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 external String toString(); 329 external String toString();
330 } 330 }
331 """, 331 """,
332 """ 332 """
333 @patch class Class { 333 @patch class Class {
334 @patch String toString() => 'string'; 334 @patch String toString() => 'string';
335 } 335 }
336 """); 336 """);
337 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 337 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
338 expectIsPatched: true); 338 expectIsPatched: true);
339 container.parseNode(compiler.parsing); 339 container.parseNode(compiler.parsingContext);
340 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 340 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
341 expectIsPatch: true); 341 expectIsPatch: true);
342 342
343 ensure(compiler, "toString", container.lookupLocalMember, 343 ensure(compiler, "toString", container.lookupLocalMember,
344 expectIsPatched: true, checkHasBody: true); 344 expectIsPatched: true, checkHasBody: true);
345 ensure(compiler, "toString", container.patch.lookupLocalMember, 345 ensure(compiler, "toString", container.patch.lookupLocalMember,
346 expectIsPatch: true, checkHasBody: true); 346 expectIsPatch: true, checkHasBody: true);
347 347
348 DiagnosticCollector collector = compiler.diagnosticCollector; 348 DiagnosticCollector collector = compiler.diagnosticCollector;
349 Expect.isTrue(collector.warnings.isEmpty, 349 Expect.isTrue(collector.warnings.isEmpty,
350 "Unexpected warnings: ${collector.warnings}"); 350 "Unexpected warnings: ${collector.warnings}");
351 Expect.isTrue(collector.errors.isEmpty, 351 Expect.isTrue(collector.errors.isEmpty,
352 "Unexpected errors: ${collector.errors}"); 352 "Unexpected errors: ${collector.errors}");
353 } 353 }
354 354
355 Future testPatchGetter() async { 355 Future testPatchGetter() async {
356 var compiler = await applyPatch( 356 var compiler = await applyPatch(
357 """ 357 """
358 class Class { 358 class Class {
359 external int get field; 359 external int get field;
360 } 360 }
361 """, 361 """,
362 """ 362 """
363 @patch class Class { 363 @patch class Class {
364 @patch int get field => 5; 364 @patch int get field => 5;
365 } 365 }
366 """); 366 """);
367 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 367 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
368 expectIsPatched: true); 368 expectIsPatched: true);
369 container.parseNode(compiler.parsing); 369 container.parseNode(compiler.parsingContext);
370 ensure(compiler, 370 ensure(compiler,
371 "field", 371 "field",
372 container.lookupLocalMember, 372 container.lookupLocalMember,
373 expectIsGetter: true, 373 expectIsGetter: true,
374 expectIsPatched: true, 374 expectIsPatched: true,
375 checkHasBody: true); 375 checkHasBody: true);
376 ensure(compiler, 376 ensure(compiler,
377 "field", 377 "field",
378 container.patch.lookupLocalMember, 378 container.patch.lookupLocalMember,
379 expectIsGetter: true, 379 expectIsGetter: true,
(...skipping 13 matching lines...) Expand all
393 class Class { 393 class Class {
394 void regular() {} 394 void regular() {}
395 } 395 }
396 """, 396 """,
397 """ 397 """
398 @patch class Class { 398 @patch class Class {
399 } 399 }
400 """); 400 """);
401 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 401 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
402 expectIsPatched: true); 402 expectIsPatched: true);
403 container.parseNode(compiler.parsing); 403 container.parseNode(compiler.parsingContext);
404 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 404 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
405 expectIsPatch: true); 405 expectIsPatch: true);
406 406
407 ensure(compiler, "regular", container.lookupLocalMember, 407 ensure(compiler, "regular", container.lookupLocalMember,
408 checkHasBody: true, expectIsRegular: true); 408 checkHasBody: true, expectIsRegular: true);
409 ensure(compiler, "regular", container.patch.lookupLocalMember, 409 ensure(compiler, "regular", container.patch.lookupLocalMember,
410 checkHasBody: true, expectIsRegular: true); 410 checkHasBody: true, expectIsRegular: true);
411 411
412 DiagnosticCollector collector = compiler.diagnosticCollector; 412 DiagnosticCollector collector = compiler.diagnosticCollector;
413 Expect.isTrue(collector.warnings.isEmpty, 413 Expect.isTrue(collector.warnings.isEmpty,
414 "Unexpected warnings: ${collector.warnings}"); 414 "Unexpected warnings: ${collector.warnings}");
415 Expect.isTrue(collector.errors.isEmpty, 415 Expect.isTrue(collector.errors.isEmpty,
416 "Unexpected errors: ${collector.errors}"); 416 "Unexpected errors: ${collector.errors}");
417 } 417 }
418 418
419 Future testInjectedMember() async { 419 Future testInjectedMember() async {
420 var compiler = await applyPatch( 420 var compiler = await applyPatch(
421 """ 421 """
422 class Class { 422 class Class {
423 } 423 }
424 """, 424 """,
425 """ 425 """
426 @patch class Class { 426 @patch class Class {
427 void _injected() {} 427 void _injected() {}
428 } 428 }
429 """); 429 """);
430 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 430 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
431 expectIsPatched: true); 431 expectIsPatched: true);
432 container.parseNode(compiler.parsing); 432 container.parseNode(compiler.parsingContext);
433 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 433 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
434 expectIsPatch: true); 434 expectIsPatch: true);
435 435
436 ensure(compiler, "_injected", container.lookupLocalMember, 436 ensure(compiler, "_injected", container.lookupLocalMember,
437 expectIsFound: false); 437 expectIsFound: false);
438 ensure(compiler, "_injected", container.patch.lookupLocalMember, 438 ensure(compiler, "_injected", container.patch.lookupLocalMember,
439 checkHasBody: true, expectIsRegular: true); 439 checkHasBody: true, expectIsRegular: true);
440 440
441 DiagnosticCollector collector = compiler.diagnosticCollector; 441 DiagnosticCollector collector = compiler.diagnosticCollector;
442 Expect.isTrue(collector.warnings.isEmpty, 442 Expect.isTrue(collector.warnings.isEmpty,
443 "Unexpected warnings: ${collector.warnings}"); 443 "Unexpected warnings: ${collector.warnings}");
444 Expect.isTrue(collector.errors.isEmpty, 444 Expect.isTrue(collector.errors.isEmpty,
445 "Unexpected errors: ${collector.errors}"); 445 "Unexpected errors: ${collector.errors}");
446 } 446 }
447 447
448 Future testInjectedPublicMember() async { 448 Future testInjectedPublicMember() async {
449 var compiler = await applyPatch( 449 var compiler = await applyPatch(
450 """ 450 """
451 class Class { 451 class Class {
452 } 452 }
453 """, 453 """,
454 """ 454 """
455 @patch class Class { 455 @patch class Class {
456 void injected() {} 456 void injected() {}
457 } 457 }
458 """); 458 """);
459 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 459 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
460 expectIsPatched: true); 460 expectIsPatched: true);
461 container.parseNode(compiler.parsing); 461 container.parseNode(compiler.parsingContext);
462 ensure(compiler, "Class", compiler.coreLibrary.patch.find, 462 ensure(compiler, "Class", compiler.coreLibrary.patch.find,
463 expectIsPatch: true); 463 expectIsPatch: true);
464 464
465 ensure(compiler, "injected", container.lookupLocalMember, 465 ensure(compiler, "injected", container.lookupLocalMember,
466 expectIsFound: false); 466 expectIsFound: false);
467 ensure(compiler, "injected", container.patch.lookupLocalMember, 467 ensure(compiler, "injected", container.patch.lookupLocalMember,
468 checkHasBody: true, expectIsRegular: true); 468 checkHasBody: true, expectIsRegular: true);
469 469
470 DiagnosticCollector collector = compiler.diagnosticCollector; 470 DiagnosticCollector collector = compiler.diagnosticCollector;
471 Expect.isTrue(collector.warnings.isEmpty, 471 Expect.isTrue(collector.warnings.isEmpty,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 @patch void method7([String s2]) {} 548 @patch void method7([String s2]) {}
549 @patch void method8({String s2}) {} 549 @patch void method8({String s2}) {}
550 @patch void method9(int str) {} 550 @patch void method9(int str) {}
551 @patch void method10([int str]) {} 551 @patch void method10([int str]) {}
552 @patch void method11({int str}) {} 552 @patch void method11({int str}) {}
553 } 553 }
554 """); 554 """);
555 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 555 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
556 expectIsPatched: true); 556 expectIsPatched: true);
557 container.ensureResolved(compiler.resolution); 557 container.ensureResolved(compiler.resolution);
558 container.parseNode(compiler.parsing); 558 container.parseNode(compiler.parsingContext);
559 DiagnosticCollector collector = compiler.diagnosticCollector; 559 DiagnosticCollector collector = compiler.diagnosticCollector;
560 560
561 void expect(String methodName, List infos, List errors) { 561 void expect(String methodName, List infos, List errors) {
562 collector.clear(); 562 collector.clear();
563 compiler.resolver.resolveMethodElement( 563 compiler.resolver.resolveMethodElement(
564 ensure(compiler, methodName, container.lookupLocalMember, 564 ensure(compiler, methodName, container.lookupLocalMember,
565 expectIsPatched: true, checkHasBody: true)); 565 expectIsPatched: true, checkHasBody: true));
566 Expect.equals(0, collector.warnings.length); 566 Expect.equals(0, collector.warnings.length);
567 Expect.equals(infos.length, collector.infos.length, 567 Expect.equals(infos.length, collector.infos.length,
568 "Unexpected infos: ${collector.infos} on $methodName"); 568 "Unexpected infos: ${collector.infos} on $methodName");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 external void foo(); 628 external void foo();
629 } 629 }
630 """, 630 """,
631 """ 631 """
632 @patch class Class { 632 @patch class Class {
633 // @patch void foo() {} 633 // @patch void foo() {}
634 } 634 }
635 """); 635 """);
636 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 636 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
637 expectIsPatched: true); 637 expectIsPatched: true);
638 container.parseNode(compiler.parsing); 638 container.parseNode(compiler.parsingContext);
639 DiagnosticCollector collector = compiler.diagnosticCollector; 639 DiagnosticCollector collector = compiler.diagnosticCollector;
640 collector.clear(); 640 collector.clear();
641 compiler.resolver.resolveMethodElement( 641 compiler.resolver.resolveMethodElement(
642 ensure(compiler, "foo", container.lookupLocalMember)); 642 ensure(compiler, "foo", container.lookupLocalMember));
643 Expect.isTrue(collector.warnings.isEmpty, 643 Expect.isTrue(collector.warnings.isEmpty,
644 "Unexpected warnings: ${collector.warnings}"); 644 "Unexpected warnings: ${collector.warnings}");
645 print('testExternalWithoutImplementationMember:${collector.errors}'); 645 print('testExternalWithoutImplementationMember:${collector.errors}');
646 Expect.equals(1, collector.errors.length); 646 Expect.equals(1, collector.errors.length);
647 Expect.isTrue( 647 Expect.isTrue(
648 collector.errors.first.message.kind == 648 collector.errors.first.message.kind ==
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 """ 689 """
690 class Class {} 690 class Class {}
691 """, 691 """,
692 """ 692 """
693 @patch class Class { 693 @patch class Class {
694 @patch void foo() {} 694 @patch void foo() {}
695 } 695 }
696 """); 696 """);
697 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 697 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
698 expectIsPatched: true); 698 expectIsPatched: true);
699 container.parseNode(compiler.parsing); 699 container.parseNode(compiler.parsingContext);
700 DiagnosticCollector collector = compiler.diagnosticCollector; 700 DiagnosticCollector collector = compiler.diagnosticCollector;
701 701
702 Expect.isTrue(collector.warnings.isEmpty, 702 Expect.isTrue(collector.warnings.isEmpty,
703 "Unexpected warnings: ${collector.warnings}"); 703 "Unexpected warnings: ${collector.warnings}");
704 print('testPatchNonExistingMember:${collector.errors}'); 704 print('testPatchNonExistingMember:${collector.errors}');
705 Expect.equals(1, collector.errors.length); 705 Expect.equals(1, collector.errors.length);
706 Expect.isTrue( 706 Expect.isTrue(
707 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING); 707 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXISTING);
708 } 708 }
709 709
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 void foo() {} 777 void foo() {}
778 } 778 }
779 """, 779 """,
780 """ 780 """
781 @patch class Class { 781 @patch class Class {
782 @patch void foo() {} 782 @patch void foo() {}
783 } 783 }
784 """); 784 """);
785 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 785 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
786 expectIsPatched: true); 786 expectIsPatched: true);
787 container.parseNode(compiler.parsing); 787 container.parseNode(compiler.parsingContext);
788 788
789 DiagnosticCollector collector = compiler.diagnosticCollector; 789 DiagnosticCollector collector = compiler.diagnosticCollector;
790 print('testPatchNonExternalMember.errors:${collector.errors}'); 790 print('testPatchNonExternalMember.errors:${collector.errors}');
791 print('testPatchNonExternalMember.warnings:${collector.warnings}'); 791 print('testPatchNonExternalMember.warnings:${collector.warnings}');
792 Expect.equals(1, collector.errors.length); 792 Expect.equals(1, collector.errors.length);
793 Expect.isTrue( 793 Expect.isTrue(
794 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL); 794 collector.errors.first.message.kind == MessageKind.PATCH_NON_EXTERNAL);
795 Expect.equals(0, collector.warnings.length); 795 Expect.equals(0, collector.warnings.length);
796 Expect.equals(1, collector.infos.length); 796 Expect.equals(1, collector.infos.length);
797 Expect.isTrue(collector.infos.first.message.kind == 797 Expect.isTrue(collector.infos.first.message.kind ==
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 await testPatchNonFunction(); 1110 await testPatchNonFunction();
1111 1111
1112 await testPatchAndSelector(); 1112 await testPatchAndSelector();
1113 1113
1114 await testEffectiveTarget(); 1114 await testEffectiveTarget();
1115 1115
1116 await testAnalyzeAllInjectedMembers(); 1116 await testAnalyzeAllInjectedMembers();
1117 await testTypecheckPatchedMembers(); 1117 await testTypecheckPatchedMembers();
1118 }); 1118 });
1119 } 1119 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/parser_helper.dart ('k') | tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698