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

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

Issue 2625783002: Explicitly compute analysis results for sources to check errors. (Closed)
Patch Set: Rollback await(ing) of assertErrors(). Format. Created 3 years, 11 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) 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.strong_mode_test; 5 library analyzer.test.generated.strong_mode_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8
8 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
10 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
13 import 'package:analyzer/src/error/codes.dart'; 14 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 15 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source_io.dart'; 16 import 'package:analyzer/src/generated/source_io.dart';
16 import 'package:test/test.dart'; 17 import 'package:test/test.dart';
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; 18 import 'package:test_reflective_loader/test_reflective_loader.dart';
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 } 679 }
679 680
680 test_inference_hints() async { 681 test_inference_hints() async {
681 Source source = addSource(r''' 682 Source source = addSource(r'''
682 void main () { 683 void main () {
683 var x = 3; 684 var x = 3;
684 List<int> l0 = []; 685 List<int> l0 = [];
685 } 686 }
686 '''); 687 ''');
687 resolve2(source); 688 resolve2(source);
688 await assertNoErrors(source); 689 await computeAnalysisResult(source);
690 assertNoErrors(source);
689 verify([source]); 691 verify([source]);
690 } 692 }
691 693
692 test_inferredFieldDeclaration_propagation() async { 694 test_inferredFieldDeclaration_propagation() async {
693 // Regression test for https://github.com/dart-lang/sdk/issues/25546 695 // Regression test for https://github.com/dart-lang/sdk/issues/25546
694 String code = r''' 696 String code = r'''
695 abstract class A { 697 abstract class A {
696 Map<int, List<int>> get map; 698 Map<int, List<int>> get map;
697 } 699 }
698 class B extends A { 700 class B extends A {
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 '''); 1323 ''');
1322 expectIdentifierType('methodTearOffInst', "(int) → int"); 1324 expectIdentifierType('methodTearOffInst', "(int) → int");
1323 expectIdentifierType('staticTearOffInst', "(int) → int"); 1325 expectIdentifierType('staticTearOffInst', "(int) → int");
1324 expectIdentifierType('staticFieldTearOffInst', "(int) → int"); 1326 expectIdentifierType('staticFieldTearOffInst', "(int) → int");
1325 expectIdentifierType('topFunTearOffInst', "(int) → int"); 1327 expectIdentifierType('topFunTearOffInst', "(int) → int");
1326 expectIdentifierType('topFieldTearOffInst', "(int) → int"); 1328 expectIdentifierType('topFieldTearOffInst', "(int) → int");
1327 expectIdentifierType('localTearOffInst', "(int) → int"); 1329 expectIdentifierType('localTearOffInst', "(int) → int");
1328 expectIdentifierType('paramTearOffInst', "(int) → int"); 1330 expectIdentifierType('paramTearOffInst', "(int) → int");
1329 } 1331 }
1330 1332
1331 Future<Null> _objectMethodOnFunctions_helper2(String code) async {
1332 await resolveTestUnit(code);
1333 expectIdentifierType('t0', "String");
1334 expectIdentifierType('t1', "() → String");
1335 expectIdentifierType('t2', "int");
1336 expectIdentifierType('t3', "String");
1337 expectIdentifierType('t4', "() → String");
1338 expectIdentifierType('t5', "int");
1339 }
1340
1341 void setUp() { 1333 void setUp() {
1342 super.setUp(); 1334 super.setUp();
1343 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1335 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1344 options.strongMode = true; 1336 options.strongMode = true;
1345 resetWithOptions(options); 1337 resetWithOptions(options);
1346 } 1338 }
1347 1339
1348 test_dynamicObjectGetter_hashCode() async { 1340 test_dynamicObjectGetter_hashCode() async {
1349 String code = r''' 1341 String code = r'''
1350 main() { 1342 main() {
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 } 1799 }
1808 1800
1809 test_genericMethod_override_invalidReturnType() async { 1801 test_genericMethod_override_invalidReturnType() async {
1810 Source source = addSource(r''' 1802 Source source = addSource(r'''
1811 class C { 1803 class C {
1812 Iterable/*<T>*/ f/*<T>*/(/*=T*/ x) => null; 1804 Iterable/*<T>*/ f/*<T>*/(/*=T*/ x) => null;
1813 } 1805 }
1814 class D extends C { 1806 class D extends C {
1815 String f/*<S>*/(/*=S*/ x) => null; 1807 String f/*<S>*/(/*=S*/ x) => null;
1816 }'''); 1808 }''');
1817 await assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); 1809 await computeAnalysisResult(source);
1810 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
1818 verify([source]); 1811 verify([source]);
1819 } 1812 }
1820 1813
1821 test_genericMethod_override_invalidTypeParamBounds() async { 1814 test_genericMethod_override_invalidTypeParamBounds() async {
1822 Source source = addSource(r''' 1815 Source source = addSource(r'''
1823 class A {} 1816 class A {}
1824 class B extends A {} 1817 class B extends A {}
1825 class C { 1818 class C {
1826 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null; 1819 /*=T*/ f/*<T extends A>*/(/*=T*/ x) => null;
1827 } 1820 }
1828 class D extends C { 1821 class D extends C {
1829 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null; 1822 /*=T*/ f/*<T extends B>*/(/*=T*/ x) => null;
1830 }'''); 1823 }''');
1831 await assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); 1824 await computeAnalysisResult(source);
1825 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
1832 verify([source]); 1826 verify([source]);
1833 } 1827 }
1834 1828
1835 test_genericMethod_override_invalidTypeParamCount() async { 1829 test_genericMethod_override_invalidTypeParamCount() async {
1836 Source source = addSource(r''' 1830 Source source = addSource(r'''
1837 class C { 1831 class C {
1838 /*=T*/ f/*<T>*/(/*=T*/ x) => null; 1832 /*=T*/ f/*<T>*/(/*=T*/ x) => null;
1839 } 1833 }
1840 class D extends C { 1834 class D extends C {
1841 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null; 1835 /*=S*/ f/*<T, S>*/(/*=T*/ x) => null;
1842 }'''); 1836 }''');
1843 await assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]); 1837 await computeAnalysisResult(source);
1838 assertErrors(source, [StrongModeCode.INVALID_METHOD_OVERRIDE]);
1844 verify([source]); 1839 verify([source]);
1845 } 1840 }
1846 1841
1847 test_genericMethod_propagatedType_promotion() async { 1842 test_genericMethod_propagatedType_promotion() async {
1848 // Regression test for: 1843 // Regression test for:
1849 // https://github.com/dart-lang/sdk/issues/25340 1844 // https://github.com/dart-lang/sdk/issues/25340
1850 1845
1851 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original 1846 // Note, after https://github.com/dart-lang/sdk/issues/25486 the original
1852 // example won't work, as we now compute a static type and therefore discard 1847 // example won't work, as we now compute a static type and therefore discard
1853 // the propagated type. So a new test was created that doesn't run under 1848 // the propagated type. So a new test was created that doesn't run under
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 await _objectMethodOnFunctions_helper2(code); 2069 await _objectMethodOnFunctions_helper2(code);
2075 } 2070 }
2076 2071
2077 test_setterWithDynamicTypeIsError() async { 2072 test_setterWithDynamicTypeIsError() async {
2078 Source source = addSource(r''' 2073 Source source = addSource(r'''
2079 class A { 2074 class A {
2080 dynamic set f(String s) => null; 2075 dynamic set f(String s) => null;
2081 } 2076 }
2082 dynamic set g(int x) => null; 2077 dynamic set g(int x) => null;
2083 '''); 2078 ''');
2084 await assertErrors(source, [ 2079 await computeAnalysisResult(source);
2080 assertErrors(source, [
2085 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, 2081 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER,
2086 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER 2082 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
2087 ]); 2083 ]);
2088 verify([source]); 2084 verify([source]);
2089 } 2085 }
2090 2086
2091 test_setterWithExplicitVoidType_returningVoid() async { 2087 test_setterWithExplicitVoidType_returningVoid() async {
2092 Source source = addSource(r''' 2088 Source source = addSource(r'''
2093 void returnsVoid() {} 2089 void returnsVoid() {}
2094 class A { 2090 class A {
2095 void set f(String s) => returnsVoid(); 2091 void set f(String s) => returnsVoid();
2096 } 2092 }
2097 void set g(int x) => returnsVoid(); 2093 void set g(int x) => returnsVoid();
2098 '''); 2094 ''');
2099 await assertNoErrors(source); 2095 await computeAnalysisResult(source);
2096 assertNoErrors(source);
2100 verify([source]); 2097 verify([source]);
2101 } 2098 }
2102 2099
2103 test_setterWithNoVoidType() async { 2100 test_setterWithNoVoidType() async {
2104 Source source = addSource(r''' 2101 Source source = addSource(r'''
2105 class A { 2102 class A {
2106 set f(String s) { 2103 set f(String s) {
2107 return '42'; 2104 return '42';
2108 } 2105 }
2109 } 2106 }
2110 set g(int x) => 42; 2107 set g(int x) => 42;
2111 '''); 2108 ''');
2112 await assertErrors(source, [ 2109 await computeAnalysisResult(source);
2110 assertErrors(source, [
2113 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, 2111 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,
2114 ]); 2112 ]);
2115 verify([source]); 2113 verify([source]);
2116 } 2114 }
2117 2115
2118 test_setterWithNoVoidType_returningVoid() async { 2116 test_setterWithNoVoidType_returningVoid() async {
2119 Source source = addSource(r''' 2117 Source source = addSource(r'''
2120 void returnsVoid() {} 2118 void returnsVoid() {}
2121 class A { 2119 class A {
2122 set f(String s) => returnsVoid(); 2120 set f(String s) => returnsVoid();
2123 } 2121 }
2124 set g(int x) => returnsVoid(); 2122 set g(int x) => returnsVoid();
2125 '''); 2123 ''');
2126 await assertNoErrors(source); 2124 await computeAnalysisResult(source);
2125 assertNoErrors(source);
2127 verify([source]); 2126 verify([source]);
2128 } 2127 }
2129 2128
2130 test_setterWithOtherTypeIsError() async { 2129 test_setterWithOtherTypeIsError() async {
2131 Source source = addSource(r''' 2130 Source source = addSource(r'''
2132 class A { 2131 class A {
2133 String set f(String s) => null; 2132 String set f(String s) => null;
2134 } 2133 }
2135 Object set g(x) => null; 2134 Object set g(x) => null;
2136 '''); 2135 ''');
2137 await assertErrors(source, [ 2136 await computeAnalysisResult(source);
2137 assertErrors(source, [
2138 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, 2138 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER,
2139 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER 2139 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER
2140 ]); 2140 ]);
2141 verify([source]); 2141 verify([source]);
2142 } 2142 }
2143 2143
2144 test_ternaryOperator_null_left() async { 2144 test_ternaryOperator_null_left() async {
2145 String code = r''' 2145 String code = r'''
2146 main() { 2146 main() {
2147 var foo = (true) ? null : 3; 2147 var foo = (true) ? null : 3;
2148 } 2148 }
2149 '''; 2149 ''';
2150 await resolveTestUnit(code); 2150 await resolveTestUnit(code);
2151 expectInitializerType('foo', 'int', isNull); 2151 expectInitializerType('foo', 'int', isNull);
2152 } 2152 }
2153 2153
2154 test_ternaryOperator_null_right() async { 2154 test_ternaryOperator_null_right() async {
2155 String code = r''' 2155 String code = r'''
2156 main() { 2156 main() {
2157 var foo = (true) ? 3 : null; 2157 var foo = (true) ? 3 : null;
2158 } 2158 }
2159 '''; 2159 ''';
2160 await resolveTestUnit(code); 2160 await resolveTestUnit(code);
2161 expectInitializerType('foo', 'int', isNull); 2161 expectInitializerType('foo', 'int', isNull);
2162 } 2162 }
2163
2164 Future<Null> _objectMethodOnFunctions_helper2(String code) async {
2165 await resolveTestUnit(code);
2166 expectIdentifierType('t0', "String");
2167 expectIdentifierType('t1', "() → String");
2168 expectIdentifierType('t2', "int");
2169 expectIdentifierType('t3', "String");
2170 expectIdentifierType('t4', "() → String");
2171 expectIdentifierType('t5', "int");
2172 }
2163 } 2173 }
2164 2174
2165 @reflectiveTest 2175 @reflectiveTest
2166 class StrongModeTypePropagationTest extends ResolverTestCase { 2176 class StrongModeTypePropagationTest extends ResolverTestCase {
2167 @override 2177 @override
2168 void setUp() { 2178 void setUp() {
2169 super.setUp(); 2179 super.setUp();
2170 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 2180 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
2171 options.strongMode = true; 2181 options.strongMode = true;
2172 resetWithOptions(options); 2182 resetWithOptions(options);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2402 main() { 2412 main() {
2403 var v = x; 2413 var v = x;
2404 v; // marker 2414 v; // marker
2405 } 2415 }
2406 int x = 3; 2416 int x = 3;
2407 '''; 2417 ''';
2408 await assertPropagatedAssignedType(code, typeProvider.intType, null); 2418 await assertPropagatedAssignedType(code, typeProvider.intType, null);
2409 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); 2419 await assertTypeOfMarkedExpression(code, typeProvider.intType, null);
2410 } 2420 }
2411 } 2421 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/static_warning_code_test.dart ('k') | pkg/analyzer/test/src/dart/constant/evaluation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698