Skip to content

Commit

Permalink
[flutter_tools] migrate some integration tests to null safety (#103560)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored May 13, 2022
1 parent 42b6fba commit 9f28b83
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 175 deletions.
22 changes: 10 additions & 12 deletions packages/flutter_tools/test/integration.shard/daemon_mode_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:async';
import 'dart:convert';
import 'dart:io' hide Directory;
Expand All @@ -17,16 +15,16 @@ import 'test_driver.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
Process daemonProcess;
late Directory tempDir;
late Process daemonProcess;

setUp(() async {
tempDir = createResolvedTempDirectorySync('daemon_mode_test.');
});

tearDown(() async {
tryToDelete(tempDir);
daemonProcess?.kill();
daemonProcess.kill();
});

testWithoutContext('device.getDevices', () async {
Expand All @@ -43,26 +41,26 @@ void main() {

final StreamController<String> stdout = StreamController<String>.broadcast();
transformToLines(daemonProcess.stdout).listen((String line) => stdout.add(line));
final Stream<Map<String, dynamic>> stream = stdout
final Stream<Map<String, Object?>?> stream = stdout
.stream
.map<Map<String, dynamic>>(parseFlutterResponse)
.where((Map<String, dynamic> value) => value != null);
.map<Map<String, Object?>?>(parseFlutterResponse)
.where((Map<String, Object?>? value) => value != null);

Map<String, dynamic> response = await stream.first;
Map<String, Object?> response = (await stream.first)!;
expect(response['event'], 'daemon.connected');

// start listening for devices
daemonProcess.stdin.writeln('[${jsonEncode(<String, dynamic>{
'id': 1,
'method': 'device.enable',
})}]');
response = await stream.firstWhere((Map<String, Object> json) => json['id'] == 1);
response = (await stream.firstWhere((Map<String, Object?>? json) => json!['id'] == 1))!;
expect(response['id'], 1);
expect(response['error'], isNull);

// [{"event":"device.added","params":{"id":"flutter-tester","name":
// "Flutter test device","platform":"flutter-tester","emulator":false}}]
response = await stream.first;
response = (await stream.first)!;
expect(response['event'], 'device.added');

// get the list of all devices
Expand All @@ -71,7 +69,7 @@ void main() {
'method': 'device.getDevices',
})}]');
// Skip other device.added events that may fire (desktop/web devices).
response = await stream.firstWhere((Map<String, dynamic> response) => response['event'] != 'device.added');
response = (await stream.firstWhere((Map<String, Object?>? response) => response!['event'] != 'device.added'))!;
expect(response['id'], 2);
expect(response['error'], isNull);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/io.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
Expand All @@ -29,7 +27,7 @@ final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform

