diff --git a/packages/flutter/test/foundation/_compute_caller_unsound_null_safety.dart b/packages/flutter/test/foundation/_compute_caller_unsound_null_safety.dart index 98209d0916..19c0dfb02f 100644 --- a/packages/flutter/test/foundation/_compute_caller_unsound_null_safety.dart +++ b/packages/flutter/test/foundation/_compute_caller_unsound_null_safety.dart @@ -2,19 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 // Running in unsound null-safety mode is intended to test for potential miscasts // or invalid assertions. import 'package:flutter/src/foundation/_isolates_io.dart'; import 'package:flutter/src/foundation/isolates.dart' as isolates; - -int returnInt(int arg) { +int? returnInt(int? arg) { return arg; } -Future returnIntAsync(int arg) { +Future returnIntAsync(int? arg) { return Future.value(arg); } diff --git a/packages/flutter/test/foundation/_compute_caller_unsound_null_safety_error.dart b/packages/flutter/test/foundation/_compute_caller_unsound_null_safety_error.dart index 8ceaddbc97..d8fba6b2d8 100644 --- a/packages/flutter/test/foundation/_compute_caller_unsound_null_safety_error.dart +++ b/packages/flutter/test/foundation/_compute_caller_unsound_null_safety_error.dart @@ -2,21 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 // Running in unsound null-safety mode is intended to test for potential miscasts // or invalid assertions. import 'package:flutter/src/foundation/_isolates_io.dart'; -int throwNull(int arg) { - throw null; +int throwNull(dynamic arg) { + throw arg as Object; } void main() async { try { await compute(throwNull, null); } catch (e) { - if (e is! NullThrownError) { + if (e is! TypeError && e is! NullThrownError) { throw Exception('compute returned bad result'); } } diff --git a/packages/flutter/test/foundation/isolates_test.dart b/packages/flutter/test/foundation/isolates_test.dart index a5adc60022..101c0dbd22 100644 --- a/packages/flutter/test/foundation/isolates_test.dart +++ b/packages/flutter/test/foundation/isolates_test.dart @@ -80,19 +80,25 @@ Future test5CallCompute(int value) { return compute(test5, value); } -Future expectFileSuccessfullyCompletes(String filename) async { +Future expectFileSuccessfullyCompletes(String filename, + [bool unsound = false]) async { // Run a Dart script that calls compute(). // The Dart process will terminate only if the script exits cleanly with // all isolate ports closed. const FileSystem fs = LocalFileSystem(); const Platform platform = LocalPlatform(); final String flutterRoot = platform.environment['FLUTTER_ROOT']!; - final String dartPath = fs.path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dart'); + final String dartPath = + fs.path.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', 'dart'); final String packageRoot = fs.path.dirname(fs.path.fromUri(platform.script)); - final String scriptPath = fs.path.join(packageRoot, 'test', 'foundation', filename); + final String scriptPath = + fs.path.join(packageRoot, 'test', 'foundation', filename); + final String nullSafetyArg = + unsound ? '--no-sound-null-safety' : '--sound-null-safety'; // Enable asserts to also catch potentially invalid assertions. - final ProcessResult result = await Process.run(dartPath, ['run', '--enable-asserts', scriptPath]); + final ProcessResult result = await Process.run( + dartPath, [nullSafetyArg, 'run', '--enable-asserts', scriptPath]); expect(result.exitCode, 0); } @@ -194,7 +200,8 @@ void main() { expect(await computeInstanceMethod(10), 100); expect(computeInvalidInstanceMethod(10), throwsArgumentError); - expect(await compute(testDebugName, null, debugLabel: 'debug_name'), 'debug_name'); + expect(await compute(testDebugName, null, debugLabel: 'debug_name'), + 'debug_name'); expect(await compute(testReturnNull, null), null); }, skip: kIsWeb); // [intended] isn't supported on the web. @@ -203,22 +210,26 @@ void main() { await expectFileSuccessfullyCompletes('_compute_caller.dart'); }); test('with invalid message', () async { - await expectFileSuccessfullyCompletes('_compute_caller_invalid_message.dart'); + await expectFileSuccessfullyCompletes( + '_compute_caller_invalid_message.dart'); }); test('with valid error', () async { await expectFileSuccessfullyCompletes('_compute_caller.dart'); }); test('with invalid error', () async { - await expectFileSuccessfullyCompletes('_compute_caller_invalid_message.dart'); + await expectFileSuccessfullyCompletes( + '_compute_caller_invalid_message.dart'); }); }, skip: kIsWeb); // [intended] isn't supported on the web. group('compute() works with unsound null safety caller', () { test('returning', () async { - await expectFileSuccessfullyCompletes('_compute_caller_unsound_null_safety.dart'); + await expectFileSuccessfullyCompletes( + '_compute_caller_unsound_null_safety.dart', true); }); test('erroring', () async { - await expectFileSuccessfullyCompletes('_compute_caller_unsound_null_safety_error.dart'); + await expectFileSuccessfullyCompletes( + '_compute_caller_unsound_null_safety_error.dart', true); }); }, skip: kIsWeb); // [intended] isn't supported on the web. }