Skip to content

Fix test in preparation of the Dart VM dropping support for language versions < 2.12.0 #115176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
29 changes: 20 additions & 9 deletions packages/flutter/test/foundation/isolates_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.

Expand All @@ -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.
}