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.
This commit is contained in:
parent
f2ec1c459f
commit
ea4e11dd9b
@ -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<int> returnIntAsync(int arg) {
|
||||
Future<int?> returnIntAsync(int? arg) {
|
||||
return Future<int>.value(arg);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -80,19 +80,25 @@ Future<int> test5CallCompute(int value) {
|
||||
return compute(test5, value);
|
||||
}
|
||||
|
||||
Future<void> expectFileSuccessfullyCompletes(String filename) async {
|
||||
Future<void> 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, <String>['run', '--enable-asserts', scriptPath]);
|
||||
final ProcessResult result = await Process.run(
|
||||
dartPath, <String>[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.
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user