/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
void main() {
Directory parentDirectory;
late Directory parentDirectory;

setUp(() {
parentDirectory = fileSystem.systemTempDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';

Expand All @@ -12,7 +10,7 @@ import 'test_utils.dart';

void main() {
final String dartBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'dart');
Directory tempDir;
late Directory tempDir;

setUp(() {
tempDir = createResolvedTempDirectorySync('exit_code_test.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:vm_service/vm_service.dart';

Expand All @@ -13,9 +11,9 @@ import 'test_driver.dart';
import 'test_utils.dart';

void main() {
FlutterRunTestDriver flutterRun, flutterAttach;
late FlutterRunTestDriver flutterRun, flutterAttach;
final BasicProject project = BasicProject();
Directory tempDir;
late Directory tempDir;

setUp(() async {
tempDir = createResolvedTempDirectorySync('attach_test.');
Expand All @@ -39,28 +37,28 @@ void main() {

testWithoutContext('can hot reload', () async {
await flutterRun.run(withDebugger: true);
await flutterAttach.attach(flutterRun.vmServicePort);
await flutterAttach.attach(flutterRun.vmServicePort!);
await flutterAttach.hotReload();
});

testWithoutContext('can detach, reattach, hot reload', () async {
await flutterRun.run(withDebugger: true);
await flutterAttach.attach(flutterRun.vmServicePort);
await flutterAttach.attach(flutterRun.vmServicePort!);
await flutterAttach.detach();
await flutterAttach.attach(flutterRun.vmServicePort);
await flutterAttach.attach(flutterRun.vmServicePort!);
await flutterAttach.hotReload();
});

testWithoutContext('killing process behaves the same as detach ', () async {
await flutterRun.run(withDebugger: true);
await flutterAttach.attach(flutterRun.vmServicePort);
await flutterAttach.attach(flutterRun.vmServicePort!);
await flutterAttach.quit();
flutterAttach = FlutterRunTestDriver(
tempDir,
logPrefix: 'ATTACH-2',
spawnDdsInstance: false,
);
await flutterAttach.attach(flutterRun.vmServicePort);
await flutterAttach.attach(flutterRun.vmServicePort!);
await flutterAttach.hotReload();
});

Expand All @@ -85,11 +83,11 @@ void main() {
);

final Response response = await flutterRun.callServiceExtension('ext.flutter.connectedVmServiceUri');
final String vmServiceUri = response.json['value'] as String;
final String vmServiceUri = response.json!['value'] as String;

// Attach with a different DevTools server address.
await flutterAttach.attach(
flutterRun.vmServicePort,
flutterRun.vmServicePort!,
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9110'],
);
await pollForServiceExtensionValue<String>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';

Expand All @@ -17,9 +15,9 @@ import 'test_utils.dart';
// `flutter build` command inside the `example` directory, so we create a plugin
// project in the test.
void main() {
Directory tempDir;
String flutterBin;
Directory exampleAppDir;
late Directory tempDir;
late String flutterBin;
late Directory exampleAppDir;

setUp(() async {
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
Directory projectRoot;
String flutterBin;
late Directory tempDir;
late Directory projectRoot;
late String flutterBin;
final List<String> targetPlatforms = <String>[
'apk',
'web',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
Directory projectRoot;
String flutterBin;
late Directory tempDir;
late Directory projectRoot;
late String flutterBin;
final List<String> targetPlatforms = <String>[
'apk',
'web',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:convert';

import 'package:file/file.dart';
Expand All @@ -14,9 +12,9 @@ import 'test_driver.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
late Directory tempDir;
final BasicProjectWithFlutterGen project = BasicProjectWithFlutterGen();
FlutterRunTestDriver flutter;
late FlutterRunTestDriver flutter;

setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:process/process.dart';
Expand All @@ -14,9 +12,9 @@ import 'test_driver.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
late Directory tempDir;
final BasicProject project = BasicProject();
FlutterRunTestDriver flutter;
late FlutterRunTestDriver flutter;

setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:async';

import 'package:file/file.dart';
Expand All @@ -17,10 +15,10 @@ import 'test_driver.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
late Directory tempDir;
final ProjectWithEarlyError project = ProjectWithEarlyError();
const String exceptionStart = '══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞══════════════════';
FlutterRunTestDriver flutter;
late FlutterRunTestDriver flutter;

setUp(() async {
tempDir = createResolvedTempDirectorySync('run_test.');
Expand Down Expand Up @@ -56,14 +54,14 @@ void main() {

if (line.startsWith('An Observatory debugger')) {
final RegExp exp = RegExp(r'http://127.0.0.1:(\d+)/');
final RegExpMatch match = exp.firstMatch(line);
final String port = match.group(1);
final RegExpMatch match = exp.firstMatch(line)!;
final String port = match.group(1)!;
if (port != null) {
final VmService vmService =
await vmServiceConnectUri('ws://localhost:$port/ws');
final VM vm = await vmService.getVM();
for (final IsolateRef isolate in vm.isolates) {
await vmService.resume(isolate.id);
for (final IsolateRef isolate in vm.isolates!) {
await vmService.resume(isolate.id!);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';

import '../src/common.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'dart:async';

import 'package:file/file.dart';
Expand All @@ -19,8 +17,8 @@ final GenL10nProject project = GenL10nProject();
// It can fail if gen_l10n produces a lib/l10n/app_localizations.dart that
// does not analyze cleanly.
void main() {
Directory tempDir;
FlutterRunTestDriver flutter;
late Directory tempDir;
late FlutterRunTestDriver flutter;

setUp(() async {
tempDir = createResolvedTempDirectorySync('gen_l10n_test.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.8

import 'package:file/file.dart';
import 'package:file_testing/file_testing.dart';

import '../src/common.dart';
import 'test_utils.dart';

void main() {
Directory tempDir;
late Directory tempDir;

setUp(() {
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');
Expand Down
Loading

0 comments on commit 9f28b83

Please sign in to comment.