From 8da0432094c2c581c08a48927cc296ed8adbf669 Mon Sep 17 00:00:00 2001 From: Liam Appelbe Date: Tue, 6 Sep 2022 11:21:23 -0700 Subject: [PATCH] Null safety migration of packages/flutter_tools/test/commands.shard/hermetic, part 1/3 (#110707) * Migrate packages/flutter_tools/test/commands.shard/hermetic, part 1/3 * Fix tests * Fix analysis * Fix analyze_test * Make AnalysisServer a local variable * Chris's comments --- .../lib/src/commands/analyze_base.dart | 2 +- .../hermetic/analyze_continuously_test.dart | 49 +++++++++---------- .../hermetic/analyze_suggestion_test.dart | 16 +++--- .../commands.shard/hermetic/analyze_test.dart | 25 +++++----- .../hermetic/assemble_test.dart | 2 - .../hermetic/build_darwin_framework_test.dart | 20 ++++---- .../hermetic/build_ios_test.dart | 24 +++++---- .../hermetic/build_ipa_test.dart | 16 +++--- .../hermetic/build_linux_test.dart | 14 +++--- .../hermetic/build_macos_test.dart | 14 +++--- .../commands.shard/hermetic/build_test.dart | 8 ++- 11 files changed, 86 insertions(+), 104 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/analyze_base.dart b/packages/flutter_tools/lib/src/commands/analyze_base.dart index 54a9ff6fe0..cdd21a7659 100644 --- a/packages/flutter_tools/lib/src/commands/analyze_base.dart +++ b/packages/flutter_tools/lib/src/commands/analyze_base.dart @@ -87,7 +87,7 @@ abstract class AnalyzeBase { return artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path; } bool get isBenchmarking => argResults['benchmark'] as bool; - String get protocolTrafficLog => argResults['protocol-traffic-log'] as String; + String? get protocolTrafficLog => argResults['protocol-traffic-log'] as String?; /// Generate an analysis summary for both [AnalyzeOnce], [AnalyzeContinuously]. static String generateErrorsMessage({ diff --git a/packages/flutter_tools/test/commands.shard/hermetic/analyze_continuously_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/analyze_continuously_test.dart index 0205a9a723..2322d70d26 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/analyze_continuously_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/analyze_continuously_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 'dart:async'; import 'package:fake_async/fake_async.dart'; @@ -32,13 +30,12 @@ void main() { Cache.flutterRoot = getFlutterRoot(); }); - AnalysisServer server; - Directory tempDir; - FileSystem fileSystem; - Platform platform; - ProcessManager processManager; - AnsiTerminal terminal; - Logger logger; + late Directory tempDir; + late FileSystem fileSystem; + late Platform platform; + late ProcessManager processManager; + late AnsiTerminal terminal; + late Logger logger; setUp(() { fileSystem = globals.localFileSystem; @@ -51,7 +48,6 @@ void main() { tearDown(() { tryToDelete(tempDir); - return server?.dispose(); }); @@ -88,11 +84,10 @@ void main() { await pub.get( context: PubContext.flutterTests, directory: tempDir.path, - generateSyntheticPackage: false, ); - server = AnalysisServer( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + final AnalysisServer server = AnalysisServer( + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, [tempDir.path], fileSystem: fileSystem, platform: platform, @@ -109,6 +104,8 @@ void main() { await onDone; expect(errorCount, 0); + + await server.dispose(); }); }); @@ -126,18 +123,17 @@ void main() { await pub.get( context: PubContext.flutterTests, directory: tempDir.path, - generateSyntheticPackage: false, ); - server = AnalysisServer( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, - [tempDir.path], - fileSystem: fileSystem, - platform: platform, - processManager: processManager, - logger: logger, - terminal: terminal, - ); + final AnalysisServer server = AnalysisServer( + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, + [tempDir.path], + fileSystem: fileSystem, + platform: platform, + processManager: processManager, + logger: logger, + terminal: terminal, + ); int errorCount = 0; final Future onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first; @@ -149,13 +145,15 @@ void main() { await onDone; expect(errorCount, greaterThan(0)); + + await server.dispose(); }); testUsingContext('Returns no errors when source is error-free', () async { const String contents = "StringBuffer bar = StringBuffer('baz');"; tempDir.childFile('main.dart').writeAsStringSync(contents); - server = AnalysisServer( - globals.artifacts.getHostArtifact(HostArtifact.engineDartSdkPath).path, + final AnalysisServer server = AnalysisServer( + globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path, [tempDir.path], fileSystem: fileSystem, platform: platform, @@ -172,6 +170,7 @@ void main() { await server.start(); await onDone; expect(errorCount, 0); + await server.dispose(); }); testUsingContext('Can run AnalysisService with customized cache location', () async { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/analyze_suggestion_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/analyze_suggestion_test.dart index 1411060073..172b0511f3 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/analyze_suggestion_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/analyze_suggestion_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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/artifacts.dart'; @@ -22,7 +20,7 @@ import '../../src/test_flutter_command_runner.dart'; class ProjectValidatorDummy extends ProjectValidator { @override - Future> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{ + Future> start(FlutterProject project, {Logger? logger, FileSystem? fileSystem}) async{ return [ const ProjectValidatorResult(name: 'pass', value: 'value', status: StatusProjectValidator.success), const ProjectValidatorResult(name: 'fail', value: 'my error', status: StatusProjectValidator.error), @@ -41,7 +39,7 @@ class ProjectValidatorDummy extends ProjectValidator { class ProjectValidatorSecondDummy extends ProjectValidator { @override - Future> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{ + Future> start(FlutterProject project, {Logger? logger, FileSystem? fileSystem}) async{ return [ const ProjectValidatorResult(name: 'second', value: 'pass', status: StatusProjectValidator.success), const ProjectValidatorResult(name: 'other fail', value: 'second fail', status: StatusProjectValidator.error), @@ -59,7 +57,7 @@ class ProjectValidatorSecondDummy extends ProjectValidator { class ProjectValidatorCrash extends ProjectValidator { @override - Future> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{ + Future> start(FlutterProject project, {Logger? logger, FileSystem? fileSystem}) async{ throw Exception('my exception'); } @@ -73,10 +71,10 @@ class ProjectValidatorCrash extends ProjectValidator { } void main() { - FileSystem fileSystem; - Terminal terminal; - ProcessManager processManager; - Platform platform; + late FileSystem fileSystem; + late Terminal terminal; + late ProcessManager processManager; + late Platform platform; group('analyze --suggestions command', () { diff --git a/packages/flutter_tools/test/commands.shard/hermetic/analyze_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/analyze_test.dart index b8424914fe..2dac6cf3be 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/analyze_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/analyze_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/command_runner.dart'; import 'package:file/file.dart'; import 'package:file/memory.dart'; @@ -46,13 +44,13 @@ void main() { }); group('analyze command', () { - FileSystem fileSystem; - Platform platform; - BufferLogger logger; - FakeProcessManager processManager; - Terminal terminal; - AnalyzeCommand command; - CommandRunner runner; + late FileSystem fileSystem; + late Platform platform; + late BufferLogger logger; + late FakeProcessManager processManager; + late Terminal terminal; + late AnalyzeCommand command; + late CommandRunner runner; setUpAll(() { Cache.disableLocking(); @@ -130,8 +128,8 @@ void main() { // Absolute paths expect(inRepo([tempDir.path], fileSystem), isFalse); expect(inRepo([fileSystem.path.join(tempDir.path, 'foo')], fileSystem), isFalse); - expect(inRepo([Cache.flutterRoot], fileSystem), isTrue); - expect(inRepo([fileSystem.path.join(Cache.flutterRoot, 'foo')], fileSystem), isTrue); + expect(inRepo([Cache.flutterRoot!], fileSystem), isTrue); + expect(inRepo([fileSystem.path.join(Cache.flutterRoot!, 'foo')], fileSystem), isTrue); // Relative paths fileSystem.currentDirectory = Cache.flutterRoot; @@ -158,6 +156,7 @@ void main() { 'startColumn': 4, }, 'message': 'Prefer final for variable declarations if they are not reassigned.', + 'code': 'var foo = 123;', 'hasFix': false, }; expect(WrittenError.fromJson(json).toString(), @@ -165,11 +164,11 @@ void main() { }); } -bool inRepo(List fileList, FileSystem fileSystem) { +bool inRepo(List? fileList, FileSystem fileSystem) { if (fileList == null || fileList.isEmpty) { fileList = [fileSystem.path.current]; } - final String root = fileSystem.path.normalize(fileSystem.path.absolute(Cache.flutterRoot)); + final String root = fileSystem.path.normalize(fileSystem.path.absolute(Cache.flutterRoot!)); final String prefix = root + fileSystem.path.separator; for (String file in fileList) { file = fileSystem.path.normalize(fileSystem.path.absolute(file)); diff --git a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart index beb713cde5..072015afb1 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/assemble_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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_darwin_framework_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_darwin_framework_test.dart index c104788886..b830640caf 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_darwin_framework_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_darwin_framework_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/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/platform.dart'; @@ -21,9 +19,9 @@ import '../../src/fakes.dart'; import '../../src/test_build_system.dart'; void main() { - MemoryFileSystem memoryFileSystem; - Directory outputDirectory; - FakePlatform fakePlatform; + late MemoryFileSystem memoryFileSystem; + late Directory outputDirectory; + late FakePlatform fakePlatform; setUpAll(() { Cache.disableLocking(); @@ -48,7 +46,7 @@ void main() { group('build ios-framework', () { group('podspec', () { const String engineRevision = '0123456789abcdef'; - Cache cache; + late Cache cache; setUp(() { final Directory rootOverride = memoryFileSystem.directory('cache'); @@ -181,7 +179,7 @@ void main() { }); group('not on master channel', () { - FakeFlutterVersion fakeFlutterVersion; + late FakeFlutterVersion fakeFlutterVersion; setUp(() { const GitTagVersion gitTagVersion = GitTagVersion( x: 1, @@ -277,7 +275,7 @@ void main() { group('build macos-framework', () { group('podspec', () { const String engineRevision = '0123456789abcdef'; - Cache cache; + late Cache cache; setUp(() { final Directory rootOverride = memoryFileSystem.directory('cache'); @@ -410,7 +408,7 @@ void main() { }); group('not on master channel', () { - FakeFlutterVersion fakeFlutterVersion; + late FakeFlutterVersion fakeFlutterVersion; setUp(() { const GitTagVersion gitTagVersion = GitTagVersion( x: 1, @@ -504,8 +502,8 @@ void main() { }); group('XCFrameworks', () { - MemoryFileSystem fileSystem; - FakeProcessManager fakeProcessManager; + late MemoryFileSystem fileSystem; + late FakeProcessManager fakeProcessManager; setUp(() { fileSystem = MemoryFileSystem.test(); diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart index d18c63bc22..a9dafa324d 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ios_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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -28,21 +26,21 @@ class FakeXcodeProjectInterpreterWithBuildSettings extends FakeXcodeProjectInter @override Future> getBuildSettings( String projectPath, { - XcodeProjectBuildContext buildContext, + XcodeProjectBuildContext? buildContext, Duration timeout = const Duration(minutes: 1), }) async { return { 'PRODUCT_BUNDLE_IDENTIFIER': productBundleIdentifier ?? 'io.flutter.someProject', 'TARGET_BUILD_DIR': 'build/ios/Release-iphoneos', 'WRAPPER_NAME': 'Runner.app', - if (developmentTeam != null) 'DEVELOPMENT_TEAM': developmentTeam, + if (developmentTeam != null) 'DEVELOPMENT_TEAM': developmentTeam!, }; } /// The value of 'PRODUCT_BUNDLE_IDENTIFIER'. - final String productBundleIdentifier; + final String? productBundleIdentifier; - final String developmentTeam; + final String? developmentTeam; } final Platform macosPlatform = FakePlatform( @@ -59,8 +57,8 @@ final Platform notMacosPlatform = FakePlatform( ); void main() { - FileSystem fileSystem; - TestUsage usage; + late FileSystem fileSystem; + late TestUsage usage; setUpAll(() { Cache.disableLocking(); @@ -90,7 +88,7 @@ void main() { 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/', ]); - FakeCommand setUpRsyncCommand({void Function() onRun}) { + FakeCommand setUpRsyncCommand({void Function()? onRun}) { return FakeCommand( command: const [ 'rsync', @@ -104,7 +102,7 @@ void main() { ); } - FakeCommand setUpXCResultCommand({String stdout = '', void Function() onRun}) { + FakeCommand setUpXCResultCommand({String stdout = '', void Function()? onRun}) { return FakeCommand( command: const [ 'xcrun', @@ -125,10 +123,10 @@ void main() { FakeCommand setUpFakeXcodeBuildHandler({ bool verbose = false, bool simulator = false, - String deviceId, + String? deviceId, int exitCode = 0, - String stdout, - void Function() onRun, + String? stdout, + void Function()? onRun, }) { return FakeCommand( command: [ diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart index 85630849f4..4599e7f55f 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_ipa_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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; @@ -28,7 +26,7 @@ class FakeXcodeProjectInterpreterWithBuildSettings extends FakeXcodeProjectInter @override Future> getBuildSettings( String projectPath, { - XcodeProjectBuildContext buildContext, + XcodeProjectBuildContext? buildContext, Duration timeout = const Duration(minutes: 1), }) async { return { @@ -53,9 +51,9 @@ final Platform notMacosPlatform = FakePlatform( ); void main() { - FileSystem fileSystem; - TestUsage usage; - FakeProcessManager fakeProcessManager; + late FileSystem fileSystem; + late TestUsage usage; + late FakeProcessManager fakeProcessManager; setUpAll(() { Cache.disableLocking(); @@ -86,7 +84,7 @@ void main() { 'xattr', '-r', '-d', 'com.apple.FinderInfo', '/', ]); - FakeCommand setUpXCResultCommand({String stdout = '', void Function() onRun}) { + FakeCommand setUpXCResultCommand({String stdout = '', void Function()? onRun}) { return FakeCommand( command: const [ 'xcrun', @@ -104,7 +102,7 @@ void main() { // Creates a FakeCommand for the xcodebuild call to build the app // in the given configuration. - FakeCommand setUpFakeXcodeBuildHandler({ bool verbose = false, int exitCode = 0, void Function() onRun }) { + FakeCommand setUpFakeXcodeBuildHandler({ bool verbose = false, int exitCode = 0, void Function()? onRun }) { return FakeCommand( command: [ 'xcrun', @@ -134,7 +132,7 @@ void main() { FakeCommand exportArchiveCommand({ String exportOptionsPlist = '/ExportOptions.plist', - File cachePlist, + File? cachePlist, }) { return FakeCommand( command: [ diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart index bf8d2db8f4..363dfcdf36 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_linux_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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; @@ -45,9 +43,9 @@ void main() { Cache.disableLocking(); }); - FileSystem fileSystem; - ProcessManager processManager; - TestUsage usage; + late FileSystem fileSystem; + late ProcessManager processManager; + late TestUsage usage; setUp(() { fileSystem = MemoryFileSystem.test(); @@ -71,7 +69,7 @@ void main() { // Returns the command matching the build_linux call to cmake. FakeCommand cmakeCommand(String buildMode, { String target = 'x64', - void Function() onRun, + void Function()? onRun, }) { return FakeCommand( command: [ @@ -89,9 +87,9 @@ void main() { // Returns the command matching the build_linux call to ninja. FakeCommand ninjaCommand(String buildMode, { - Map environment, + Map? environment, String target = 'x64', - void Function() onRun, + void Function()? onRun, String stdout = '', }) { return FakeCommand( diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart index 245ed862bd..acab399a12 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_macos_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_macos_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 'dart:async'; import 'package:args/command_runner.dart'; @@ -29,7 +27,7 @@ import '../../src/test_flutter_command_runner.dart'; class FakeXcodeProjectInterpreterWithProfile extends FakeXcodeProjectInterpreter { @override - Future getInfo(String projectPath, { String projectFilename }) async { + Future getInfo(String projectPath, { String? projectFilename }) async { return XcodeProjectInfo( ['Runner'], ['Debug', 'Profile', 'Release'], @@ -62,10 +60,10 @@ final Platform notMacosPlatform = FakePlatform( ); void main() { - FileSystem fileSystem; - TestUsage usage; - FakeProcessManager fakeProcessManager; - XcodeProjectInterpreter xcodeProjectInterpreter; + late FileSystem fileSystem; + late TestUsage usage; + late FakeProcessManager fakeProcessManager; + late XcodeProjectInterpreter xcodeProjectInterpreter; setUpAll(() { Cache.disableLocking(); @@ -93,7 +91,7 @@ void main() { // Creates a FakeCommand for the xcodebuild call to build the app // in the given configuration. - FakeCommand setUpFakeXcodeBuildHandler(String configuration, { bool verbose = false, void Function() onRun }) { + FakeCommand setUpFakeXcodeBuildHandler(String configuration, { bool verbose = false, void Function()? onRun }) { final FlutterProject flutterProject = FlutterProject.fromDirectory(fileSystem.currentDirectory); final Directory flutterBuildDir = fileSystem.directory(getMacOSBuildDirectory()); return FakeCommand( diff --git a/packages/flutter_tools/test/commands.shard/hermetic/build_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/build_test.dart index 57aba7ecd5..144ed0e109 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/build_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/build_test.dart @@ -2,14 +2,12 @@ // 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/command_runner.dart'; import 'package:file/memory.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/commands/build.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart'; -import 'package:meta/meta.dart'; import '../../src/common.dart'; import '../../src/context.dart'; @@ -27,8 +25,8 @@ void main() { 'combination with "--${FlutterOptions.kSplitDebugInfoOption}"')); }); group('Fatal Logs', () { - FakeBuildCommand command; - MemoryFileSystem fs; + late FakeBuildCommand command; + late MemoryFileSystem fs; setUp(() { fs = MemoryFileSystem.test(); @@ -134,7 +132,7 @@ class FakeBuildCommand extends BuildCommand { } class FakeBuildSubcommand extends BuildSubCommand { - FakeBuildSubcommand({@required bool verboseHelp}) : super(verboseHelp: verboseHelp); + FakeBuildSubcommand({required super.verboseHelp}); @override String get description => '';