Skip to content

Commit 2adb1fc

Browse files
Fix environment leakage in doctor_test (flutter#54478)
1 parent d081364 commit 2adb1fc

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,16 @@ void main() {
365365
});
366366

367367
group('doctor with fake validators', () {
368+
MockArtifacts mockArtifacts;
369+
const String genSnapshotPath = '/path/to/gen_snapshot';
370+
FileSystem memoryFileSystem;
371+
372+
setUp(() {
373+
memoryFileSystem = MemoryFileSystem.test();
374+
mockArtifacts = MockArtifacts();
375+
when(mockArtifacts.getArtifactPath(Artifact.genSnapshot)).thenReturn(genSnapshotPath);
376+
});
377+
368378
testUsingContext('validate non-verbose output format for run without issues', () async {
369379
expect(await FakeQuietDoctor().diagnose(verbose: false), isTrue);
370380
expect(testLogger.statusText, equals(
@@ -507,8 +517,9 @@ void main() {
507517
}, overrides: noColorTerminalOverride);
508518

509519
testUsingContext('gen_snapshot does not work', () async {
520+
memoryFileSystem.file(genSnapshotPath).createSync(recursive: true);
510521
when(mockProcessManager.runSync(
511-
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)],
522+
<String>[genSnapshotPath],
512523
workingDirectory: anyNamed('workingDirectory'),
513524
environment: anyNamed('environment'),
514525
)).thenReturn(ProcessResult(101, 1, '', ''));
@@ -524,30 +535,34 @@ void main() {
524535
}
525536
}
526537
}, overrides: <Type, Generator>{
538+
Artifacts: () => mockArtifacts,
539+
FileSystem: () => memoryFileSystem,
527540
OutputPreferences: () => OutputPreferences(wrapText: false),
528541
ProcessManager: () => mockProcessManager,
529542
Platform: _kNoColorOutputPlatform,
530543
});
531544

532545
testUsingContext('gen_snapshot binary not available', () async {
533-
expect(await FlutterValidatorDoctor().diagnose(verbose: false), isTrue);
534-
// gen_snapshot is downloaded on demand, and the doctor should not
535-
// fail if the gen_snapshot binary is not present.
536-
expect(testLogger.statusText, contains('No issues found!'));
546+
expect(await FlutterValidatorDoctor().diagnose(verbose: false), isTrue);
547+
// gen_snapshot is downloaded on demand, and the doctor should not
548+
// fail if the gen_snapshot binary is not present.
549+
expect(testLogger.statusText, contains('No issues found!'));
537550
}, overrides: <Type, Generator>{
551+
Artifacts: () => mockArtifacts,
538552
FileSystem: () => MemoryFileSystem(),
539553
ProcessManager: () => FakeProcessManager.any(),
540554
});
541555

542556
testUsingContext('version checking does not work', () async {
557+
memoryFileSystem.file(genSnapshotPath).createSync(recursive: true);
543558
final VersionCheckError versionCheckError = VersionCheckError('version error');
544559

545560
when(mockFlutterVersion.channel).thenReturn('unknown');
546561
when(mockFlutterVersion.frameworkVersion).thenReturn('0.0.0');
547562
when(mockFlutterVersion.frameworkDate).thenThrow(versionCheckError);
548563

549564
when(mockProcessManager.runSync(
550-
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)],
565+
<String>[genSnapshotPath],
551566
workingDirectory: anyNamed('workingDirectory'),
552567
environment: anyNamed('environment'),
553568
)).thenReturn(ProcessResult(101, 255, '', ''));
@@ -561,6 +576,8 @@ void main() {
561576
'! Doctor found issues in 1 category.\n'
562577
));
563578
}, overrides: <Type, Generator>{
579+
Artifacts: () => mockArtifacts,
580+
FileSystem: () => memoryFileSystem,
564581
OutputPreferences: () => OutputPreferences(wrapText: false),
565582
ProcessManager: () => mockProcessManager,
566583
Platform: _kNoColorOutputPlatform,
@@ -736,6 +753,7 @@ void main() {
736753
contains(isA<WebWorkflow>()));
737754
}, overrides: <Type, Generator>{
738755
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
756+
FileSystem: () => MemoryFileSystem.test(),
739757
ProcessManager: () => MockProcessManager(),
740758
});
741759

@@ -1122,3 +1140,4 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
11221140
}
11231141

11241142
class MockProcessManager extends Mock implements ProcessManager {}
1143+
class MockArtifacts extends Mock implements Artifacts {}

0 commit comments

Comments
 (0)