Skip to content

Commit db829c1

Browse files
author
Jonah Williams
authored
[flutter_tools] migrate more unit tests to null safety (#106153)
1 parent 2af8250 commit db829c1

File tree

70 files changed

+798
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+798
-950
lines changed

packages/flutter_tools/lib/src/build_system/targets/assets.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ DevFSContent? processSkSLBundle(String? bundlePath, {
210210
}
211211

212212
// Step 2: validate top level bundle structure.
213-
Map<String, Object>? bundle;
213+
Map<String, Object?>? bundle;
214214
try {
215215
final Object? rawBundle = json.decode(skSLBundleFile.readAsStringSync());
216-
if (rawBundle is Map<String, Object>) {
216+
if (rawBundle is Map<String, Object?>) {
217217
bundle = rawBundle;
218218
} else {
219219
logger.printError('"$bundle" was not a JSON object: $rawBundle');

packages/flutter_tools/lib/src/cache.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,10 @@ class Cache {
389389
throw Exception('Could not find file at $versionFilePath');
390390
}
391391
final dynamic data = jsonDecode(versionFile.readAsStringSync());
392-
if (data is! Map<String, Object>) {
393-
throw Exception("Expected object of type 'Map<String, Object>' but got one of type '${data.runtimeType}'");
392+
if (data is! Map<String, Object?>) {
393+
throw Exception("Expected object of type 'Map<String, Object?>' but got one of type '${data.runtimeType}'");
394394
}
395-
final dynamic version = data['version'];
395+
final Object? version = data['version'];
396396
if (version == null) {
397397
throw Exception('Could not parse DevTools version from $version');
398398
}

packages/flutter_tools/lib/src/commands/create_base.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,11 @@ abstract class CreateBase extends FlutterCommand {
668668
'templates',
669669
'template_manifest.json',
670670
);
671-
final Map<String, Object> manifest = json.decode(
671+
final Map<String, Object?> manifest = json.decode(
672672
globals.fs.file(manifestPath).readAsStringSync(),
673-
) as Map<String, Object>;
673+
) as Map<String, Object?>;
674674
return Set<Uri>.from(
675-
(manifest['files']! as List<Object>).cast<String>().map<Uri>(
675+
(manifest['files']! as List<Object?>).cast<String>().map<Uri>(
676676
(String path) =>
677677
Uri.file(globals.fs.path.join(flutterToolsAbsolutePath, path))),
678678
);

packages/flutter_tools/lib/src/macos/application_package.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ abstract class MacOSApp extends ApplicationPackage {
8686
return null;
8787
}
8888
final Map<String, dynamic> propertyValues = globals.plistParser.parseFile(plistPath);
89-
final String id = propertyValues[PlistParser.kCFBundleIdentifierKey] as String;
90-
final String executableName = propertyValues[PlistParser.kCFBundleExecutable] as String;
89+
final String? id = propertyValues[PlistParser.kCFBundleIdentifierKey] as String?;
90+
final String? executableName = propertyValues[PlistParser.kCFBundleExecutable] as String?;
9191
if (id == null) {
9292
globals.printError('Invalid prebuilt macOS app. Info.plist does not contain bundle identifier');
9393
return null;

packages/flutter_tools/lib/src/runner/flutter_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ abstract class FlutterCommand extends Command<void> {
15341534
if (!argParser.options.containsKey(name)) {
15351535
return null;
15361536
}
1537-
return argResults![name] as String;
1537+
return argResults![name] as String?;
15381538
}
15391539

15401540
/// Gets the parsed command-line option named [name] as an `int`.

packages/flutter_tools/lib/src/test/coverage_collector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CoverageCollector extends TestWatcher {
117117
);
118118

119119
final Future<void> collectionComplete = testDevice.observatoryUri
120-
.then((Uri observatoryUri) {
120+
.then((Uri? observatoryUri) {
121121
_logMessage('collecting coverage data from $testDevice at $observatoryUri...');
122122
return collect(observatoryUri, libraryNames)
123123
.then<void>((Map<String, dynamic> result) {

packages/flutter_tools/lib/src/test/flutter_platform.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ class FlutterPlatform extends PlatformPlugin {
494494
await Future.any<void>(<Future<void>>[
495495
testDevice.finished,
496496
() async {
497-
final Uri processObservatoryUri = await testDevice.observatoryUri;
497+
final Uri? processObservatoryUri = await testDevice.observatoryUri;
498498
if (processObservatoryUri != null) {
499499
globals.printTrace('test $ourTestCount: Observatory uri is available at $processObservatoryUri');
500500
} else {

packages/flutter_tools/lib/src/test/flutter_tester_device.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class FlutterTesterTestDevice extends TestDevice {
4747
}) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable.
4848
assert(!debuggingOptions.startPaused || enableObservatory),
4949
_gotProcessObservatoryUri = enableObservatory
50-
// ignore: null_argument_to_non_null_type
51-
? Completer<Uri>() : (Completer<Uri>()..complete()),
50+
? Completer<Uri?>() : (Completer<Uri?>()..complete()),
5251
_operatingSystemUtils = OperatingSystemUtils(
5352
fileSystem: fileSystem,
5453
logger: logger,
@@ -73,7 +72,7 @@ class FlutterTesterTestDevice extends TestDevice {
7372
final CompileExpression? compileExpression;
7473
final FontConfigManager fontConfigManager;
7574

76-
final Completer<Uri> _gotProcessObservatoryUri;
75+
final Completer<Uri?> _gotProcessObservatoryUri;
7776
final Completer<int> _exitCode = Completer<int>();
7877

7978
Process? _process;
@@ -209,7 +208,7 @@ class FlutterTesterTestDevice extends TestDevice {
209208
}
210209

211210
@override
212-
Future<Uri> get observatoryUri {
211+
Future<Uri?> get observatoryUri {
213212
assert(_gotProcessObservatoryUri != null);
214213
return _gotProcessObservatoryUri.future;
215214
}

packages/flutter_tools/lib/src/test/test_compiler.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TestCompiler {
7979
late File outputDill;
8080

8181
Future<String?> compile(Uri mainDart) {
82-
final Completer<String> completer = Completer<String>();
82+
final Completer<String?> completer = Completer<String?>();
8383
if (compilerController.isClosed) {
8484
return Future<String?>.value();
8585
}
@@ -175,7 +175,7 @@ class TestCompiler {
175175
// compiler to avoid reusing compiler that might have gotten into
176176
// a weird state.
177177
if (outputPath == null || compilerOutput!.errorCount > 0) {
178-
request.result.complete(null);
178+
request.result.complete();
179179
await _shutdown();
180180
} else {
181181
if (shouldCopyDillFile) {

packages/flutter_tools/lib/src/test/test_device.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class TestDevice {
2222
Future<StreamChannel<String>> start(String entrypointPath);
2323

2424
/// Should complete with null if the observatory is not enabled.
25-
Future<Uri> get observatoryUri;
25+
Future<Uri?> get observatoryUri;
2626

2727
/// Terminates the test device.
2828
Future<void> kill();

0 commit comments

Comments
 (0)