Skip to content

Commit ea4e11d

Browse files
authored
Fix test in preparation of the Dart VM dropping support for language versions < 2.12.0 (#115176)
* Fix test in preparation of the Dart VM switching to being null safe by default. * Fix analyze error. * Format. * Remove print. * Fix analyzer lint. * Fix warnings.
1 parent f2ec1c4 commit ea4e11d

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

packages/flutter/test/foundation/_compute_caller_unsound_null_safety.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart=2.9
65
// Running in unsound null-safety mode is intended to test for potential miscasts
76
// or invalid assertions.
87

98
import 'package:flutter/src/foundation/_isolates_io.dart';
109
import 'package:flutter/src/foundation/isolates.dart' as isolates;
1110

12-
13-
int returnInt(int arg) {
11+
int? returnInt(int? arg) {
1412
return arg;
1513
}
1614

17-
Future<int> returnIntAsync(int arg) {
15+
Future<int?> returnIntAsync(int? arg) {
1816
return Future<int>.value(arg);
1917
}
2018

packages/flutter/test/foundation/_compute_caller_unsound_null_safety_error.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart=2.9
65
// Running in unsound null-safety mode is intended to test for potential miscasts
76
// or invalid assertions.
87

98
import 'package:flutter/src/foundation/_isolates_io.dart';
109

11-
int throwNull(int arg) {
12-
throw null;
10+
int throwNull(dynamic arg) {
11+
throw arg as Object;
1312
}
1413

1514
void main() async {
1615
try {
1716
await compute(throwNull, null);
1817
} catch (e) {
19-
if (e is! NullThrownError) {
18+
if (e is! TypeError && e is! NullThrownError) {
2019
throw Exception('compute returned bad result');
2120
}
2221
}

packages/flutter/test/foundation/isolates_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,25 @@ Future<int> test5CallCompute(int value) {
8080
return compute(test5, value);
8181
}
8282

83-
Future<void> expectFileSuccessfullyCompletes(String filename) async {
83+
Future<void> expectFileSuccessfullyCompletes(String filename,
84+
[bool unsound = false]) async {
8485
// Run a Dart script that calls compute().
8586
// The Dart process will terminate only if the script exits cleanly with
8687
// all isolate ports closed.
8788
const FileSystem fs = LocalFileSystem();
8889
const Platform platform = LocalPlatform();
8990
final String flutterRoot = platform.environment['FLUTTER_ROOT']!;
90-
final String dartPath = fs.path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dart');
91+
final String dartPath =
92+
fs.path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dart');
9193
final String packageRoot = fs.path.dirname(fs.path.fromUri(platform.script));
92-
final String scriptPath = fs.path.join(packageRoot, 'test', 'foundation', filename);
94+
final String scriptPath =
95+
fs.path.join(packageRoot, 'test', 'foundation', filename);
96+
final String nullSafetyArg =
97+
unsound ? '--no-sound-null-safety' : '--sound-null-safety';
9398

9499
// Enable asserts to also catch potentially invalid assertions.
95-
final ProcessResult result = await Process.run(dartPath, <String>['run', '--enable-asserts', scriptPath]);
100+
final ProcessResult result = await Process.run(
101+
dartPath, <String>[nullSafetyArg, 'run', '--enable-asserts', scriptPath]);
96102
expect(result.exitCode, 0);
97103
}
98104

@@ -194,7 +200,8 @@ void main() {
194200
expect(await computeInstanceMethod(10), 100);
195201
expect(computeInvalidInstanceMethod(10), throwsArgumentError);
196202

197-
expect(await compute(testDebugName, null, debugLabel: 'debug_name'), 'debug_name');
203+
expect(await compute(testDebugName, null, debugLabel: 'debug_name'),
204+
'debug_name');
198205
expect(await compute(testReturnNull, null), null);
199206
}, skip: kIsWeb); // [intended] isn't supported on the web.
200207

@@ -203,22 +210,26 @@ void main() {
203210
await expectFileSuccessfullyCompletes('_compute_caller.dart');
204211
});
205212
test('with invalid message', () async {
206-
await expectFileSuccessfullyCompletes('_compute_caller_invalid_message.dart');
213+
await expectFileSuccessfullyCompletes(
214+
'_compute_caller_invalid_message.dart');
207215
});
208216
test('with valid error', () async {
209217
await expectFileSuccessfullyCompletes('_compute_caller.dart');
210218
});
211219
test('with invalid error', () async {
212-
await expectFileSuccessfullyCompletes('_compute_caller_invalid_message.dart');
220+
await expectFileSuccessfullyCompletes(
221+
'_compute_caller_invalid_message.dart');
213222
});
214223
}, skip: kIsWeb); // [intended] isn't supported on the web.
215224

216225
group('compute() works with unsound null safety caller', () {
217226
test('returning', () async {
218-
await expectFileSuccessfullyCompletes('_compute_caller_unsound_null_safety.dart');
227+
await expectFileSuccessfullyCompletes(
228+
'_compute_caller_unsound_null_safety.dart', true);
219229
});
220230
test('erroring', () async {
221-
await expectFileSuccessfullyCompletes('_compute_caller_unsound_null_safety_error.dart');
231+
await expectFileSuccessfullyCompletes(
232+
'_compute_caller_unsound_null_safety_error.dart', true);
222233
});
223234
}, skip: kIsWeb); // [intended] isn't supported on the web.
224235
}

0 commit comments

Comments
 (0)