Skip to content

Commit 9f28b83

Browse files
author
Jonah Williams
authored
[flutter_tools] migrate some integration tests to null safety (flutter#103560)
1 parent 42b6fba commit 9f28b83

32 files changed

+110
-175
lines changed

packages/flutter_tools/test/integration.shard/daemon_mode_test.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'dart:async';
86
import 'dart:convert';
97
import 'dart:io' hide Directory;
@@ -17,16 +15,16 @@ import 'test_driver.dart';
1715
import 'test_utils.dart';
1816

1917
void main() {
20-
Directory tempDir;
21-
Process daemonProcess;
18+
late Directory tempDir;
19+
late Process daemonProcess;
2220

2321
setUp(() async {
2422
tempDir = createResolvedTempDirectorySync('daemon_mode_test.');
2523
});
2624

2725
tearDown(() async {
2826
tryToDelete(tempDir);
29-
daemonProcess?.kill();
27+
daemonProcess.kill();
3028
});
3129

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

4442
final StreamController<String> stdout = StreamController<String>.broadcast();
4543
transformToLines(daemonProcess.stdout).listen((String line) => stdout.add(line));
46-
final Stream<Map<String, dynamic>> stream = stdout
44+
final Stream<Map<String, Object?>?> stream = stdout
4745
.stream
48-
.map<Map<String, dynamic>>(parseFlutterResponse)
49-
.where((Map<String, dynamic> value) => value != null);
46+
.map<Map<String, Object?>?>(parseFlutterResponse)
47+
.where((Map<String, Object?>? value) => value != null);
5048

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

5452
// start listening for devices
5553
daemonProcess.stdin.writeln('[${jsonEncode(<String, dynamic>{
5654
'id': 1,
5755
'method': 'device.enable',
5856
})}]');
59-
response = await stream.firstWhere((Map<String, Object> json) => json['id'] == 1);
57+
response = (await stream.firstWhere((Map<String, Object?>? json) => json!['id'] == 1))!;
6058
expect(response['id'], 1);
6159
expect(response['error'], isNull);
6260

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

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

packages/flutter_tools/test/integration.shard/deprecated_gradle_settings_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file_testing/file_testing.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97

packages/flutter_tools/test/integration.shard/downgrade_upgrade_integration_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:flutter_tools/src/base/file_system.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97
import 'package:flutter_tools/src/base/logger.dart';
@@ -29,7 +27,7 @@ final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform
2927

