Skip to content

Commit

Permalink
Cleanup dart analyze diagnostics in ignored directories. (flutter#54262)
Browse files Browse the repository at this point in the history
Towards flutter/flutter#152636.

I also deleted some code that was TODO'd 10 years ago.
  • Loading branch information
matanlurey authored Jul 31, 2024
1 parent ed95b49 commit e7bbdcf
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 224 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
deprecated_member_use: ignore
deprecated_member_use_from_same_package: ignore
exclude: # DIFFERENT FROM FLUTTER/FLUTTER
- examples
# Fixture depends on dart:ui and raises false positives.
- flutter_frontend_server/test/fixtures/lib/main.dart
- prebuilts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:isolate';
import 'dart:ui';
import 'dart:io' show Platform;

@pragma('vm:external-name', 'PassMessage')
external void passMessage(String message);
Expand All @@ -14,18 +13,15 @@ bool didCallRegistrantBeforeEntrypoint = false;
// Test the Dart plugin registrant.
@pragma('vm:entry-point')
class _PluginRegistrant {

@pragma('vm:entry-point')
static void register() {
if (didCallRegistrantBeforeEntrypoint) {
throw '_registerPlugins is being called twice';
throw StateError('_registerPlugins is being called twice');
}
didCallRegistrantBeforeEntrypoint = true;
}

}


@pragma('vm:entry-point')
void mainForPluginRegistrantTest() {
if (didCallRegistrantBeforeEntrypoint) {
Expand All @@ -42,22 +38,29 @@ void dartPluginRegistrantIsolate(SendPort sendPort) {
sendPort.send(didCallRegistrantBeforeEntrypoint);
}

void registerBackgroundIsolate(List args) {
SendPort sendPort = args[0] as SendPort;
RootIsolateToken token = args[1] as RootIsolateToken;
void registerBackgroundIsolate(List<Object?> args) {
final sendPort = args[0]! as SendPort;
final token = args[1]! as RootIsolateToken;
PlatformDispatcher.instance.registerBackgroundIsolate(token);
sendPort.send(didCallRegistrantBeforeEntrypoint);
}

@pragma('vm:entry-point')
void callDartPluginRegistrantFromBackgroundIsolate() async {
ReceivePort receivePort = ReceivePort();
Isolate isolate = await Isolate.spawn(dartPluginRegistrantIsolate, receivePort.sendPort);
bool didCallEntrypoint = await receivePort.first;
Future<void> callDartPluginRegistrantFromBackgroundIsolate() async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(
dartPluginRegistrantIsolate,
receivePort.sendPort,
);
final didCallEntrypoint = await receivePort.first as bool;
if (didCallEntrypoint) {
passMessage('_PluginRegistrant.register() was called on background isolate');
passMessage(
'_PluginRegistrant.register() was called on background isolate',
);
} else {
passMessage('_PluginRegistrant.register() was not called on background isolate');
passMessage(
'_PluginRegistrant.register() was not called on background isolate',
);
}
isolate.kill();
}
Expand All @@ -67,27 +70,41 @@ void noDartPluginRegistrantIsolate(SendPort sendPort) {
}

@pragma('vm:entry-point')
void dontCallDartPluginRegistrantFromBackgroundIsolate() async {
ReceivePort receivePort = ReceivePort();
Isolate isolate = await Isolate.spawn(noDartPluginRegistrantIsolate, receivePort.sendPort);
bool didCallEntrypoint = await receivePort.first;
Future<void> dontCallDartPluginRegistrantFromBackgroundIsolate() async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(
noDartPluginRegistrantIsolate,
receivePort.sendPort,
);
final didCallEntrypoint = await receivePort.first as bool;
if (didCallEntrypoint) {
passMessage('_PluginRegistrant.register() was called on background isolate');
passMessage(
'_PluginRegistrant.register() was called on background isolate',
);
} else {
passMessage('_PluginRegistrant.register() was not called on background isolate');
passMessage(
'_PluginRegistrant.register() was not called on background isolate',
);
}
isolate.kill();
}

@pragma('vm:entry-point')
void registerBackgroundIsolateCallsDartPluginRegistrant() async {
ReceivePort receivePort = ReceivePort();
Isolate isolate = await Isolate.spawn(registerBackgroundIsolate, [receivePort.sendPort, RootIsolateToken.instance]);
bool didCallEntrypoint = await receivePort.first;
Future<void> registerBackgroundIsolateCallsDartPluginRegistrant() async {
final receivePort = ReceivePort();
final isolate = await Isolate.spawn(registerBackgroundIsolate, [
receivePort.sendPort,
RootIsolateToken.instance,
]);
final didCallEntrypoint = await receivePort.first as bool;
if (didCallEntrypoint) {
passMessage('_PluginRegistrant.register() was called on background isolate');
passMessage(
'_PluginRegistrant.register() was called on background isolate',
);
} else {
passMessage('_PluginRegistrant.register() was not called on background isolate');
passMessage(
'_PluginRegistrant.register() was not called on background isolate',
);
}
isolate.kill();
}
108 changes: 54 additions & 54 deletions runtime/fixtures/runtime_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: avoid_print

import 'dart:async';
import 'dart:isolate';
import 'dart:ui';

import 'split_lib_test.dart' deferred as splitlib;

Expand All @@ -17,91 +18,92 @@ void sayHi() {

@pragma('vm:entry-point')
void throwExceptionNow() {
throw 'Hello';
throw AssertionError('Hello');
}

@pragma('vm:entry-point')
void canRegisterNativeCallback() async {
Future<void> canRegisterNativeCallback() async {
print('In function canRegisterNativeCallback');
notifyNative();
print('Called native method from canRegisterNativeCallback');
}

Future<void>? splitLoadFuture = null;
Future<void>? splitLoadFuture;

@pragma('vm:entry-point')
void canCallDeferredLibrary() {
print('In function canCallDeferredLibrary');
splitLoadFuture = splitlib.loadLibrary()
.then((_) {
print('Deferred load complete');
notifySuccess(splitlib.splitAdd(10, 23) == 33);
})
.catchError((_) {
print('Deferred load error');
notifySuccess(false);
});
splitLoadFuture = splitlib.loadLibrary().then((_) {
print('Deferred load complete');
notifySuccess(splitlib.splitAdd(10, 23) == 33);
}).catchError((_) {
print('Deferred load error');
notifySuccess(false);
});
notifyNative();
}

@pragma('vm:external-name', 'NotifyNative')
external void notifyNative();

@pragma('vm:entry-point')
void testIsolateShutdown() { }
void testIsolateShutdown() {}

@pragma('vm:external-name', 'NotifyNative')
external void notifyResult(bool success);
@pragma('vm:external-name', 'PassMessage')
external void passMessage(String message);

void secondaryIsolateMain(String message) {
print('Secondary isolate got message: ' + message);
print('Secondary isolate got message: $message');
passMessage('Hello from code is secondary isolate.');
notifyNative();
}

@pragma('vm:entry-point')
void testCanLaunchSecondaryIsolate() {
final onExit = RawReceivePort((_) { notifyNative(); });
Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.', onExit: onExit.sendPort);
final onExit = RawReceivePort((_) {
notifyNative();
});
Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.',
onExit: onExit.sendPort);
}


@pragma('vm:entry-point')
void testIsolateStartupFailure() async {
Future mainTest(dynamic _) async {
Future testSuccessfullIsolateLaunch() async {
Future<void> testIsolateStartupFailure() async {
Future<void> mainTest(void _) async {
Future<void> testSuccessfullIsolateLaunch() async {
final onMessage = ReceivePort();
final onExit = ReceivePort();

final messages = StreamIterator<dynamic>(onMessage);
final exits = StreamIterator<dynamic>(onExit);

await Isolate.spawn((SendPort port) => port.send('good'),
onMessage.sendPort, onExit: onExit.sendPort);
await Isolate.spawn(
(SendPort port) => port.send('good'), onMessage.sendPort,
onExit: onExit.sendPort);
if (!await messages.moveNext()) {
throw 'Failed to receive message';
throw AssertionError('Failed to receive message');
}
if (messages.current != 'good') {
throw 'Failed to receive correct message';
throw AssertionError('Failed to receive correct message');
}
if (!await exits.moveNext()) {
throw 'Failed to receive onExit';
throw AssertionError('Failed to receive onExit');
}
messages.cancel();
exits.cancel();
}

Future testUnsuccessfullIsolateLaunch() async {
Future<void> testUnsuccessfullIsolateLaunch() async {
IsolateSpawnException? error;
try {
await Isolate.spawn((_) {}, null);
} on IsolateSpawnException catch (e) {
error = e;
}
if (error == null) {
throw 'Expected isolate spawn to fail.';
throw AssertionError('Expected isolate spawn to fail.');
}
}

Expand All @@ -115,6 +117,7 @@ void testIsolateStartupFailure() async {
// test in an isolate.
Isolate.spawn(mainTest, null);
}

@pragma('vm:external-name', 'MakeNextIsolateSpawnFail')
external void makeNextIsolateSpawnFail();

Expand All @@ -132,54 +135,51 @@ void trampoline() {
external void notifySuccess(bool success);

@pragma('vm:entry-point')
void testCanConvertEmptyList(List<int> args){
notifySuccess(args.length == 0);
void testCanConvertEmptyList(List<int> args) {
notifySuccess(args.isEmpty);
}

@pragma('vm:entry-point')
void testCanConvertListOfStrings(List<String> args){
void testCanConvertListOfStrings(List<String> args) {
notifySuccess(args.length == 4 &&
args[0] == 'tinker' &&
args[1] == 'tailor' &&
args[2] == 'soldier' &&
args[3] == 'sailor');
args[0] == 'tinker' &&
args[1] == 'tailor' &&
args[2] == 'soldier' &&
args[3] == 'sailor');
}

@pragma('vm:entry-point')
void testCanConvertListOfDoubles(List<double> args){
void testCanConvertListOfDoubles(List<double> args) {
notifySuccess(args.length == 4 &&
args[0] == 1.0 &&
args[1] == 2.0 &&
args[2] == 3.0 &&
args[3] == 4.0);
args[0] == 1.0 &&
args[1] == 2.0 &&
args[2] == 3.0 &&
args[3] == 4.0);
}

@pragma('vm:entry-point')
void testCanConvertListOfInts(List<int> args){
void testCanConvertListOfInts(List<int> args) {
notifySuccess(args.length == 4 &&
args[0] == 1 &&
args[1] == 2 &&
args[2] == 3 &&
args[3] == 4);
args[0] == 1 &&
args[1] == 2 &&
args[2] == 3 &&
args[3] == 4);
}

bool didCallRegistrantBeforeEntrypoint = false;

// Test the Dart plugin registrant.
@pragma('vm:entry-point')
class _PluginRegistrant {

@pragma('vm:entry-point')
static void register() {
if (didCallRegistrantBeforeEntrypoint) {
throw '_registerPlugins is being called twice';
throw AssertionError('_registerPlugins is being called twice');
}
didCallRegistrantBeforeEntrypoint = true;
}

}


@pragma('vm:entry-point')
void mainForPluginRegistrantTest() {
if (didCallRegistrantBeforeEntrypoint) {
Expand All @@ -195,19 +195,19 @@ void mainForPlatformIsolates() {
}

@pragma('vm:entry-point')
void emptyMain(args) {}
void emptyMain(List<Object?> args) {}

@pragma('vm:entry-point')
Function createEntryPointForPlatIsoSendAndRecvTest() {
final port = RawReceivePort();
port.handler = (message) {
port.handler = (Object? message) {
port.close();
(message as SendPort).send('Hello from root isolate!');
(message! as SendPort).send('Hello from root isolate!');
};
final SendPort sendPort = port.sendPort;
return () {
final replyPort = RawReceivePort();
replyPort.handler = (message) {
replyPort.handler = (Object? message) {
replyPort.close();
passMessage('Platform isolate received: $message');
};
Expand All @@ -217,5 +217,5 @@ Function createEntryPointForPlatIsoSendAndRecvTest() {

@pragma('vm:entry-point')
void mainForPlatformIsolatesThrowError() {
throw 'Error from platform isolate';
throw AssertionError('Error from platform isolate');
}
Loading

0 comments on commit e7bbdcf

Please sign in to comment.