Introduce DoctorValidatorsProvider to improve extensibility of flutter_tools (#16918)

DoctorValidatorsProvider is injected into Doctor to allow
overriding of DoctorValidators without needing to override
the whole Doctor instance.
This commit is contained in:
josephmr
2018-04-24 22:01:53 -04:00
committed by Todd Volkert
parent a7d7652a5f
commit 7f9bf5ade9
3 changed files with 56 additions and 7 deletions

View File

@@ -82,7 +82,24 @@ void main() {
});
});
group('doctor with fake validators', () {
group('doctor with overriden validators', () {
testUsingContext('validate non-verbose output format for run without issues', () async {
expect(await doctor.diagnose(verbose: false), isTrue);
expect(testLogger.statusText, equals(
'Doctor summary (to see all details, run flutter doctor -v):\n'
'[✓] Passing Validator (with statusInfo)\n'
'[✓] Another Passing Validator (with statusInfo)\n'
'[✓] Providing validators is fun (with statusInfo)\n'
'\n'
'• No issues found!\n'
));
}, overrides: <Type, Generator>{
DoctorValidatorsProvider: () => new FakeDoctorValidatorsProvider()
});
});
group('doctor with fake validators', () {
testUsingContext('validate non-verbose output format for run without issues', () async {
expect(await new FakeQuietDoctor().diagnose(verbose: false), isTrue);
expect(testLogger.statusText, equals(
@@ -291,6 +308,19 @@ class FakeQuietDoctor extends Doctor {
}
}
/// A DoctorValidatorsProvider that overrides the default validators without
/// overriding the doctor.
class FakeDoctorValidatorsProvider implements DoctorValidatorsProvider {
@override
List<DoctorValidator> get validators {
return <DoctorValidator>[
new PassingValidator('Passing Validator'),
new PassingValidator('Another Passing Validator'),
new PassingValidator('Providing validators is fun')
];
}
}
class VsCodeValidatorTestTargets extends VsCodeValidator {
static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application');
static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions');