From 4453ba0a4d3a6ce5fcf29bb39d1cb3d2360b6874 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Wed, 7 Sep 2022 12:28:52 -0700 Subject: [PATCH] Null safety migration of packages/flutter_tools/test/general.shard, part 2/2 (#110712) * Migrate packages/flutter_tools/test/general.shard, part 2/2 * Fix analysis * Fix tests * Fix analysis * Apply suggestions from code review Co-authored-by: Christopher Fujino Co-authored-by: Christopher Fujino --- .../lib/src/resident_runner.dart | 2 +- packages/flutter_tools/lib/src/vmservice.dart | 4 +- .../application_package_test.dart | 105 +++++----- .../test/general.shard/args_test.dart | 17 +- .../test/general.shard/emulator_test.dart | 36 +++- .../test/general.shard/hot_test.dart | 123 ++++++----- .../resident_web_runner_cold_test.dart | 32 ++- .../resident_web_runner_test.dart | 198 +++++++++--------- .../test/general.shard/vmservice_test.dart | 36 ++-- .../general.shard/web/devfs_web_test.dart | 101 +++++---- .../web/golden_comparator_process_test.dart | 12 +- ...crub_generated_plugin_registrant_test.dart | 12 +- .../web/web_asset_server_test.dart | 4 +- .../web/web_expression_compiler_test.dart | 14 +- 14 files changed, 343 insertions(+), 353 deletions(-) diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index de428242089..4b493d93c47 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -707,7 +707,7 @@ abstract class ResidentHandlers { } final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { - final Map? rasterData = + final Map? rasterData = await device.vmService!.renderFrameWithRasterStats( viewId: view.id, uiIsolateId: view.uiIsolate!.id, diff --git a/packages/flutter_tools/lib/src/vmservice.dart b/packages/flutter_tools/lib/src/vmservice.dart index 1d1d5c7fc17..95429336fe0 100644 --- a/packages/flutter_tools/lib/src/vmservice.dart +++ b/packages/flutter_tools/lib/src/vmservice.dart @@ -557,7 +557,7 @@ class FlutterVmService { /// for rasterization which is not reflective of how long the frame takes in /// production. This is primarily intended to be used to identify the layers /// that result in the most raster perf degradation. - Future?> renderFrameWithRasterStats({ + Future?> renderFrameWithRasterStats({ required String? viewId, required String? uiIsolateId, }) async { @@ -568,7 +568,7 @@ class FlutterVmService { 'viewId': viewId, }, ); - return response?.json as Map?; + return response?.json; } Future flutterDebugDumpApp({ diff --git a/packages/flutter_tools/test/general.shard/application_package_test.dart b/packages/flutter_tools/test/general.shard/application_package_test.dart index 5b94432d32c..fe1bb0fff41 100644 --- a/packages/flutter_tools/test/general.shard/application_package_test.dart +++ b/packages/flutter_tools/test/general.shard/application_package_test.dart @@ -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:file/memory.dart'; import 'package:flutter_tools/src/android/android_sdk.dart'; @@ -30,10 +28,10 @@ import '../src/fakes.dart'; void main() { group('Apk with partial Android SDK works', () { - FakeAndroidSdk sdk; - FakeProcessManager fakeProcessManager; - MemoryFileSystem fs; - Cache cache; + late FakeAndroidSdk sdk; + late FakeProcessManager fakeProcessManager; + late MemoryFileSystem fs; + late Cache cache; final Map overrides = { AndroidSdk: () => sdk, @@ -79,11 +77,10 @@ void main() { ) ); - final ApplicationPackage applicationPackage = await ApplicationPackageFactory.instance.getPackageForPlatform( + final ApplicationPackage applicationPackage = (await ApplicationPackageFactory.instance!.getPackageForPlatform( TargetPlatform.android_arm, - buildInfo: null, applicationBinary: apkFile, - ); + ))!; expect(applicationPackage.name, 'app.apk'); expect(applicationPackage, isA()); expect((applicationPackage as PrebuiltApplicationPackage).applicationPackage.path, apkFile.path); @@ -104,9 +101,8 @@ void main() { gradleWrapperDir.childFile('gradlew').writeAsStringSync('irrelevant'); gradleWrapperDir.childFile('gradlew.bat').writeAsStringSync('irrelevant'); - await ApplicationPackageFactory.instance.getPackageForPlatform( + await ApplicationPackageFactory.instance!.getPackageForPlatform( TargetPlatform.android_arm, - buildInfo: null, applicationBinary: globals.fs.file('app.apk'), ); expect(fakeProcessManager, hasNoRemainingExpectations); @@ -116,19 +112,16 @@ void main() { final AndroidSdkVersion sdkVersion = FakeAndroidSdkVersion(); sdk.latestVersion = sdkVersion; - await ApplicationPackageFactory.instance.getPackageForPlatform( + await ApplicationPackageFactory.instance!.getPackageForPlatform( TargetPlatform.android_arm, - buildInfo: null, ); expect(fakeProcessManager, hasNoRemainingExpectations); }, overrides: overrides); testWithoutContext('returns null when failed to extract manifest', () async { - final AndroidSdkVersion sdkVersion = FakeAndroidSdkVersion(); - sdk.latestVersion = sdkVersion; final Logger logger = BufferLogger.test(); - final AndroidApk androidApk = AndroidApk.fromApk( - null, + final AndroidApk? androidApk = AndroidApk.fromApk( + fs.file(''), processManager: fakeProcessManager, logger: logger, userMessages: UserMessages(), @@ -146,7 +139,7 @@ void main() { final ApkManifestData data = ApkManifestData.parseFromXmlDump( _aaptDataWithExplicitEnabledAndMainLauncherActivity, BufferLogger.test(), - ); + )!; expect(data, isNotNull); expect(data.packageName, 'io.flutter.examples.hello_world'); @@ -157,7 +150,7 @@ void main() { final ApkManifestData data = ApkManifestData.parseFromXmlDump( _aaptDataWithDefaultEnabledAndMainLauncherActivity, BufferLogger.test(), - ); + )!; expect(data, isNotNull); expect(data.packageName, 'io.flutter.examples.hello_world'); @@ -168,7 +161,7 @@ void main() { final ApkManifestData data = ApkManifestData.parseFromXmlDump( _aaptDataWithDistNamespace, BufferLogger.test(), - ); + )!; expect(data, isNotNull); expect(data.packageName, 'io.flutter.examples.hello_world'); @@ -177,7 +170,7 @@ void main() { testWithoutContext('Error when parsing manifest with no Activity that has enabled set to true nor has no value for its enabled field', () { final BufferLogger logger = BufferLogger.test(); - final ApkManifestData data = ApkManifestData.parseFromXmlDump( + final ApkManifestData? data = ApkManifestData.parseFromXmlDump( _aaptDataWithNoEnabledActivity, logger, ); @@ -191,7 +184,7 @@ void main() { testWithoutContext('Error when parsing manifest with no Activity that has action set to android.intent.action.MAIN', () { final BufferLogger logger = BufferLogger.test(); - final ApkManifestData data = ApkManifestData.parseFromXmlDump( + final ApkManifestData? data = ApkManifestData.parseFromXmlDump( _aaptDataWithNoMainActivity, logger, ); @@ -205,7 +198,7 @@ void main() { testWithoutContext('Error when parsing manifest with no Activity that has category set to android.intent.category.LAUNCHER', () { final BufferLogger logger = BufferLogger.test(); - final ApkManifestData data = ApkManifestData.parseFromXmlDump( + final ApkManifestData? data = ApkManifestData.parseFromXmlDump( _aaptDataWithNoLauncherActivity, logger, ); @@ -221,7 +214,7 @@ void main() { final ApkManifestData data = ApkManifestData.parseFromXmlDump( _aaptDataWithLauncherAndDefaultActivity, BufferLogger.test(), - ); + )!; expect(data, isNotNull); expect(data.packageName, 'io.flutter.examples.hello_world'); @@ -229,7 +222,7 @@ void main() { }); testWithoutContext('Parses manifest with missing application tag', () async { - final ApkManifestData data = ApkManifestData.parseFromXmlDump( + final ApkManifestData? data = ApkManifestData.parseFromXmlDump( _aaptDataWithoutApplication, BufferLogger.test(), ); @@ -239,8 +232,8 @@ void main() { }); group('PrebuiltIOSApp', () { - FakeOperatingSystemUtils os; - FakePlistParser testPlistParser; + late FakeOperatingSystemUtils os; + late FakePlistParser testPlistParser; final Map overrides = { FileSystem: () => MemoryFileSystem.test(), @@ -255,8 +248,8 @@ void main() { }); testUsingContext('Error on non-existing file', () { - final PrebuiltIOSApp iosApp = - IOSApp.fromPrebuiltApp(globals.fs.file('not_existing.ipa')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = + IOSApp.fromPrebuiltApp(globals.fs.file('not_existing.ipa')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect( testLogger.errorText, @@ -266,8 +259,8 @@ void main() { testUsingContext('Error on non-app-bundle folder', () { globals.fs.directory('regular_folder').createSync(); - final PrebuiltIOSApp iosApp = - IOSApp.fromPrebuiltApp(globals.fs.file('regular_folder')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = + IOSApp.fromPrebuiltApp(globals.fs.file('regular_folder')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect( testLogger.errorText, 'Folder "regular_folder" is not an app bundle.\n'); @@ -275,7 +268,7 @@ void main() { testUsingContext('Error on no info.plist', () { globals.fs.directory('bundle.app').createSync(); - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect( testLogger.errorText, @@ -286,7 +279,7 @@ void main() { testUsingContext('Error on bad info.plist', () { globals.fs.directory('bundle.app').createSync(); globals.fs.file('bundle.app/Info.plist').createSync(); - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect( testLogger.errorText, @@ -299,7 +292,7 @@ void main() { globals.fs.directory('bundle.app').createSync(); globals.fs.file('bundle.app/Info.plist').createSync(); testPlistParser.setProperty('CFBundleIdentifier', 'fooBundleId'); - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp; + final PrebuiltIOSApp iosApp = (IOSApp.fromPrebuiltApp(globals.fs.file('bundle.app')) as PrebuiltIOSApp?)!; expect(testLogger.errorText, isEmpty); expect(iosApp.uncompressedBundle.path, 'bundle.app'); expect(iosApp.id, 'fooBundleId'); @@ -309,7 +302,7 @@ void main() { testUsingContext('Bad ipa zip-file, no payload dir', () { globals.fs.file('app.ipa').createSync(); - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect( testLogger.errorText, @@ -330,7 +323,7 @@ void main() { globals.fs.directory(bundlePath1).createSync(recursive: true); globals.fs.directory(bundlePath2).createSync(recursive: true); }; - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp; + final PrebuiltIOSApp? iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp?; expect(iosApp, isNull); expect(testLogger.errorText, 'Invalid prebuilt iOS ipa. Does not contain a single app bundle.\n'); @@ -350,7 +343,7 @@ void main() { .file(globals.fs.path.join(bundleAppDir.path, 'Info.plist')) .createSync(); }; - final PrebuiltIOSApp iosApp = IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp; + final PrebuiltIOSApp iosApp = (IOSApp.fromPrebuiltApp(globals.fs.file('app.ipa')) as PrebuiltIOSApp?)!; expect(testLogger.errorText, isEmpty); expect(iosApp.uncompressedBundle.path, endsWith('bundle.app')); expect(iosApp.id, 'fooBundleId'); @@ -361,8 +354,8 @@ void main() { testUsingContext('returns null when there is no ios or .ios directory', () async { globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('.packages').createSync(); - final BuildableIOSApp iosApp = await IOSApp.fromIosProject( - FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp; + final BuildableIOSApp? iosApp = await IOSApp.fromIosProject( + FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?; expect(iosApp, null); }, overrides: overrides); @@ -371,8 +364,8 @@ void main() { globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('.packages').createSync(); globals.fs.file('ios/FooBar.xcodeproj').createSync(recursive: true); - final BuildableIOSApp iosApp = await IOSApp.fromIosProject( - FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp; + final BuildableIOSApp? iosApp = await IOSApp.fromIosProject( + FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?; expect(iosApp, null); }, overrides: overrides); @@ -381,8 +374,8 @@ void main() { globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('.packages').createSync(); globals.fs.file('ios/Runner.xcodeproj').createSync(recursive: true); - final BuildableIOSApp iosApp = await IOSApp.fromIosProject( - FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp; + final BuildableIOSApp? iosApp = await IOSApp.fromIosProject( + FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?; expect(iosApp, null); }, overrides: overrides); @@ -392,8 +385,8 @@ void main() { globals.fs.file('.packages').createSync(); final Directory project = globals.fs.directory('ios/Runner.xcodeproj')..createSync(recursive: true); project.childFile('project.pbxproj').createSync(); - final BuildableIOSApp iosApp = await IOSApp.fromIosProject( - FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp; + final BuildableIOSApp? iosApp = await IOSApp.fromIosProject( + FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?; expect(iosApp, null); }, overrides: overrides); @@ -407,8 +400,8 @@ void main() { }; testUsingContext('Error on non-existing file', () { - final PrebuiltFuchsiaApp fuchsiaApp = - FuchsiaApp.fromPrebuiltApp(globals.fs.file('not_existing.far')) as PrebuiltFuchsiaApp; + final PrebuiltFuchsiaApp? fuchsiaApp = + FuchsiaApp.fromPrebuiltApp(globals.fs.file('not_existing.far')) as PrebuiltFuchsiaApp?; expect(fuchsiaApp, isNull); expect( testLogger.errorText, @@ -418,8 +411,8 @@ void main() { testUsingContext('Error on non-far file', () { globals.fs.directory('regular_folder').createSync(); - final PrebuiltFuchsiaApp fuchsiaApp = - FuchsiaApp.fromPrebuiltApp(globals.fs.file('regular_folder')) as PrebuiltFuchsiaApp; + final PrebuiltFuchsiaApp? fuchsiaApp = + FuchsiaApp.fromPrebuiltApp(globals.fs.file('regular_folder')) as PrebuiltFuchsiaApp?; expect(fuchsiaApp, isNull); expect( testLogger.errorText, @@ -429,7 +422,7 @@ void main() { testUsingContext('Success with far file', () { globals.fs.file('bundle.far').createSync(); - final PrebuiltFuchsiaApp fuchsiaApp = FuchsiaApp.fromPrebuiltApp(globals.fs.file('bundle.far')) as PrebuiltFuchsiaApp; + final PrebuiltFuchsiaApp fuchsiaApp = (FuchsiaApp.fromPrebuiltApp(globals.fs.file('bundle.far')) as PrebuiltFuchsiaApp?)!; expect(testLogger.errorText, isEmpty); expect(fuchsiaApp.id, 'bundle.far'); expect(fuchsiaApp.applicationPackage.path, globals.fs.file('bundle.far').path); @@ -438,7 +431,7 @@ void main() { testUsingContext('returns null when there is no fuchsia', () async { globals.fs.file('pubspec.yaml').createSync(); globals.fs.file('.packages').createSync(); - final BuildableFuchsiaApp fuchsiaApp = FuchsiaApp.fromFuchsiaProject(FlutterProject.fromDirectory(globals.fs.currentDirectory).fuchsia) as BuildableFuchsiaApp; + final BuildableFuchsiaApp? fuchsiaApp = FuchsiaApp.fromFuchsiaProject(FlutterProject.fromDirectory(globals.fs.currentDirectory).fuchsia) as BuildableFuchsiaApp?; expect(fuchsiaApp, null); }, overrides: overrides); @@ -707,7 +700,7 @@ N: android=http://schemas.android.com/apk/res/android '''; class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils { - void Function(File, Directory) onUnzip; + void Function(File, Directory)? onUnzip; @override void unzip(File file, Directory targetDirectory) { @@ -717,16 +710,16 @@ class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils { class FakeAndroidSdk extends Fake implements AndroidSdk { @override - bool platformToolsAvailable; + late bool platformToolsAvailable; @override - bool licensesAvailable; + late bool licensesAvailable; @override - AndroidSdkVersion latestVersion; + AndroidSdkVersion? latestVersion; } class FakeAndroidSdkVersion extends Fake implements AndroidSdkVersion { @override - String aaptPath; + late String aaptPath; } diff --git a/packages/flutter_tools/test/general.shard/args_test.dart b/packages/flutter_tools/test/general.shard/args_test.dart index 4725e37d2aa..683a4df7088 100644 --- a/packages/flutter_tools/test/general.shard/args_test.dart +++ b/packages/flutter_tools/test/general.shard/args_test.dart @@ -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:args/args.dart'; import 'package:args/command_runner.dart'; import 'package:flutter_tools/executable.dart' as executable; @@ -111,7 +109,7 @@ void main() { }); } -void verifyCommandRunner(CommandRunner runner) { +void verifyCommandRunner(CommandRunner runner) { expect(runner.argParser, isNotNull, reason: '${runner.runtimeType} has no argParser'); expect(runner.argParser.allowsAnything, isFalse, reason: '${runner.runtimeType} allows anything'); expect(runner.argParser.allowTrailingOptions, isFalse, reason: '${runner.runtimeType} allows trailing options'); @@ -119,7 +117,7 @@ void verifyCommandRunner(CommandRunner runner) { runner.commands.values.forEach(verifyCommand); } -void verifyCommand(Command runner) { +void verifyCommand(Command runner) { expect(runner.argParser, isNotNull, reason: 'command ${runner.name} has no argParser'); verifyOptions(runner.name, runner.argParser.options.values); @@ -161,7 +159,7 @@ const String _needHelp = "Every option must have help explaining what it does, e const String _header = ' Comment: '; -void verifyOptions(String command, Iterable