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
This commit is contained in:
Liam Appelbe 2022-09-06 11:21:23 -07:00 committed by GitHub
parent c0354999a7
commit 8da0432094
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 86 additions and 104 deletions

View file

@ -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({

View file

@ -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,
<String>[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,
<String>[tempDir.path],
fileSystem: fileSystem,
platform: platform,
processManager: processManager,
logger: logger,
terminal: terminal,
);
final AnalysisServer server = AnalysisServer(
globals.artifacts!.getHostArtifact(HostArtifact.engineDartSdkPath).path,
<String>[tempDir.path],
fileSystem: fileSystem,
platform: platform,
processManager: processManager,
logger: logger,
terminal: terminal,
);
int errorCount = 0;
final Future<bool> 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,
<String>[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 {

View file

@ -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<List<ProjectValidatorResult>> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{
Future<List<ProjectValidatorResult>> start(FlutterProject project, {Logger? logger, FileSystem? fileSystem}) async{
return <ProjectValidatorResult>[
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<List<ProjectValidatorResult>> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{
Future<List<ProjectValidatorResult>> start(FlutterProject project, {Logger? logger, FileSystem? fileSystem}) async{
return <ProjectValidatorResult>[
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<List<ProjectValidatorResult>> start(FlutterProject project, {Logger logger, FileSystem fileSystem}) async{
Future<List<ProjectValidatorResult>> 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', () {

View file

@ -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<void> runner;
late FileSystem fileSystem;
late Platform platform;
late BufferLogger logger;
late FakeProcessManager processManager;
late Terminal terminal;
late AnalyzeCommand command;
late CommandRunner<void> runner;
setUpAll(() {
Cache.disableLocking();
@ -130,8 +128,8 @@ void main() {
// Absolute paths
expect(inRepo(<String>[tempDir.path], fileSystem), isFalse);
expect(inRepo(<String>[fileSystem.path.join(tempDir.path, 'foo')], fileSystem), isFalse);
expect(inRepo(<String>[Cache.flutterRoot], fileSystem), isTrue);
expect(inRepo(<String>[fileSystem.path.join(Cache.flutterRoot, 'foo')], fileSystem), isTrue);
expect(inRepo(<String>[Cache.flutterRoot!], fileSystem), isTrue);
expect(inRepo(<String>[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<String> fileList, FileSystem fileSystem) {
bool inRepo(List<String>? fileList, FileSystem fileSystem) {
if (fileList == null || fileList.isEmpty) {
fileList = <String>[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));

View file

@ -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';

View file

@ -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();

View file

@ -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<Map<String, String>> getBuildSettings(
String projectPath, {
XcodeProjectBuildContext buildContext,
XcodeProjectBuildContext? buildContext,
Duration timeout = const Duration(minutes: 1),
}) async {
return <String, String>{
'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 <String>[
'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 <String>[
'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: <String>[

View file

@ -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<Map<String, String>> getBuildSettings(
String projectPath, {
XcodeProjectBuildContext buildContext,
XcodeProjectBuildContext? buildContext,
Duration timeout = const Duration(minutes: 1),
}) async {
return <String, String>{
@ -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 <String>[
'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: <String>[
'xcrun',
@ -134,7 +132,7 @@ void main() {
FakeCommand exportArchiveCommand({
String exportOptionsPlist = '/ExportOptions.plist',
File cachePlist,
File? cachePlist,
}) {
return FakeCommand(
command: <String>[

View file

@ -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: <String>[
@ -89,9 +87,9 @@ void main() {
// Returns the command matching the build_linux call to ninja.
FakeCommand ninjaCommand(String buildMode, {
Map<String, String> environment,
Map<String, String>? environment,
String target = 'x64',
void Function() onRun,
void Function()? onRun,
String stdout = '',
}) {
return FakeCommand(

View file

@ -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<XcodeProjectInfo> getInfo(String projectPath, { String projectFilename }) async {
Future<XcodeProjectInfo> getInfo(String projectPath, { String? projectFilename }) async {
return XcodeProjectInfo(
<String>['Runner'],
<String>['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(

View file

@ -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 => '';