Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library analyzer.test.generated.hint_code_test; | 5 library analyzer.test.generated.hint_code_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/engine.dart'; | 7 import 'package:analyzer/src/generated/engine.dart'; |
| 8 import 'package:analyzer/src/generated/error.dart'; | 8 import 'package:analyzer/src/generated/error.dart'; |
| 9 import 'package:analyzer/src/generated/source_io.dart'; | 9 import 'package:analyzer/src/generated/source_io.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 return; | 612 return; |
| 613 var two = 2; | 613 var two = 2; |
| 614 return; | 614 return; |
| 615 var three = 3; | 615 var three = 3; |
| 616 }'''); | 616 }'''); |
| 617 computeLibrarySourceErrors(source); | 617 computeLibrarySourceErrors(source); |
| 618 assertErrors(source, [HintCode.DEAD_CODE]); | 618 assertErrors(source, [HintCode.DEAD_CODE]); |
| 619 verify([source]); | 619 verify([source]); |
| 620 } | 620 } |
| 621 | 621 |
| 622 void test_deadCode_statementAfterExitingIf_function() { | |
|
Brian Wilkerson
2016/05/04 17:28:19
If ExitDetector worked, then most of these tests c
srawlins
2016/05/19 18:36:44
You're right. Dramatically reduced tests!
| |
| 623 Source source = addSource(r''' | |
| 624 f() { | |
| 625 if (1 > 2) { | |
| 626 return; | |
| 627 } else { | |
| 628 return; | |
| 629 } | |
| 630 var two = 2; | |
| 631 }'''); | |
| 632 computeLibrarySourceErrors(source); | |
| 633 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 634 verify([source]); | |
| 635 } | |
| 636 | |
| 637 void test_deadCode_statementAfterExitingIf_returns() { | |
| 638 Source source = addSource(r''' | |
| 639 f() { | |
| 640 if (1 > 2) { | |
| 641 return; | |
| 642 } else { | |
| 643 return; | |
| 644 } | |
| 645 var one = 1; | |
| 646 }'''); | |
| 647 computeLibrarySourceErrors(source); | |
| 648 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 649 verify([source]); | |
| 650 } | |
| 651 | |
| 652 void test_deadCode_statementAfterExitingIf_throws() { | |
| 653 Source source = addSource(r''' | |
| 654 f() { | |
| 655 if (1 > 2) { | |
| 656 throw 'Stopping in then'; | |
| 657 } else { | |
| 658 throw 'Stopping in else'; | |
| 659 } | |
| 660 var one = 1; | |
| 661 }'''); | |
| 662 computeLibrarySourceErrors(source); | |
| 663 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 664 verify([source]); | |
| 665 } | |
| 666 | |
| 667 void test_deadCode_statementAfterExitingIf_loops() { | |
| 668 Source source = addSource(r''' | |
| 669 f() { | |
| 670 if (1 > 2) { | |
| 671 while (true) { print('Hello'); } | |
| 672 } else { | |
| 673 while (true) { print('Hello'); } | |
| 674 } | |
| 675 var one = 1; | |
| 676 }'''); | |
| 677 computeLibrarySourceErrors(source); | |
| 678 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 679 verify([source]); | |
| 680 } | |
| 681 | |
| 682 void test_deadCode_statementAfterExitingDo_returns() { | |
| 683 Source source = addSource(r''' | |
| 684 f() { | |
| 685 do { | |
| 686 return; | |
| 687 } while (1 < 0); | |
| 688 var one = 1; | |
| 689 }'''); | |
| 690 computeLibrarySourceErrors(source); | |
| 691 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 692 verify([source]); | |
| 693 } | |
| 694 | |
| 695 void test_deadCode_statementAfterExitingDo_throws() { | |
| 696 Source source = addSource(r''' | |
| 697 f() { | |
| 698 do { | |
| 699 throw 'me'; | |
| 700 } while (1 < 0); | |
| 701 var one = 1; | |
| 702 }'''); | |
| 703 computeLibrarySourceErrors(source); | |
| 704 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 705 verify([source]); | |
| 706 } | |
| 707 | |
| 708 void test_deadCode_statementAfterExitingDo_loops() { | |
| 709 Source source = addSource(r''' | |
| 710 f() { | |
| 711 do { | |
| 712 while (true) print('Hello'); | |
| 713 } while (1 < 0); | |
| 714 var one = 1; | |
| 715 }'''); | |
| 716 computeLibrarySourceErrors(source); | |
| 717 assertErrors(source, [HintCode.DEAD_CODE]); | |
| 718 verify([source]); | |
| 719 } | |
| 720 | |
| 622 void test_deprecatedAnnotationUse_assignment() { | 721 void test_deprecatedAnnotationUse_assignment() { |
| 623 Source source = addSource(r''' | 722 Source source = addSource(r''' |
| 624 class A { | 723 class A { |
| 625 @deprecated | 724 @deprecated |
| 626 A operator+(A a) { return a; } | 725 A operator+(A a) { return a; } |
| 627 } | 726 } |
| 628 f(A a) { | 727 f(A a) { |
| 629 A b; | 728 A b; |
| 630 a += b; | 729 a += b; |
| 631 }'''); | 730 }'''); |
| (...skipping 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3312 n() { | 3411 n() { |
| 3313 var a = m(), b = m(); | 3412 var a = m(), b = m(); |
| 3314 } | 3413 } |
| 3315 }'''); | 3414 }'''); |
| 3316 computeLibrarySourceErrors(source); | 3415 computeLibrarySourceErrors(source); |
| 3317 assertErrors( | 3416 assertErrors( |
| 3318 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 3417 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 3319 verify([source]); | 3418 verify([source]); |
| 3320 } | 3419 } |
| 3321 } | 3420 } |
| OLD | NEW |