mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix environment leakage in doctor_test (#54478)
This commit is contained in:
parent
d081364d3c
commit
2adb1fc095
@ -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(
|
||||
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)],
|
||||
<String>[genSnapshotPath],
|
||||
workingDirectory: anyNamed('workingDirectory'),
|
||||
environment: anyNamed('environment'),
|
||||
)).thenReturn(ProcessResult(101, 1, '', ''));
|
||||
@ -524,22 +535,26 @@ void main() {
|
||||
}
|
||||
}
|
||||
}, overrides: <Type, Generator>{
|
||||
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: <Type, Generator>{
|
||||
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(
|
||||
<String>[globals.artifacts.getArtifactPath(Artifact.genSnapshot)],
|
||||
<String>[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: <Type, Generator>{
|
||||
Artifacts: () => mockArtifacts,
|
||||
FileSystem: () => memoryFileSystem,
|
||||
OutputPreferences: () => OutputPreferences(wrapText: false),
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: _kNoColorOutputPlatform,
|
||||
@ -736,6 +753,7 @@ void main() {
|
||||
contains(isA<WebWorkflow>()));
|
||||
}, overrides: <Type, Generator>{
|
||||
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 {}
|
||||
|
Loading…
Reference in New Issue
Block a user