Skip to content

Commit 82bcd13

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Change PubPackageResolutionTest to use null safety.
Some tests had some issues migrating to null safety that I could not immediately hash out, or may warrant some more discussion. So I've added WithoutNullSafetyMixin, and we can incrementally migrate these after this CL. Many tests have little no-op tweaks to make them null safe, like initializing variables, adding late, making nullable. Nest steps: 1. Remove `WithNullSafetyMixin` applications. 2. Remove `WithoutNullSafetyMixin` in every position with a TODO for #44666. 3. For every file with pair(s) of test classes (one pre-null safety, and one null safety), move around test cases so that they generally run with null safety, unless they are testing things very specific to before and after null safety. Bug: #44666 Change-Id: I0512dedcda42e864fd580af4842702095937bdb6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183140 Commit-Queue: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 08f90ca commit 82bcd13

File tree

170 files changed

+819
-571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+819
-571
lines changed

pkg/analyzer/test/generated/error_suppression_test.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const y = x; //CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
8383
await assertNoErrorsInCode('''
8484
//ignore_for_file: unused_element , unnecessary_cast
8585
int x = (0 as int); //UNNECESSARY_CAST
86-
String _foo; //UNUSED_ELEMENT
86+
String _foo = ''; //UNUSED_ELEMENT
8787
''');
8888
}
8989

@@ -98,7 +98,7 @@ int x = (0 as int); // ignore: unnecessary_cast
9898
//UNNECESSARY_CAST
9999
int x = (0 as int);
100100
// ignore: unused_element
101-
String _foo; //UNUSED_ELEMENT
101+
String _foo = ''; //UNUSED_ELEMENT
102102
''', [
103103
error(HintCode.UNNECESSARY_CAST, 28, 8),
104104
]);
@@ -108,7 +108,7 @@ String _foo; //UNUSED_ELEMENT
108108
await assertErrorsInCode('''
109109
//UNNECESSARY_CAST
110110
int x = (0 as int);
111-
String _foo; // ignore: $ignoredCode
111+
String _foo = ''; // ignore: $ignoredCode
112112
''', [
113113
error(HintCode.UNNECESSARY_CAST, 28, 8),
114114
]);
@@ -119,7 +119,7 @@ String _foo; // ignore: $ignoredCode
119119
await assertNoErrorsInCode('''
120120
import 'package:meta/meta.dart';
121121
122-
int f({@Required('x') int a}) => 0;
122+
int f({@Required('x') int? a}) => 0;
123123
124124
// ignore: missing_required_param_with_details
125125
int x = f();
@@ -169,7 +169,7 @@ String y = 3; //INVALID_ASSIGNMENT
169169
await assertErrorsInCode('''
170170
int x = (0 as int); //This is the first comment...
171171
// ignore: $ignoredCode
172-
String _foo; //UNUSED_ELEMENT
172+
String _foo = ''; //UNUSED_ELEMENT
173173
''', [
174174
error(HintCode.UNNECESSARY_CAST, 9, 8),
175175
]);
@@ -178,7 +178,7 @@ String _foo; //UNUSED_ELEMENT
178178
test_multiple_ignore_for_files() async {
179179
await assertNoErrorsInCode('''
180180
int x = (0 as int); //UNNECESSARY_CAST
181-
String _foo; //UNUSED_ELEMENT
181+
String _foo = ''; //UNUSED_ELEMENT
182182
// ignore_for_file: unnecessary_cast,$ignoredCode
183183
''');
184184
}

