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

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

Issue 20742002: Clean up error handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added documentation guide lines. Created 7 years, 4 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 "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; 6 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart";
7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
8 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; 9 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
10 import "mock_compiler.dart"; 10 import "mock_compiler.dart";
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 """); 379 """);
380 var function = ensure(compiler, "foo", compiler.coreLibrary.find); 380 var function = ensure(compiler, "foo", compiler.coreLibrary.find);
381 compiler.resolver.resolve(function); 381 compiler.resolver.resolve(function);
382 Expect.isTrue(compiler.warnings.isEmpty, 382 Expect.isTrue(compiler.warnings.isEmpty,
383 "Unexpected warnings: ${compiler.warnings}"); 383 "Unexpected warnings: ${compiler.warnings}");
384 print('testExternalWithoutImplementationTopLevel:${compiler.errors}'); 384 print('testExternalWithoutImplementationTopLevel:${compiler.errors}');
385 Expect.equals(1, compiler.errors.length); 385 Expect.equals(1, compiler.errors.length);
386 Expect.isTrue( 386 Expect.isTrue(
387 compiler.errors[0].message.kind == 387 compiler.errors[0].message.kind ==
388 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 388 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
389 Expect.equals('External method without an implementation.', 389 Expect.stringEquals('Error: External method without an implementation.',
390 compiler.errors[0].message.toString()); 390 compiler.errors[0].message.toString());
391 } 391 }
392 392
393 testExternalWithoutImplementationMember() { 393 testExternalWithoutImplementationMember() {
394 var compiler = applyPatch( 394 var compiler = applyPatch(
395 """ 395 """
396 class Class { 396 class Class {
397 external void foo(); 397 external void foo();
398 } 398 }
399 """, 399 """,
400 """ 400 """
401 patch class Class { 401 patch class Class {
402 // patch void foo() {} 402 // patch void foo() {}
403 } 403 }
404 """); 404 """);
405 var container = ensure(compiler, "Class", compiler.coreLibrary.find, 405 var container = ensure(compiler, "Class", compiler.coreLibrary.find,
406 expectIsPatched: true); 406 expectIsPatched: true);
407 container.parseNode(compiler); 407 container.parseNode(compiler);
408 408
409 compiler.warnings.clear(); 409 compiler.warnings.clear();
410 compiler.errors.clear(); 410 compiler.errors.clear();
411 compiler.resolver.resolveMethodElement( 411 compiler.resolver.resolveMethodElement(
412 ensure(compiler, "foo", container.lookupLocalMember)); 412 ensure(compiler, "foo", container.lookupLocalMember));
413 Expect.isTrue(compiler.warnings.isEmpty, 413 Expect.isTrue(compiler.warnings.isEmpty,
414 "Unexpected warnings: ${compiler.warnings}"); 414 "Unexpected warnings: ${compiler.warnings}");
415 print('testExternalWithoutImplementationMember:${compiler.errors}'); 415 print('testExternalWithoutImplementationMember:${compiler.errors}');
416 Expect.equals(1, compiler.errors.length); 416 Expect.equals(1, compiler.errors.length);
417 Expect.isTrue( 417 Expect.isTrue(
418 compiler.errors[0].message.kind == 418 compiler.errors[0].message.kind ==
419 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION); 419 MessageKind.PATCH_EXTERNAL_WITHOUT_IMPLEMENTATION);
420 Expect.equals('External method without an implementation.', 420 Expect.stringEquals('Error: External method without an implementation.',
421 compiler.errors[0].message.toString()); 421 compiler.errors[0].message.toString());
422 } 422 }
423 423
424 testIsSubclass() { 424 testIsSubclass() {
425 var compiler = applyPatch( 425 var compiler = applyPatch(
426 """ 426 """
427 class A {} 427 class A {}
428 """, 428 """,
429 """ 429 """
430 patch class A {} 430 patch class A {}
431 """); 431 """);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 cls = ensure(compiler, "B", compiler.coreLibrary.find); 714 cls = ensure(compiler, "B", compiler.coreLibrary.find);
715 cls.ensureResolved(compiler); 715 cls.ensureResolved(compiler);
716 typedSelector = new TypedSelector.exact(cls.rawType, selector); 716 typedSelector = new TypedSelector.exact(cls.rawType, selector);
717 Expect.isTrue(selector.applies(method, compiler)); 717 Expect.isTrue(selector.applies(method, compiler));
718 Expect.isTrue(typedSelector.applies(method, compiler)); 718 Expect.isTrue(typedSelector.applies(method, compiler));
719 } 719 }
720 720
721 void testAnalyzeAllInjectedMembers() { 721 void testAnalyzeAllInjectedMembers() {
722 void expect(String patchText, [expectedWarnings]) { 722 void expect(String patchText, [expectedWarnings]) {
723 if (expectedWarnings == null) expectedWarnings = []; 723 if (expectedWarnings == null) expectedWarnings = [];
724 if (expectedWarnings is! List) expectedWarnings = [expectedWarnings]; 724 if (expectedWarnings is! List) {
725 expectedWarnings = <MessageKind>[expectedWarnings];
726 }
725 727
726 var compiler = applyPatch('', patchText, 728 var compiler = applyPatch('', patchText,
727 analyzeAll: true, analyzeOnly: true); 729 analyzeAll: true, analyzeOnly: true);
728 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 730 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
729 compiler.runCompiler(null); 731 compiler.runCompiler(null);
730 compareWarningKinds(patchText, expectedWarnings, compiler.warnings); 732 compareWarningKinds(patchText, expectedWarnings, compiler.warnings);
731 } 733 }
732 734
733 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE); 735 expect('String s = 0;', MessageKind.NOT_ASSIGNABLE.warning);
734 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE); 736 expect('void method() { String s = 0; }', MessageKind.NOT_ASSIGNABLE.warning);
735 expect(''' 737 expect('''
736 class Class { 738 class Class {
737 String s = 0; 739 String s = 0;
738 } 740 }
739 ''', 741 ''',
740 MessageKind.NOT_ASSIGNABLE); 742 MessageKind.NOT_ASSIGNABLE.warning);
741 expect(''' 743 expect('''
742 class Class { 744 class Class {
743 void method() { 745 void method() {
744 String s = 0; 746 String s = 0;
745 } 747 }
746 } 748 }
747 ''', 749 ''',
748 MessageKind.NOT_ASSIGNABLE); 750 MessageKind.NOT_ASSIGNABLE.warning);
749 } 751 }
750 752
751 void testTypecheckPatchedMembers() { 753 void testTypecheckPatchedMembers() {
752 String originText = "external void method();"; 754 String originText = "external void method();";
753 String patchText = """ 755 String patchText = """
754 patch void method() { 756 patch void method() {
755 String s = 0; 757 String s = 0;
756 } 758 }
757 """; 759 """;
758 var compiler = applyPatch(originText, patchText, 760 var compiler = applyPatch(originText, patchText,
759 analyzeAll: true, analyzeOnly: true); 761 analyzeAll: true, analyzeOnly: true);
760 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')]; 762 compiler.librariesToAnalyzeWhenRun = [Uri.parse('dart:core')];
761 compiler.runCompiler(null); 763 compiler.runCompiler(null);
762 compareWarningKinds(patchText, 764 compareWarningKinds(patchText,
763 [MessageKind.NOT_ASSIGNABLE], compiler.warnings); 765 [MessageKind.NOT_ASSIGNABLE.warning], compiler.warnings);
764 } 766 }
765 767
766 main() { 768 main() {
767 testPatchConstructor(); 769 testPatchConstructor();
768 testPatchFunction(); 770 testPatchFunction();
769 testPatchMember(); 771 testPatchMember();
770 testPatchGetter(); 772 testPatchGetter();
771 testRegularMember(); 773 testRegularMember();
772 testGhostMember(); 774 testGhostMember();
773 testInjectFunction(); 775 testInjectFunction();
(...skipping 15 matching lines...) Expand all
789 testPatchNoGetter(); 791 testPatchNoGetter();
790 testPatchNonSetter(); 792 testPatchNonSetter();
791 testPatchNoSetter(); 793 testPatchNoSetter();
792 testPatchNonFunction(); 794 testPatchNonFunction();
793 795
794 testPatchAndSelector(); 796 testPatchAndSelector();
795 797
796 testAnalyzeAllInjectedMembers(); 798 testAnalyzeAllInjectedMembers();
797 testTypecheckPatchedMembers(); 799 testTypecheckPatchedMembers();
798 } 800 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698