forked from firka/flutter
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:
@@ -56,7 +56,8 @@ Future<T> runInContext<T>(
|
|||||||
Config: () => new Config(),
|
Config: () => new Config(),
|
||||||
DevFSConfig: () => new DevFSConfig(),
|
DevFSConfig: () => new DevFSConfig(),
|
||||||
DeviceManager: () => new DeviceManager(),
|
DeviceManager: () => new DeviceManager(),
|
||||||
Doctor: () => new Doctor(),
|
Doctor: () => const Doctor(),
|
||||||
|
DoctorValidatorsProvider: () => DoctorValidatorsProvider.defaultInstance,
|
||||||
Flags: () => const EmptyFlags(),
|
Flags: () => const EmptyFlags(),
|
||||||
FlutterVersion: () => new FlutterVersion(const Clock()),
|
FlutterVersion: () => new FlutterVersion(const Clock()),
|
||||||
GenSnapshot: () => const GenSnapshot(),
|
GenSnapshot: () => const GenSnapshot(),
|
||||||
|
|||||||
@@ -26,15 +26,19 @@ import 'vscode/vscode_validator.dart';
|
|||||||
|
|
||||||
Doctor get doctor => context[Doctor];
|
Doctor get doctor => context[Doctor];
|
||||||
|
|
||||||
class ValidatorTask {
|
abstract class DoctorValidatorsProvider {
|
||||||
ValidatorTask(this.validator, this.result);
|
/// The singleton instance, pulled from the [AppContext].
|
||||||
final DoctorValidator validator;
|
static DoctorValidatorsProvider get instance => context[DoctorValidatorsProvider];
|
||||||
final Future<ValidationResult> result;
|
|
||||||
|
static final DoctorValidatorsProvider defaultInstance = new _DefaultDoctorValidatorsProvider();
|
||||||
|
|
||||||
|
List<DoctorValidator> get validators;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Doctor {
|
class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||||
List<DoctorValidator> _validators;
|
List<DoctorValidator> _validators;
|
||||||
|
|
||||||
|
@override
|
||||||
List<DoctorValidator> get validators {
|
List<DoctorValidator> get validators {
|
||||||
if (_validators == null) {
|
if (_validators == null) {
|
||||||
_validators = <DoctorValidator>[];
|
_validators = <DoctorValidator>[];
|
||||||
@@ -60,6 +64,20 @@ class Doctor {
|
|||||||
}
|
}
|
||||||
return _validators;
|
return _validators;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ValidatorTask {
|
||||||
|
ValidatorTask(this.validator, this.result);
|
||||||
|
final DoctorValidator validator;
|
||||||
|
final Future<ValidationResult> result;
|
||||||
|
}
|
||||||
|
|
||||||
|
class Doctor {
|
||||||
|
const Doctor();
|
||||||
|
|
||||||
|
List<DoctorValidator> get validators {
|
||||||
|
return DoctorValidatorsProvider.instance.validators;
|
||||||
|
}
|
||||||
|
|
||||||
/// Return a list of [ValidatorTask] objects and starts validation on all
|
/// Return a list of [ValidatorTask] objects and starts validation on all
|
||||||
/// objects in [validators].
|
/// objects in [validators].
|
||||||
|
|||||||
@@ -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 {
|
testUsingContext('validate non-verbose output format for run without issues', () async {
|
||||||
expect(await new FakeQuietDoctor().diagnose(verbose: false), isTrue);
|
expect(await new FakeQuietDoctor().diagnose(verbose: false), isTrue);
|
||||||
expect(testLogger.statusText, equals(
|
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 {
|
class VsCodeValidatorTestTargets extends VsCodeValidator {
|
||||||
static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application');
|
static final String validInstall = fs.path.join('test', 'data', 'vscode', 'application');
|
||||||
static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions');
|
static final String validExtensions = fs.path.join('test', 'data', 'vscode', 'extensions');
|
||||||
|
|||||||
Reference in New Issue
Block a user