pkg/analyzer/test/generated/invalid_code_test.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ main() {
1919
/// errors generated, but we want to make sure that there is at least one,
2020
/// and analysis finishes without exceptions.
2121
@reflectiveTest
22-
class InvalidCodeTest extends PubPackageResolutionTest {
22+
class InvalidCodeTest extends PubPackageResolutionTest
23+
with WithoutNullSafetyMixin {
24+
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
25+
// test cases.
2326
test_const_AwaitExpression() async {
2427
await _assertCanBeAnalyzed(r'''
2528
const a = await b();

pkg/analyzer/test/generated/non_error_resolver_test.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import '../src/dart/resolution/context_collection_resolution.dart';
1313

1414
main() {
1515
defineReflectiveSuite(() {
16-
defineReflectiveTests(NonErrorResolverTest);
1716
defineReflectiveTests(NonConstantValueInInitializer);
17+
defineReflectiveTests(NonErrorResolverTest);
1818
});
1919
}
2020

@@ -53,7 +53,10 @@ void main() {
5353
}
5454

5555
@reflectiveTest
56-
class NonErrorResolverTest extends PubPackageResolutionTest {
56+
class NonErrorResolverTest extends PubPackageResolutionTest
57+
with WithoutNullSafetyMixin {
58+
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
59+
// test cases.
5760
test_ambiguousExport() async {
5861
newFile("$testPackageLibPath/lib1.dart", content: r'''
5962
library lib1;

pkg/analyzer/test/generated/resolver_test.dart

+8-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ class StaticTypeVerifier extends GeneralizingAstVisitor<void> {
277277
/// The class `StrictModeTest` contains tests to ensure that the correct errors
278278
/// and warnings are reported when the analysis engine is run in strict mode.
279279
@reflectiveTest
280-
class StrictModeTest extends PubPackageResolutionTest {
280+
class StrictModeTest extends PubPackageResolutionTest
281+
with WithoutNullSafetyMixin {
282+
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
283+
// test cases.
281284
test_assert_is() async {
282285
await assertErrorsInCode(r'''
283286
int f(num n) {
@@ -417,7 +420,10 @@ int f() {
417420
}
418421

419422
@reflectiveTest
420-
class TypePropagationTest extends PubPackageResolutionTest {
423+
class TypePropagationTest extends PubPackageResolutionTest
424+
with WithoutNullSafetyMixin {
425+
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
426+
// test cases.
421427
test_assignment_null() async {
422428
String code = r'''
423429
main() {

pkg/analyzer/test/generated/resolver_test_case.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ class ResolutionVerifier extends RecursiveAstVisitor<void> {
285285
}
286286

287287
/// Shared infrastructure for [StaticTypeAnalyzer2Test].
288-
class StaticTypeAnalyzer2TestShared extends PubPackageResolutionTest {
288+
class StaticTypeAnalyzer2TestShared extends PubPackageResolutionTest
289+
with WithoutNullSafetyMixin {
290+
// TODO(https://github.com/dart-lang/sdk/issues/44666): Use null safety in
291+
// test cases.
292+
289293
/// Looks up the identifier with [name] and validates that its type type
290294
/// stringifies to [type] and that its generics match the given stringified
291295
/// output.

pkg/analyzer/test/generated/simple_resolver_test.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ f() {
530530
await assertNoErrorsInCode(r'''
531531
typedef bool P(e);
532532
class A {
533-
P p;
533+
late P p;
534534
m(e) {
535535
if (p(e)) {}
536536
}
@@ -604,7 +604,7 @@ import 'lib2.dart';
604604
main() {
605605
foo = 0;
606606
}
607-
A a;''');
607+
A a = A();''');
608608
verifyTestResolved();
609609
}
610610

@@ -693,11 +693,11 @@ main() {
693693
test_indexExpression_typeParameters() async {
694694
await assertNoErrorsInCode(r'''
695695
f() {
696-
List<int> a;
696+
List<int> a = [];
697697
a[0];
698-
List<List<int>> b;
698+
List<List<int>> b = [];
699699
b[0][0];
700-
List<List<List<int>>> c;
700+
List<List<List<int>>> c = [];
701701
c[0][0][0];
702702
}''');
703703
verifyTestResolved();
@@ -706,10 +706,10 @@ f() {
706706
test_indexExpression_typeParameters_invalidAssignmentWarning() async {
707707
await assertErrorsInCode(r'''
708708
f() {
709-
List<List<int>> b;
709+
List<List<int>> b = [];
710710
b[0][0] = 'hi';
711711
}''', [
712-
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 39, 4),
712+
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 44, 4),
713713
]);
714714
verifyTestResolved();
715715
}
@@ -854,7 +854,7 @@ const A = null;
854854
await assertNoErrorsInCode(r'''
855855
const A = null;
856856
class C {
857-
@A int f;
857+
@A int f = 1;
858858
}''');
859859
verifyTestResolved();
860860

@@ -1077,7 +1077,7 @@ class A {
10771077
test_methodCascades_withSetter() async {
10781078
await assertNoErrorsInCode(r'''
10791079
class A {
1080-
String name;
1080+
String name = '';
10811081
void m1() {}
10821082
void m2() {}
10831083
void m() {

0 commit comments

Comments
 (0)