diff --git a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart index b2a58a567e3..2c0472edb57 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart @@ -365,6 +365,16 @@ void main() { }); group('doctor with fake validators', () { + MockArtifacts mockArtifacts; + const String genSnapshotPath = '/path/to/gen_snapshot'; + FileSystem memoryFileSystem; + + setUp(() { + memoryFileSystem = MemoryFileSystem.test(); + mockArtifacts = MockArtifacts(); + when(mockArtifacts.getArtifactPath(Artifact.genSnapshot)).thenReturn(genSnapshotPath); + }); + testUsingContext('validate non-verbose output format for run without issues', () async { expect(await FakeQuietDoctor().diagnose(verbose: false), isTrue); expect(testLogger.statusText, equals( @@ -507,8 +517,9 @@ void main() { }, overrides: noColorTerminalOverride); testUsingContext('gen_snapshot does not work', () async { + memoryFileSystem.file(genSnapshotPath).createSync(recursive: true); when(mockProcessManager.runSync( - [globals.artifacts.getArtifactPath(Artifact.genSnapshot)], + [genSnapshotPath], workingDirectory: anyNamed('workingDirectory'), environment: anyNamed('environment'), )).thenReturn(ProcessResult(101, 1, '', '')); @@ -524,22 +535,26 @@ void main() { } } }, overrides: { + Artifacts: () => mockArtifacts, + FileSystem: () => memoryFileSystem, OutputPreferences: () => OutputPreferences(wrapText: false), ProcessManager: () => mockProcessManager, Platform: _kNoColorOutputPlatform, }); testUsingContext('gen_snapshot binary not available', () async { - expect(await FlutterValidatorDoctor().diagnose(verbose: false), isTrue); - // gen_snapshot is downloaded on demand, and the doctor should not - // fail if the gen_snapshot binary is not present. - expect(testLogger.statusText, contains('No issues found!')); + expect(await FlutterValidatorDoctor().diagnose(verbose: false), isTrue); + // gen_snapshot is downloaded on demand, and the doctor should not + // fail if the gen_snapshot binary is not present. + expect(testLogger.statusText, contains('No issues found!')); }, overrides: { + Artifacts: () => mockArtifacts, FileSystem: () => MemoryFileSystem(), ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('version checking does not work', () async { + memoryFileSystem.file(genSnapshotPath).createSync(recursive: true); final VersionCheckError versionCheckError = VersionCheckError('version error'); when(mockFlutterVersion.channel).thenReturn('unknown'); @@ -547,7 +562,7 @@ void main() { when(mockFlutterVersion.frameworkDate).thenThrow(versionCheckError); when(mockProcessManager.runSync( - [globals.artifacts.getArtifactPath(Artifact.genSnapshot)], + [genSnapshotPath], workingDirectory: anyNamed('workingDirectory'), environment: anyNamed('environment'), )).thenReturn(ProcessResult(101, 255, '', '')); @@ -561,6 +576,8 @@ void main() { '! Doctor found issues in 1 category.\n' )); }, overrides: { + Artifacts: () => mockArtifacts, + FileSystem: () => memoryFileSystem, OutputPreferences: () => OutputPreferences(wrapText: false), ProcessManager: () => mockProcessManager, Platform: _kNoColorOutputPlatform, @@ -736,6 +753,7 @@ void main() { contains(isA())); }, overrides: { FeatureFlags: () => TestFeatureFlags(isWebEnabled: true), + FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => MockProcessManager(), }); @@ -1122,3 +1140,4 @@ class VsCodeValidatorTestTargets extends VsCodeValidator { } class MockProcessManager extends Mock implements ProcessManager {} +class MockArtifacts extends Mock implements Artifacts {}