3028
/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
3129
void main() {
32-
Directory parentDirectory;
30+
late Directory parentDirectory;
3331

3432
setUp(() {
3533
parentDirectory = fileSystem.systemTempDirectory

packages/flutter_tools/test/integration.shard/exit_code_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file/file.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97

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

1311
void main() {
1412
final String dartBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'dart');
15-
Directory tempDir;
13+
late Directory tempDir;
1614

1715
setUp(() {
1816
tempDir = createResolvedTempDirectorySync('exit_code_test.');

packages/flutter_tools/test/integration.shard/flutter_attach_test.dart

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file/file.dart';
86
import 'package:vm_service/vm_service.dart';
97

@@ -13,9 +11,9 @@ import 'test_driver.dart';
1311
import 'test_utils.dart';
1412

1513
void main() {
16-
FlutterRunTestDriver flutterRun, flutterAttach;
14+
late FlutterRunTestDriver flutterRun, flutterAttach;
1715
final BasicProject project = BasicProject();
18-
Directory tempDir;
16+
late Directory tempDir;
1917

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

4038
testWithoutContext('can hot reload', () async {
4139
await flutterRun.run(withDebugger: true);
42-
await flutterAttach.attach(flutterRun.vmServicePort);
40+
await flutterAttach.attach(flutterRun.vmServicePort!);
4341
await flutterAttach.hotReload();
4442
});
4543

4644
testWithoutContext('can detach, reattach, hot reload', () async {
4745
await flutterRun.run(withDebugger: true);
48-
await flutterAttach.attach(flutterRun.vmServicePort);
46+
await flutterAttach.attach(flutterRun.vmServicePort!);
4947
await flutterAttach.detach();
50-
await flutterAttach.attach(flutterRun.vmServicePort);
48+
await flutterAttach.attach(flutterRun.vmServicePort!);
5149
await flutterAttach.hotReload();
5250
});
5351

5452
testWithoutContext('killing process behaves the same as detach ', () async {
5553
await flutterRun.run(withDebugger: true);
56-
await flutterAttach.attach(flutterRun.vmServicePort);
54+
await flutterAttach.attach(flutterRun.vmServicePort!);
5755
await flutterAttach.quit();
5856
flutterAttach = FlutterRunTestDriver(
5957
tempDir,
6058
logPrefix: 'ATTACH-2',
6159
spawnDdsInstance: false,
6260
);
63-
await flutterAttach.attach(flutterRun.vmServicePort);
61+
await flutterAttach.attach(flutterRun.vmServicePort!);
6462
await flutterAttach.hotReload();
6563
});
6664

@@ -85,11 +83,11 @@ void main() {
8583
);
8684

8785
final Response response = await flutterRun.callServiceExtension('ext.flutter.connectedVmServiceUri');
88-
final String vmServiceUri = response.json['value'] as String;
86+
final String vmServiceUri = response.json!['value'] as String;
8987

9088
// Attach with a different DevTools server address.
9189
await flutterAttach.attach(
92-
flutterRun.vmServicePort,
90+
flutterRun.vmServicePort!,
9391
additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9110'],
9492
);
9593
await pollForServiceExtensionValue<String>(

packages/flutter_tools/test/integration.shard/flutter_build_android_app_project_builddir_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file_testing/file_testing.dart';
86
import 'package:flutter_tools/src/base/file_system.dart';
97

@@ -17,9 +15,9 @@ import 'test_utils.dart';
1715
// `flutter build` command inside the `example` directory, so we create a plugin
1816
// project in the test.
1917
void main() {
20-
Directory tempDir;
21-
String flutterBin;
22-
Directory exampleAppDir;
18+
late Directory tempDir;
19+
late String flutterBin;
20+
late Directory exampleAppDir;
2321

2422
setUp(() async {
2523
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');

packages/flutter_tools/test/integration.shard/flutter_build_null_unsafe_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file/file.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97

108
import '../src/common.dart';
119
import 'test_utils.dart';
1210

1311
void main() {
14-
Directory tempDir;
15-
Directory projectRoot;
16-
String flutterBin;
12+
late Directory tempDir;
13+
late Directory projectRoot;
14+
late String flutterBin;
1715
final List<String> targetPlatforms = <String>[
1816
'apk',
1917
'web',

packages/flutter_tools/test/integration.shard/flutter_build_with_compilation_error_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file/file.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97

108
import '../src/common.dart';
119
import 'test_utils.dart';
1210

1311
void main() {
14-
Directory tempDir;
15-
Directory projectRoot;
16-
String flutterBin;
12+
late Directory tempDir;
13+
late Directory projectRoot;
14+
late String flutterBin;
1715
final List<String> targetPlatforms = <String>[
1816
'apk',
1917
'web',

packages/flutter_tools/test/integration.shard/flutter_gen_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'dart:convert';
86

97
import 'package:file/file.dart';
@@ -14,9 +12,9 @@ import 'test_driver.dart';
1412
import 'test_utils.dart';
1513

1614
void main() {
17-
Directory tempDir;
15+
late Directory tempDir;
1816
final BasicProjectWithFlutterGen project = BasicProjectWithFlutterGen();
19-
FlutterRunTestDriver flutter;
17+
late FlutterRunTestDriver flutter;
2018

2119
setUp(() async {
2220
tempDir = createResolvedTempDirectorySync('run_test.');

packages/flutter_tools/test/integration.shard/flutter_run_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.8
6-
75
import 'package:file/file.dart';
86
import 'package:flutter_tools/src/base/io.dart';
97
import 'package:process/process.dart';
@@ -14,9 +12,9 @@ import 'test_driver.dart';
1412
import 'test_utils.dart';
1513

1614
void main() {
17-
Directory tempDir;
15+
late Directory tempDir;
1816
final BasicProject project = BasicProject();
19-
FlutterRunTestDriver flutter;
17+
late FlutterRunTestDriver flutter;
2018

2119
setUp(() async {
2220
tempDir = createResolvedTempDirectorySync('run_test.');

0 commit comments

Comments
 (0)