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

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 2054323002: Fix exit detection for try statements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add tests without a "finally" clause Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 3461 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 } 3472 }
3473 3473
3474 void test_conditionalCall_rhs2() { 3474 void test_conditionalCall_rhs2() {
3475 _assertFalse("null?.b(throw '');"); 3475 _assertFalse("null?.b(throw '');");
3476 } 3476 }
3477 3477
3478 void test_creation() { 3478 void test_creation() {
3479 expect(new ExitDetector(), isNotNull); 3479 expect(new ExitDetector(), isNotNull);
3480 } 3480 }
3481 3481
3482 void test_doStatement_return() {
3483 _assertTrue("{ do { return null; } while (1 == 2); }");
3484 }
3485
3482 void test_doStatement_throwCondition() { 3486 void test_doStatement_throwCondition() {
3483 _assertTrue("{ do {} while (throw ''); }"); 3487 _assertTrue("{ do {} while (throw ''); }");
3484 } 3488 }
3485 3489
3486 void test_doStatement_return() {
3487 _assertTrue("{ do { return null; } while (1 == 2); }");
3488 }
3489
3490 void test_doStatement_true_break() { 3490 void test_doStatement_true_break() {
3491 _assertFalse("{ do { break; } while (true); }"); 3491 _assertFalse("{ do { break; } while (true); }");
3492 } 3492 }
3493 3493
3494 void test_doStatement_true_continue() { 3494 void test_doStatement_true_continue() {
3495 _assertTrue("{ do { continue; } while (true); }"); 3495 _assertTrue("{ do { continue; } while (true); }");
3496 } 3496 }
3497 3497
3498 void test_doStatement_true_if_return() { 3498 void test_doStatement_true_if_return() {
3499 _assertTrue("{ do { if (true) {return null;} } while (true); }"); 3499 _assertTrue("{ do { if (true) {return null;} } while (true); }");
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
3772 } 3772 }
3773 3773
3774 void test_throwExpression() { 3774 void test_throwExpression() {
3775 _assertTrue("throw new Object();"); 3775 _assertTrue("throw new Object();");
3776 } 3776 }
3777 3777
3778 void test_tryStatement_noReturn() { 3778 void test_tryStatement_noReturn() {
3779 _assertFalse("try {} catch (e, s) {} finally {}"); 3779 _assertFalse("try {} catch (e, s) {} finally {}");
3780 } 3780 }
3781 3781
3782 void test_tryStatement_noReturn_noFinally() {
3783 _assertFalse("try {} catch (e, s) {}");
3784 }
3785
3782 void test_tryStatement_return_catch() { 3786 void test_tryStatement_return_catch() {
3783 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); 3787 _assertFalse("try {} catch (e, s) { return 1; } finally {}");
3784 } 3788 }
3785 3789
3790 void test_tryStatement_return_catch_noFinally() {
3791 _assertFalse("try {} catch (e, s) { return 1; }");
3792 }
3793
3786 void test_tryStatement_return_finally() { 3794 void test_tryStatement_return_finally() {
3787 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); 3795 _assertTrue("try {} catch (e, s) {} finally { return 1; }");
3788 } 3796 }
3789 3797
3790 void test_tryStatement_return_try() { 3798 void test_tryStatement_return_try_noCatch() {
3791 _assertTrue("try { return 1; } catch (e, s) {} finally {}"); 3799 _assertTrue("try { return 1; } finally {}");
3800 }
3801
3802 void test_tryStatement_return_try_oneCatchDoesNotExit() {
3803 _assertFalse("try { return 1; } catch (e, s) {} finally {}");
3804 }
3805
3806 void test_tryStatement_return_try_oneCatchDoesNotExit_noFinally() {
3807 _assertFalse("try { return 1; } catch (e, s) {}");
3808 }
3809
3810 void test_tryStatement_return_try_oneCatchExits() {
3811 _assertTrue("try { return 1; } catch (e, s) { return 1; } finally {}");
3812 }
3813
3814 void test_tryStatement_return_try_oneCatchExits_noFinally() {
3815 _assertTrue("try { return 1; } catch (e, s) { return 1; }");
3816 }
3817
3818 void test_tryStatement_return_try_twoCatchesDoExit() {
3819 _assertTrue('''
3820 try { return 1; }
3821 on int catch (e, s) { return 1; }
3822 on String catch (e, s) { return 1; }
3823 finally {}''');
3824 }
3825
3826 void test_tryStatement_return_try_twoCatchesDoExit_noFinally() {
3827 _assertTrue('''
3828 try { return 1; }
3829 on int catch (e, s) { return 1; }
3830 on String catch (e, s) { return 1; }''');
3831 }
3832
3833 void test_tryStatement_return_try_twoCatchesDoNotExit() {
3834 _assertFalse('''
3835 try { return 1; }
3836 on int catch (e, s) {}
3837 on String catch (e, s) {}
3838 finally {}''');
3839 }
3840
3841 void test_tryStatement_return_try_twoCatchesDoNotExit_noFinally() {
3842 _assertFalse('''
3843 try { return 1; }
3844 on int catch (e, s) {}
3845 on String catch (e, s) {}''');
3846 }
3847
3848 void test_tryStatement_return_try_twoCatchesMixed() {
3849 _assertFalse('''
3850 try { return 1; }
3851 on int catch (e, s) {}
3852 on String catch (e, s) { return 1; }
3853 finally {}''');
3854 }
3855
3856 void test_tryStatement_return_try_twoCatchesMixed_noFinally() {
3857 _assertFalse('''
3858 try { return 1; }
3859 on int catch (e, s) {}
3860 on String catch (e, s) { return 1; }''');
3792 } 3861 }
3793 3862
3794 void test_variableDeclarationStatement_noInitializer() { 3863 void test_variableDeclarationStatement_noInitializer() {
3795 _assertFalse("int i;"); 3864 _assertFalse("int i;");
3796 } 3865 }
3797 3866
3798 void test_variableDeclarationStatement_noThrow() { 3867 void test_variableDeclarationStatement_noThrow() {
3799 _assertFalse("int i = 0;"); 3868 _assertFalse("int i = 0;");
3800 } 3869 }
3801 3870
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3980 4049
3981 void test_yieldStatement_plain() { 4050 void test_yieldStatement_plain() {
3982 Source source = addSource(r''' 4051 Source source = addSource(r'''
3983 void f() sync* { 4052 void f() sync* {
3984 yield 1; 4053 yield 1;
3985 } 4054 }
3986 '''); 4055 ''');
3987 _assertNthStatementDoesNotExit(source, 0); 4056 _assertNthStatementDoesNotExit(source, 0);
3988 } 4057 }
3989 4058
3990 void test_yieldStatement_throw() {
3991 Source source = addSource(r'''
3992 void f() sync* {
3993 yield throw '';
3994 }
3995 ''');
3996 _assertNthStatementExits(source, 0);
3997 }
3998
3999 void test_yieldStatement_star_plain() { 4059 void test_yieldStatement_star_plain() {
4000 Source source = addSource(r''' 4060 Source source = addSource(r'''
4001 void f() sync* { 4061 void f() sync* {
4002 yield* 1; 4062 yield* 1;
4003 } 4063 }
4004 '''); 4064 ''');
4005 _assertNthStatementDoesNotExit(source, 0); 4065 _assertNthStatementDoesNotExit(source, 0);
4006 } 4066 }
4007 4067
4008 void test_yieldStatement_star_throw() { 4068 void test_yieldStatement_star_throw() {
4009 Source source = addSource(r''' 4069 Source source = addSource(r'''
4010 void f() sync* { 4070 void f() sync* {
4011 yield* throw ''; 4071 yield* throw '';
4012 } 4072 }
4013 '''); 4073 ''');
4014 _assertNthStatementExits(source, 0); 4074 _assertNthStatementExits(source, 0);
4075 }
4076
4077 void test_yieldStatement_throw() {
4078 Source source = addSource(r'''
4079 void f() sync* {
4080 yield throw '';
4081 }
4082 ''');
4083 _assertNthStatementExits(source, 0);
4015 } 4084 }
4016 4085
4017 void _assertHasReturn(bool expectedResult, Source source, int n) { 4086 void _assertHasReturn(bool expectedResult, Source source, int n) {
4018 LibraryElement element = resolve2(source); 4087 LibraryElement element = resolve2(source);
4019 CompilationUnit unit = resolveCompilationUnit(source, element); 4088 CompilationUnit unit = resolveCompilationUnit(source, element);
4020 FunctionDeclaration function = unit.declarations.last; 4089 FunctionDeclaration function = unit.declarations.last;
4021 BlockFunctionBody body = function.functionExpression.body; 4090 BlockFunctionBody body = function.functionExpression.body;
4022 Statement statement = body.block.statements[n]; 4091 Statement statement = body.block.statements[n];
4023 expect(ExitDetector.exits(statement), expectedResult); 4092 expect(ExitDetector.exits(statement), expectedResult);
4024 } 4093 }
4025 4094
4026 // Assert that the [n]th statement in the last function declaration of 4095 // Assert that the [n]th statement in the last function declaration of
4027 // [source] exits. 4096 // [source] exits.
4028 void _assertNthStatementExits(Source source, int n) { 4097 void _assertNthStatementDoesNotExit(Source source, int n) {
4029 _assertHasReturn(true, source, n); 4098 _assertHasReturn(false, source, n);
4030 } 4099 }
4031 4100
4032 // Assert that the [n]th statement in the last function declaration of 4101 // Assert that the [n]th statement in the last function declaration of
4033 // [source] does not exit. 4102 // [source] does not exit.
4034 void _assertNthStatementDoesNotExit(Source source, int n) { 4103 void _assertNthStatementExits(Source source, int n) {
4035 _assertHasReturn(false, source, n); 4104 _assertHasReturn(true, source, n);
4036 } 4105 }
4037 } 4106 }
4038 4107
4039 @reflectiveTest 4108 @reflectiveTest
4040 class FileBasedSourceTest { 4109 class FileBasedSourceTest {
4041 void test_equals_false_differentFiles() { 4110 void test_equals_false_differentFiles() {
4042 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); 4111 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart");
4043 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); 4112 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart");
4044 FileBasedSource source1 = new FileBasedSource(file1); 4113 FileBasedSource source1 = new FileBasedSource(file1);
4045 FileBasedSource source2 = new FileBasedSource(file2); 4114 FileBasedSource source2 = new FileBasedSource(file2);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
4407 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 4476 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
4408 expect(UriKind.fromEncoding(0x58), same(null)); 4477 expect(UriKind.fromEncoding(0x58), same(null));
4409 } 4478 }
4410 4479
4411 void test_getEncoding() { 4480 void test_getEncoding() {
4412 expect(UriKind.DART_URI.encoding, 0x64); 4481 expect(UriKind.DART_URI.encoding, 0x64);
4413 expect(UriKind.FILE_URI.encoding, 0x66); 4482 expect(UriKind.FILE_URI.encoding, 0x66);
4414 expect(UriKind.PACKAGE_URI.encoding, 0x70); 4483 expect(UriKind.PACKAGE_URI.encoding, 0x70);
4415 } 4484 }
4416 } 4485 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/non_hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698