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

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

Issue 1897293003: Required params message fix. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 1598
1599 class C { 1599 class C {
1600 C({@Required('must specify an `a`') int a}) {} 1600 C({@Required('must specify an `a`') int a}) {}
1601 } 1601 }
1602 1602
1603 main() { 1603 main() {
1604 new C(); 1604 new C();
1605 } 1605 }
1606 '''); 1606 ''');
1607 computeLibrarySourceErrors(source); 1607 computeLibrarySourceErrors(source);
1608 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 1608 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
Brian Wilkerson 2016/04/19 18:01:16 It would be good to have at least one test of the
pquitslund 2016/04/19 18:20:23 Yep! There are a few actually below...
1609 verify([source]); 1609 verify([source]);
1610 } 1610 }
1611 1611
1612 void test_required_constructor_param_no_reason() { 1612 void test_required_constructor_param_no_reason() {
pquitslund 2016/04/19 18:20:23 Here.
1613 Source source = addSource(r''' 1613 Source source = addSource(r'''
1614 import 'package:meta/meta.dart'; 1614 import 'package:meta/meta.dart';
1615 1615
1616 class C { 1616 class C {
1617 C({@required int a}) {} 1617 C({@required int a}) {}
1618 } 1618 }
1619 1619
1620 main() { 1620 main() {
1621 new C(); 1621 new C();
1622 } 1622 }
1623 '''); 1623 ''');
1624 computeLibrarySourceErrors(source); 1624 computeLibrarySourceErrors(source);
1625 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 1625 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]);
1626 verify([source]); 1626 verify([source]);
1627 } 1627 }
1628 1628
1629 void test_required_constructor_param_null_reason() { 1629 void test_required_constructor_param_null_reason() {
pquitslund 2016/04/19 18:20:23 And here...
1630 Source source = addSource(r''' 1630 Source source = addSource(r'''
1631 import 'package:meta/meta.dart'; 1631 import 'package:meta/meta.dart';
1632 1632
1633 class C { 1633 class C {
1634 C({@Required(null) int a}) {} 1634 C({@Required(null) int a}) {}
1635 } 1635 }
1636 1636
1637 main() { 1637 main() {
1638 new C(); 1638 new C();
1639 } 1639 }
(...skipping 24 matching lines...) Expand all
1664 Source source = addSource(r''' 1664 Source source = addSource(r'''
1665 import 'package:meta/meta.dart'; 1665 import 'package:meta/meta.dart';
1666 1666
1667 void f({@Required('must specify an `a`') int a}) {} 1667 void f({@Required('must specify an `a`') int a}) {}
1668 1668
1669 main() { 1669 main() {
1670 f(); 1670 f();
1671 } 1671 }
1672 '''); 1672 ''');
1673 computeLibrarySourceErrors(source); 1673 computeLibrarySourceErrors(source);
1674 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 1674 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
1675 verify([source]); 1675 verify([source]);
1676 } 1676 }
1677 1677
1678 void test_required_method_param() { 1678 void test_required_method_param() {
1679 Source source = addSource(r''' 1679 Source source = addSource(r'''
1680 import 'package:meta/meta.dart'; 1680 import 'package:meta/meta.dart';
1681 class A { 1681 class A {
1682 void m({@Required('must specify an `a`') int a}) {} 1682 void m({@Required('must specify an `a`') int a}) {}
1683 } 1683 }
1684 f() { 1684 f() {
1685 new A().m(); 1685 new A().m();
1686 } 1686 }
1687 '''); 1687 ''');
1688 computeLibrarySourceErrors(source); 1688 computeLibrarySourceErrors(source);
1689 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM]); 1689 assertErrors(source, [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS]);
1690 verify([source]); 1690 verify([source]);
1691 } 1691 }
1692 1692
1693 void test_typeCheck_type_is_Null() { 1693 void test_typeCheck_type_is_Null() {
1694 Source source = addSource(r''' 1694 Source source = addSource(r'''
1695 m(i) { 1695 m(i) {
1696 bool b = i is Null; 1696 bool b = i is Null;
1697 }'''); 1697 }''');
1698 computeLibrarySourceErrors(source); 1698 computeLibrarySourceErrors(source);
1699 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); 1699 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]);
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 assertNoErrors(source2); 2902 assertNoErrors(source2);
2903 verify([source, source2]); 2903 verify([source, source2]);
2904 } 2904 }
2905 2905
2906 void test_unusedShownName() { 2906 void test_unusedShownName() {
2907 Source source = addSource(r''' 2907 Source source = addSource(r'''
2908 library L; 2908 library L;
2909 import 'lib1.dart' show A, B; 2909 import 'lib1.dart' show A, B;
2910 A a;'''); 2910 A a;''');
2911 Source source2 = addNamedSource( 2911 Source source2 = addNamedSource(
2912 "/lib1.dart", r''' 2912 "/lib1.dart",
2913 r'''
2913 library lib1; 2914 library lib1;
2914 class A {} 2915 class A {}
2915 class B {}'''); 2916 class B {}''');
2916 computeLibrarySourceErrors(source); 2917 computeLibrarySourceErrors(source);
2917 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 2918 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
2918 assertNoErrors(source2); 2919 assertNoErrors(source2);
2919 verify([source, source2]); 2920 verify([source, source2]);
2920 } 2921 }
2921 2922
2922 void test_unusedShownName_topLevelVariable() { 2923 void test_unusedShownName_topLevelVariable() {
(...skipping 17 matching lines...) Expand all
2940 assertNoErrors(source2); 2941 assertNoErrors(source2);
2941 verify([source, source2]); 2942 verify([source, source2]);
2942 } 2943 }
2943 2944
2944 void test_unusedShownName_as() { 2945 void test_unusedShownName_as() {
2945 Source source = addSource(r''' 2946 Source source = addSource(r'''
2946 library L; 2947 library L;
2947 import 'lib1.dart' as p show A, B; 2948 import 'lib1.dart' as p show A, B;
2948 p.A a;'''); 2949 p.A a;''');
2949 Source source2 = addNamedSource( 2950 Source source2 = addNamedSource(
2950 "/lib1.dart", r''' 2951 "/lib1.dart",
2952 r'''
2951 library lib1; 2953 library lib1;
2952 class A {} 2954 class A {}
2953 class B {}'''); 2955 class B {}''');
2954 computeLibrarySourceErrors(source); 2956 computeLibrarySourceErrors(source);
2955 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]); 2957 assertErrors(source, [HintCode.UNUSED_SHOWN_NAME]);
2956 assertNoErrors(source2); 2958 assertNoErrors(source2);
2957 verify([source, source2]); 2959 verify([source, source2]);
2958 } 2960 }
2959 2961
2960 void test_unusedShownName_duplicates() { 2962 void test_unusedShownName_duplicates() {
2961 Source source = addSource(r''' 2963 Source source = addSource(r'''
2962 library L; 2964 library L;
2963 import 'lib1.dart' show A, B; 2965 import 'lib1.dart' show A, B;
2964 import 'lib1.dart' show C, D; 2966 import 'lib1.dart' show C, D;
2965 A a; 2967 A a;
2966 C c;'''); 2968 C c;''');
2967 Source source2 = addNamedSource( 2969 Source source2 = addNamedSource(
2968 "/lib1.dart", r''' 2970 "/lib1.dart",
2971 r'''
2969 library lib1; 2972 library lib1;
2970 class A {} 2973 class A {}
2971 class B {} 2974 class B {}
2972 class C {} 2975 class C {}
2973 class D {}'''); 2976 class D {}''');
2974 computeLibrarySourceErrors(source); 2977 computeLibrarySourceErrors(source);
2975 assertErrors(source, [ 2978 assertErrors(
2976 HintCode.UNUSED_SHOWN_NAME, 2979 source, [HintCode.UNUSED_SHOWN_NAME, HintCode.UNUSED_SHOWN_NAME]);
2977 HintCode.UNUSED_SHOWN_NAME]);
2978 assertNoErrors(source2); 2980 assertNoErrors(source2);
2979 verify([source, source2]); 2981 verify([source, source2]);
2980 } 2982 }
2981 2983
2982 void test_unusedLocalVariable_inCatch_exception() { 2984 void test_unusedLocalVariable_inCatch_exception() {
2983 enableUnusedLocalVariable = true; 2985 enableUnusedLocalVariable = true;
2984 Source source = addSource(r''' 2986 Source source = addSource(r'''
2985 main() { 2987 main() {
2986 try { 2988 try {
2987 } on String catch (exception) { 2989 } on String catch (exception) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3240 n() { 3242 n() {
3241 var a = m(), b = m(); 3243 var a = m(), b = m();
3242 } 3244 }
3243 }'''); 3245 }''');
3244 computeLibrarySourceErrors(source); 3246 computeLibrarySourceErrors(source);
3245 assertErrors( 3247 assertErrors(
3246 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 3248 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
3247 verify([source]); 3249 verify([source]);
3248 } 3250 }
3249 } 3251 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698