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'; |
11 | 11 |
12 import '../reflective_tests.dart'; | 12 import '../reflective_tests.dart'; |
13 import '../utils.dart'; | 13 import '../utils.dart'; |
14 import 'analysis_context_factory.dart'; | 14 import 'analysis_context_factory.dart'; |
15 import 'resolver_test_case.dart'; | 15 import 'resolver_test_case.dart'; |
16 | 16 |
17 main() { | 17 main() { |
18 initializeTestEnvironment(); | 18 initializeTestEnvironment(); |
19 runReflectiveTests(HintCodeTest); | 19 runReflectiveTests(HintCodeTest); |
20 } | 20 } |
21 | 21 |
22 @reflectiveTest | 22 @reflectiveTest |
23 class HintCodeTest extends ResolverTestCase { | 23 class HintCodeTest extends ResolverTestCase { |
24 void fail_deadCode_statementAfterRehrow() { | 24 void deadCode_statementAfterRethrow() { |
Brian Wilkerson
2016/05/20 18:04:28
nit: These method names need to start with "test_"
srawlins
2016/05/23 20:07:53
Done.
| |
25 Source source = addSource(r''' | 25 Source source = addSource(r''' |
26 f() { | 26 f() { |
27 try { | 27 try { |
28 var one = 1; | 28 var one = 1; |
29 } catch (e) { | 29 } catch (e) { |
30 rethrow; | 30 rethrow; |
31 var two = 2; | 31 var two = 2; |
32 } | 32 } |
33 }'''); | 33 }'''); |
34 computeLibrarySourceErrors(source); | 34 computeLibrarySourceErrors(source); |
35 assertErrors(source, [HintCode.DEAD_CODE]); | 35 assertErrors(source, [HintCode.DEAD_CODE]); |
36 verify([source]); | 36 verify([source]); |
37 } | 37 } |
38 | 38 |
39 void fail_deadCode_statementAfterThrow() { | 39 void deadCode_statementAfterThrow() { |
40 Source source = addSource(r''' | 40 Source source = addSource(r''' |
41 f() { | 41 f() { |
42 var one = 1; | 42 var one = 1; |
43 throw 'Stop here'; | 43 throw 'Stop here'; |
44 var two = 2; | 44 var two = 2; |
45 }'''); | 45 }'''); |
46 computeLibrarySourceErrors(source); | 46 computeLibrarySourceErrors(source); |
47 assertErrors(source, [HintCode.DEAD_CODE]); | 47 assertErrors(source, [HintCode.DEAD_CODE]); |
48 verify([source]); | 48 verify([source]); |
49 } | 49 } |
(...skipping 562 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_returns() { | |
623 Source source = addSource(r''' | |
624 f() { | |
625 if (1 > 2) { | |
626 return; | |
627 } else { | |
628 return; | |
629 } | |
630 var one = 1; | |
631 }'''); | |
632 computeLibrarySourceErrors(source); | |
633 assertErrors(source, [HintCode.DEAD_CODE]); | |
634 verify([source]); | |
635 } | |
636 | |
622 void test_deprecatedAnnotationUse_assignment() { | 637 void test_deprecatedAnnotationUse_assignment() { |
623 Source source = addSource(r''' | 638 Source source = addSource(r''' |
624 class A { | 639 class A { |
625 @deprecated | 640 @deprecated |
626 A operator+(A a) { return a; } | 641 A operator+(A a) { return a; } |
627 } | 642 } |
628 f(A a) { | 643 f(A a) { |
629 A b; | 644 A b; |
630 a += b; | 645 a += b; |
631 }'''); | 646 }'''); |
(...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3355 n() { | 3370 n() { |
3356 var a = m(), b = m(); | 3371 var a = m(), b = m(); |
3357 } | 3372 } |
3358 }'''); | 3373 }'''); |
3359 computeLibrarySourceErrors(source); | 3374 computeLibrarySourceErrors(source); |
3360 assertErrors( | 3375 assertErrors( |
3361 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 3376 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
3362 verify([source]); | 3377 verify([source]); |
3363 } | 3378 } |
3364 } | 3379 } |
OLD | NEW |