[ flutter_tool ] Fix flakiness in doctor_test.dart (#161917)
This test was merging two ZeroExecutionTimeValidationResults into a new ValidationResult with an actual execution duration set rather than Duration.zero. Fixes https://github.com/flutter/flutter/issues/161918
This commit is contained in:
@@ -63,11 +63,9 @@ abstract class DoctorValidatorsProvider {
|
||||
}
|
||||
|
||||
/// The singleton instance, pulled from the [AppContext].
|
||||
static DoctorValidatorsProvider get _instance =>
|
||||
context.get<DoctorValidatorsProvider>()!;
|
||||
static DoctorValidatorsProvider get _instance => context.get<DoctorValidatorsProvider>()!;
|
||||
|
||||
static final DoctorValidatorsProvider defaultInstance =
|
||||
_DefaultDoctorValidatorsProvider(
|
||||
static final DoctorValidatorsProvider defaultInstance = _DefaultDoctorValidatorsProvider(
|
||||
logger: globals.logger,
|
||||
platform: globals.platform,
|
||||
featureFlags: featureFlags,
|
||||
@@ -95,8 +93,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
featureFlags: featureFlags,
|
||||
);
|
||||
|
||||
late final WebWorkflow webWorkflow =
|
||||
WebWorkflow(platform: platform, featureFlags: featureFlags);
|
||||
late final WebWorkflow webWorkflow = WebWorkflow(platform: platform, featureFlags: featureFlags);
|
||||
|
||||
late final MacOSWorkflow macOSWorkflow = MacOSWorkflow(
|
||||
platform: platform,
|
||||
@@ -129,16 +126,15 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
processManager: globals.processManager,
|
||||
logger: _logger,
|
||||
),
|
||||
...VsCodeValidator.installedValidators(
|
||||
globals.fs, platform, globals.processManager),
|
||||
...VsCodeValidator.installedValidators(globals.fs, platform, globals.processManager),
|
||||
];
|
||||
final ProxyValidator proxyValidator = ProxyValidator(platform: platform);
|
||||
_validators = <DoctorValidator>[
|
||||
FlutterValidator(
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
flutterVersion: () => globals.flutterVersion
|
||||
.fetchTagsAndGetVersion(clock: globals.systemClock),
|
||||
flutterVersion:
|
||||
() => globals.flutterVersion.fetchTagsAndGetVersion(clock: globals.systemClock),
|
||||
devToolsVersion: () => globals.cache.devToolsVersion,
|
||||
processManager: globals.processManager,
|
||||
userMessages: globals.userMessages,
|
||||
@@ -156,10 +152,8 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
),
|
||||
),
|
||||
if (androidWorkflow!.appliesToHostPlatform)
|
||||
GroupedValidator(
|
||||
<DoctorValidator>[androidValidator!, androidLicenseValidator!]),
|
||||
if (globals.iosWorkflow!.appliesToHostPlatform ||
|
||||
macOSWorkflow.appliesToHostPlatform)
|
||||
GroupedValidator(<DoctorValidator>[androidValidator!, androidLicenseValidator!]),
|
||||
if (globals.iosWorkflow!.appliesToHostPlatform || macOSWorkflow.appliesToHostPlatform)
|
||||
GroupedValidator(<DoctorValidator>[
|
||||
XcodeValidator(
|
||||
xcode: globals.xcode!,
|
||||
@@ -189,9 +183,7 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
if (ideValidators.isNotEmpty) ...ideValidators else NoIdeValidator(),
|
||||
if (proxyValidator.shouldShow) proxyValidator,
|
||||
if (globals.deviceManager?.canListAnything ?? false)
|
||||
DeviceValidator(
|
||||
deviceManager: globals.deviceManager,
|
||||
userMessages: globals.userMessages),
|
||||
DeviceValidator(deviceManager: globals.deviceManager, userMessages: globals.userMessages),
|
||||
HttpHostValidator(
|
||||
platform: globals.platform,
|
||||
featureFlags: featureFlags,
|
||||
@@ -216,13 +208,10 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
}
|
||||
|
||||
class Doctor {
|
||||
Doctor(
|
||||
{required Logger logger,
|
||||
required SystemClock clock,
|
||||
Analytics? analytics})
|
||||
: _logger = logger,
|
||||
_clock = clock,
|
||||
_analytics = analytics ?? globals.analytics;
|
||||
Doctor({required Logger logger, required SystemClock clock, Analytics? analytics})
|
||||
: _logger = logger,
|
||||
_clock = clock,
|
||||
_analytics = analytics ?? globals.analytics;
|
||||
|
||||
final Logger _logger;
|
||||
final SystemClock _clock;
|
||||
@@ -235,41 +224,39 @@ class Doctor {
|
||||
/// Return a list of [ValidatorTask] objects and starts validation on all
|
||||
/// objects in [validators].
|
||||
List<ValidatorTask> startValidatorTasks() => <ValidatorTask>[
|
||||
for (final DoctorValidator validator in validators)
|
||||
ValidatorTask(
|
||||
validator,
|
||||
// We use an asyncGuard() here to be absolutely certain that
|
||||
// DoctorValidators do not result in an uncaught exception. Since the
|
||||
// Future returned by the asyncGuard() is not awaited, we pass an
|
||||
// onError callback to it and translate errors into ValidationResults.
|
||||
asyncGuard<ValidationResult>(
|
||||
() {
|
||||
final Completer<ValidationResult> timeoutCompleter =
|
||||
Completer<ValidationResult>();
|
||||
final Timer timer = Timer(doctorDuration, () {
|
||||
timeoutCompleter.completeError(
|
||||
Exception(
|
||||
'${validator.title} exceeded maximum allowed duration of $doctorDuration',
|
||||
),
|
||||
);
|
||||
});
|
||||
final Future<ValidationResult> validatorFuture =
|
||||
validator.validate();
|
||||
return Future.any<ValidationResult>(<Future<ValidationResult>>[
|
||||
validatorFuture,
|
||||
// This future can only complete with an error
|
||||
timeoutCompleter.future,
|
||||
]).then((ValidationResult result) async {
|
||||
timer.cancel();
|
||||
return result;
|
||||
});
|
||||
},
|
||||
onError: (Object exception, StackTrace stackTrace) {
|
||||
return ValidationResult.crash(exception, stackTrace);
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
for (final DoctorValidator validator in validators)
|
||||
ValidatorTask(
|
||||
validator,
|
||||
// We use an asyncGuard() here to be absolutely certain that
|
||||
// DoctorValidators do not result in an uncaught exception. Since the
|
||||
// Future returned by the asyncGuard() is not awaited, we pass an
|
||||
// onError callback to it and translate errors into ValidationResults.
|
||||
asyncGuard<ValidationResult>(
|
||||
() {
|
||||
final Completer<ValidationResult> timeoutCompleter = Completer<ValidationResult>();
|
||||
final Timer timer = Timer(doctorDuration, () {
|
||||
timeoutCompleter.completeError(
|
||||
Exception(
|
||||
'${validator.title} exceeded maximum allowed duration of $doctorDuration',
|
||||
),
|
||||
);
|
||||
});
|
||||
final Future<ValidationResult> validatorFuture = validator.validate();
|
||||
return Future.any<ValidationResult>(<Future<ValidationResult>>[
|
||||
validatorFuture,
|
||||
// This future can only complete with an error
|
||||
timeoutCompleter.future,
|
||||
]).then((ValidationResult result) async {
|
||||
timer.cancel();
|
||||
return result;
|
||||
});
|
||||
},
|
||||
onError: (Object exception, StackTrace stackTrace) {
|
||||
return ValidationResult.crash(exception, stackTrace);
|
||||
},
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
List<Workflow> get workflows {
|
||||
return DoctorValidatorsProvider._instance.workflows;
|
||||
@@ -290,8 +277,7 @@ class Doctor {
|
||||
final StringBuffer lineBuffer = StringBuffer();
|
||||
ValidationResult result;
|
||||
try {
|
||||
result =
|
||||
await asyncGuard<ValidationResult>(() => validator.validateImpl());
|
||||
result = await asyncGuard<ValidationResult>(() => validator.validateImpl());
|
||||
} on Exception catch (exception) {
|
||||
// We're generating a summary, so drop the stack trace.
|
||||
result = ValidationResult.crash(exception);
|
||||
@@ -304,8 +290,7 @@ class Doctor {
|
||||
case ValidationType.missing:
|
||||
lineBuffer.write('is not installed.');
|
||||
case ValidationType.partial:
|
||||
lineBuffer
|
||||
.write('is partially installed; more components are available.');
|
||||
lineBuffer.write('is partially installed; more components are available.');
|
||||
case ValidationType.notAvailable:
|
||||
lineBuffer.write('is not available.');
|
||||
case ValidationType.success:
|
||||
@@ -333,8 +318,7 @@ class Doctor {
|
||||
|
||||
if (sawACrash) {
|
||||
buffer.writeln();
|
||||
buffer.writeln(
|
||||
'Run "flutter doctor" for information about why a doctor check crashed.');
|
||||
buffer.writeln('Run "flutter doctor" for information about why a doctor check crashed.');
|
||||
}
|
||||
|
||||
if (missingComponent) {
|
||||
@@ -348,8 +332,7 @@ class Doctor {
|
||||
}
|
||||
|
||||
Future<bool> checkRemoteArtifacts(String engineRevision) async {
|
||||
return globals.cache
|
||||
.areRemoteArtifactsAvailable(engineVersion: engineRevision);
|
||||
return globals.cache.areRemoteArtifactsAvailable(engineVersion: engineRevision);
|
||||
}
|
||||
|
||||
/// Maximum allowed duration for an entire validator to take.
|
||||
@@ -377,8 +360,7 @@ class Doctor {
|
||||
}
|
||||
|
||||
if (!verbose) {
|
||||
_logger.printStatus(
|
||||
'Doctor summary (to see all details, run flutter doctor -v):');
|
||||
_logger.printStatus('Doctor summary (to see all details, run flutter doctor -v):');
|
||||
}
|
||||
bool doctorResult = true;
|
||||
int issues = 0;
|
||||
@@ -387,8 +369,7 @@ class Doctor {
|
||||
// were sent for each doctor validator and its result
|
||||
final int analyticsTimestamp = _clock.now().millisecondsSinceEpoch;
|
||||
|
||||
for (final ValidatorTask validatorTask
|
||||
in startedValidatorTasks ?? startValidatorTasks()) {
|
||||
for (final ValidatorTask validatorTask in startedValidatorTasks ?? startValidatorTasks()) {
|
||||
final DoctorValidator validator = validatorTask.validator;
|
||||
final Status status = _logger.startSpinner(
|
||||
timeout: validator.slowWarningDuration,
|
||||
@@ -461,36 +442,36 @@ class Doctor {
|
||||
if (!verbose || executionTime == null) {
|
||||
return '';
|
||||
}
|
||||
final String formatted = executionTime.inSeconds < 2
|
||||
? getElapsedAsMilliseconds(executionTime)
|
||||
: getElapsedAsSeconds(executionTime);
|
||||
final String formatted =
|
||||
executionTime.inSeconds < 2
|
||||
? getElapsedAsMilliseconds(executionTime)
|
||||
: getElapsedAsSeconds(executionTime);
|
||||
return ' [$formatted]';
|
||||
}();
|
||||
|
||||
final String leadingBox =
|
||||
showColor ? result.coloredLeadingBox : result.leadingBox;
|
||||
final String leadingBox = showColor ? result.coloredLeadingBox : result.leadingBox;
|
||||
if (result.statusInfo != null) {
|
||||
_logger.printStatus(
|
||||
'$leadingBox ${validator.title} (${result.statusInfo})$executionDuration',
|
||||
hangingIndent: result.leadingBox.length + 1);
|
||||
'$leadingBox ${validator.title} (${result.statusInfo})$executionDuration',
|
||||
hangingIndent: result.leadingBox.length + 1,
|
||||
);
|
||||
} else {
|
||||
_logger.printStatus('$leadingBox ${validator.title}$executionDuration',
|
||||
hangingIndent: result.leadingBox.length + 1);
|
||||
_logger.printStatus(
|
||||
'$leadingBox ${validator.title}$executionDuration',
|
||||
hangingIndent: result.leadingBox.length + 1,
|
||||
);
|
||||
}
|
||||
|
||||
for (final ValidationMessage message in result.messages) {
|
||||
if (!message.isInformation || verbose) {
|
||||
int hangingIndent = 2;
|
||||
int indent = 4;
|
||||
final String indicator =
|
||||
showColor ? message.coloredIndicator : message.indicator;
|
||||
final String indicator = showColor ? message.coloredIndicator : message.indicator;
|
||||
for (final String line
|
||||
in '$indicator ${showPii ? message.message : message.piiStrippedMessage}'
|
||||
.split(
|
||||
'\n',
|
||||
)) {
|
||||
_logger.printStatus(line,
|
||||
hangingIndent: hangingIndent, indent: indent, emphasis: true);
|
||||
in '$indicator ${showPii ? message.message : message.piiStrippedMessage}'.split(
|
||||
'\n',
|
||||
)) {
|
||||
_logger.printStatus(line, hangingIndent: hangingIndent, indent: indent, emphasis: true);
|
||||
// Only do hanging indent for the first line.
|
||||
hangingIndent = 0;
|
||||
indent = 6;
|
||||
@@ -532,8 +513,7 @@ class Doctor {
|
||||
return doctorResult;
|
||||
}
|
||||
|
||||
bool get canListAnything =>
|
||||
workflows.any((Workflow workflow) => workflow.canListDevices);
|
||||
bool get canListAnything => workflows.any((Workflow workflow) => workflow.canListDevices);
|
||||
|
||||
bool get canLaunchAnything {
|
||||
if (FlutterTesterDevices.showFlutterTesterDevice) {
|
||||
@@ -559,16 +539,16 @@ class FlutterValidator extends DoctorValidator {
|
||||
required ProcessManager processManager,
|
||||
required String Function() flutterRoot,
|
||||
required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _flutterVersion = flutterVersion,
|
||||
_devToolsVersion = devToolsVersion,
|
||||
_platform = platform,
|
||||
_userMessages = userMessages,
|
||||
_fileSystem = fileSystem,
|
||||
_artifacts = artifacts,
|
||||
_processManager = processManager,
|
||||
_flutterRoot = flutterRoot,
|
||||
_operatingSystemUtils = operatingSystemUtils,
|
||||
super('Flutter');
|
||||
}) : _flutterVersion = flutterVersion,
|
||||
_devToolsVersion = devToolsVersion,
|
||||
_platform = platform,
|
||||
_userMessages = userMessages,
|
||||
_fileSystem = fileSystem,
|
||||
_artifacts = artifacts,
|
||||
_processManager = processManager,
|
||||
_flutterRoot = flutterRoot,
|
||||
_operatingSystemUtils = operatingSystemUtils,
|
||||
super('Flutter');
|
||||
|
||||
final Platform _platform;
|
||||
final FlutterVersion Function() _flutterVersion;
|
||||
@@ -593,8 +573,7 @@ class FlutterValidator extends DoctorValidator {
|
||||
frameworkVersion = version.frameworkVersion;
|
||||
|
||||
final String flutterRoot = _flutterRoot();
|
||||
messages.add(_getFlutterVersionMessage(
|
||||
frameworkVersion, versionChannel, flutterRoot));
|
||||
messages.add(_getFlutterVersionMessage(frameworkVersion, versionChannel, flutterRoot));
|
||||
|
||||
_validateRequiredBinaries(flutterRoot).forEach(messages.add);
|
||||
messages.add(_getFlutterUpstreamMessage(version));
|
||||
@@ -610,21 +589,16 @@ class FlutterValidator extends DoctorValidator {
|
||||
),
|
||||
),
|
||||
);
|
||||
messages.add(ValidationMessage(
|
||||
_userMessages.engineRevision(version.engineRevisionShort)));
|
||||
messages.add(ValidationMessage(
|
||||
_userMessages.dartRevision(version.dartSdkVersion)));
|
||||
messages.add(
|
||||
ValidationMessage(_userMessages.devToolsVersion(_devToolsVersion())));
|
||||
messages.add(ValidationMessage(_userMessages.engineRevision(version.engineRevisionShort)));
|
||||
messages.add(ValidationMessage(_userMessages.dartRevision(version.dartSdkVersion)));
|
||||
messages.add(ValidationMessage(_userMessages.devToolsVersion(_devToolsVersion())));
|
||||
final String? pubUrl = _platform.environment[kPubDevOverride];
|
||||
if (pubUrl != null) {
|
||||
messages.add(ValidationMessage(_userMessages.pubMirrorURL(pubUrl)));
|
||||
}
|
||||
final String? storageBaseUrl =
|
||||
_platform.environment[kFlutterStorageBaseUrl];
|
||||
final String? storageBaseUrl = _platform.environment[kFlutterStorageBaseUrl];
|
||||
if (storageBaseUrl != null) {
|
||||
messages.add(
|
||||
ValidationMessage(_userMessages.flutterMirrorURL(storageBaseUrl)));
|
||||
messages.add(ValidationMessage(_userMessages.flutterMirrorURL(storageBaseUrl)));
|
||||
}
|
||||
} on VersionCheckError catch (e) {
|
||||
messages.add(ValidationMessage.error(e.message));
|
||||
@@ -633,10 +607,8 @@ class FlutterValidator extends DoctorValidator {
|
||||
// Check that the binaries we downloaded for this platform actually run on it.
|
||||
// If the binaries are not downloaded (because android is not enabled), then do
|
||||
// not run this check.
|
||||
final String genSnapshotPath =
|
||||
_artifacts.getArtifactPath(Artifact.genSnapshot);
|
||||
if (_fileSystem.file(genSnapshotPath).existsSync() &&
|
||||
!_genSnapshotRuns(genSnapshotPath)) {
|
||||
final String genSnapshotPath = _artifacts.getArtifactPath(Artifact.genSnapshot);
|
||||
if (_fileSystem.file(genSnapshotPath).existsSync() && !_genSnapshotRuns(genSnapshotPath)) {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
buffer.writeln(_userMessages.flutterBinariesDoNotRun);
|
||||
if (_platform.isLinux) {
|
||||
@@ -646,8 +618,7 @@ class FlutterValidator extends DoctorValidator {
|
||||
buffer.writeln(
|
||||
'Flutter requires the Rosetta translation environment on ARM Macs. Try running:',
|
||||
);
|
||||
buffer.writeln(
|
||||
' sudo softwareupdate --install-rosetta --agree-to-license');
|
||||
buffer.writeln(' sudo softwareupdate --install-rosetta --agree-to-license');
|
||||
}
|
||||
messages.add(ValidationMessage.error(buffer.toString()));
|
||||
}
|
||||
@@ -660,8 +631,7 @@ class FlutterValidator extends DoctorValidator {
|
||||
// in that case, make it clear that it is fine to continue, but freshness check/upgrades
|
||||
// won't be supported.
|
||||
valid = ValidationType.partial;
|
||||
messages.add(
|
||||
ValidationMessage(_userMessages.flutterValidatorErrorIntentional));
|
||||
messages.add(ValidationMessage(_userMessages.flutterValidatorErrorIntentional));
|
||||
}
|
||||
|
||||
return ValidationResult(
|
||||
@@ -695,21 +665,17 @@ class FlutterValidator extends DoctorValidator {
|
||||
return ValidationMessage(flutterVersionMessage);
|
||||
}
|
||||
if (versionChannel == kUserBranch) {
|
||||
flutterVersionMessage =
|
||||
'$flutterVersionMessage\n${_userMessages.flutterUnknownChannel}';
|
||||
flutterVersionMessage = '$flutterVersionMessage\n${_userMessages.flutterUnknownChannel}';
|
||||
}
|
||||
if (frameworkVersion == '0.0.0-unknown') {
|
||||
flutterVersionMessage =
|
||||
'$flutterVersionMessage\n${_userMessages.flutterUnknownVersion}';
|
||||
flutterVersionMessage = '$flutterVersionMessage\n${_userMessages.flutterUnknownVersion}';
|
||||
}
|
||||
return ValidationMessage.hint(flutterVersionMessage);
|
||||
}
|
||||
|
||||
List<ValidationMessage> _validateRequiredBinaries(String flutterRoot) {
|
||||
final ValidationMessage? flutterWarning =
|
||||
_validateSdkBinary('flutter', flutterRoot);
|
||||
final ValidationMessage? dartWarning =
|
||||
_validateSdkBinary('dart', flutterRoot);
|
||||
final ValidationMessage? flutterWarning = _validateSdkBinary('flutter', flutterRoot);
|
||||
final ValidationMessage? dartWarning = _validateSdkBinary('dart', flutterRoot);
|
||||
return <ValidationMessage>[
|
||||
if (flutterWarning != null) flutterWarning,
|
||||
if (dartWarning != null) dartWarning,
|
||||
@@ -730,7 +696,8 @@ class FlutterValidator extends DoctorValidator {
|
||||
}
|
||||
final String resolvedFlutterPath = flutterBin.resolveSymbolicLinksSync();
|
||||
if (!_filePathContainsDirPath(flutterRoot, resolvedFlutterPath)) {
|
||||
final String hint = 'Warning: `$binary` on your path resolves to '
|
||||
final String hint =
|
||||
'Warning: `$binary` on your path resolves to '
|
||||
'$resolvedFlutterPath, which is not inside your current Flutter '
|
||||
'SDK checkout at $flutterRoot. Consider adding $flutterBinDir to '
|
||||
'the front of your path.';
|
||||
@@ -742,8 +709,9 @@ class FlutterValidator extends DoctorValidator {
|
||||
bool _filePathContainsDirPath(String directory, String file) {
|
||||
// calling .canonicalize() will normalize for alphabetic case and path
|
||||
// separators
|
||||
return _fileSystem.path.canonicalize(file).startsWith(
|
||||
_fileSystem.path.canonicalize(directory) + _fileSystem.path.separator);
|
||||
return _fileSystem.path
|
||||
.canonicalize(file)
|
||||
.startsWith(_fileSystem.path.canonicalize(directory) + _fileSystem.path.separator);
|
||||
}
|
||||
|
||||
ValidationMessage _getFlutterUpstreamMessage(FlutterVersion version) {
|
||||
@@ -754,14 +722,11 @@ class FlutterValidator extends DoctorValidator {
|
||||
// VersionUpstreamValidator can produce an error if repositoryUrl is null
|
||||
if (upstreamValidationError != null) {
|
||||
final String errorMessage = upstreamValidationError.message;
|
||||
if (errorMessage.contains(
|
||||
'could not determine the remote upstream which is being tracked')) {
|
||||
return ValidationMessage.hint(
|
||||
_userMessages.flutterUpstreamRepositoryUnknown);
|
||||
if (errorMessage.contains('could not determine the remote upstream which is being tracked')) {
|
||||
return ValidationMessage.hint(_userMessages.flutterUpstreamRepositoryUnknown);
|
||||
}
|
||||
// At this point, repositoryUrl must not be null
|
||||
if (errorMessage
|
||||
.contains('Flutter SDK is tracking a non-standard remote')) {
|
||||
if (errorMessage.contains('Flutter SDK is tracking a non-standard remote')) {
|
||||
return ValidationMessage.hint(
|
||||
_userMessages.flutterUpstreamRepositoryUrlNonStandard(repositoryUrl!),
|
||||
);
|
||||
@@ -774,15 +739,13 @@ class FlutterValidator extends DoctorValidator {
|
||||
);
|
||||
}
|
||||
}
|
||||
return ValidationMessage(
|
||||
_userMessages.flutterUpstreamRepositoryUrl(repositoryUrl!));
|
||||
return ValidationMessage(_userMessages.flutterUpstreamRepositoryUrl(repositoryUrl!));
|
||||
}
|
||||
|
||||
bool _genSnapshotRuns(String genSnapshotPath) {
|
||||
const int kExpectedExitCode = 255;
|
||||
try {
|
||||
return _processManager.runSync(<String>[genSnapshotPath]).exitCode ==
|
||||
kExpectedExitCode;
|
||||
return _processManager.runSync(<String>[genSnapshotPath]).exitCode == kExpectedExitCode;
|
||||
} on Exception {
|
||||
return false;
|
||||
}
|
||||
@@ -792,9 +755,9 @@ class FlutterValidator extends DoctorValidator {
|
||||
class DeviceValidator extends DoctorValidator {
|
||||
// TODO(jmagman): Make required once g3 rolls and is updated.
|
||||
DeviceValidator({DeviceManager? deviceManager, UserMessages? userMessages})
|
||||
: _deviceManager = deviceManager ?? globals.deviceManager!,
|
||||
_userMessages = userMessages ?? globals.userMessages,
|
||||
super('Connected device');
|
||||
: _deviceManager = deviceManager ?? globals.deviceManager!,
|
||||
_userMessages = userMessages ?? globals.userMessages,
|
||||
super('Connected device');
|
||||
|
||||
final DeviceManager _deviceManager;
|
||||
final UserMessages _userMessages;
|
||||
@@ -809,21 +772,19 @@ class DeviceValidator extends DoctorValidator {
|
||||
);
|
||||
List<ValidationMessage> installedMessages = <ValidationMessage>[];
|
||||
if (devices.isNotEmpty) {
|
||||
installedMessages = (await Device.descriptions(
|
||||
devices,
|
||||
))
|
||||
.map<ValidationMessage>((String msg) => ValidationMessage(msg))
|
||||
.toList();
|
||||
installedMessages =
|
||||
(await Device.descriptions(
|
||||
devices,
|
||||
)).map<ValidationMessage>((String msg) => ValidationMessage(msg)).toList();
|
||||
}
|
||||
|
||||
List<ValidationMessage> diagnosticMessages = <ValidationMessage>[];
|
||||
final List<String> diagnostics =
|
||||
await _deviceManager.getDeviceDiagnostics();
|
||||
final List<String> diagnostics = await _deviceManager.getDeviceDiagnostics();
|
||||
if (diagnostics.isNotEmpty) {
|
||||
diagnosticMessages = diagnostics
|
||||
.map<ValidationMessage>(
|
||||
(String message) => ValidationMessage.hint(message))
|
||||
.toList();
|
||||
diagnosticMessages =
|
||||
diagnostics
|
||||
.map<ValidationMessage>((String message) => ValidationMessage.hint(message))
|
||||
.toList();
|
||||
} else if (devices.isEmpty) {
|
||||
diagnosticMessages = <ValidationMessage>[
|
||||
ValidationMessage.hint(_userMessages.devicesMissing),
|
||||
@@ -851,11 +812,9 @@ class DeviceValidator extends DoctorValidator {
|
||||
|
||||
/// Wrapper for doctor to run multiple times with PII and without, running the validators only once.
|
||||
class DoctorText {
|
||||
DoctorText(BufferLogger logger,
|
||||
{SystemClock? clock, @visibleForTesting Doctor? doctor})
|
||||
: _doctor = doctor ??
|
||||
Doctor(logger: logger, clock: clock ?? globals.systemClock),
|
||||
_logger = logger;
|
||||
DoctorText(BufferLogger logger, {SystemClock? clock, @visibleForTesting Doctor? doctor})
|
||||
: _doctor = doctor ?? Doctor(logger: logger, clock: clock ?? globals.systemClock),
|
||||
_logger = logger;
|
||||
|
||||
final BufferLogger _logger;
|
||||
final Doctor _doctor;
|
||||
@@ -865,8 +824,7 @@ class DoctorText {
|
||||
late final Future<String> piiStrippedText = _runDiagnosis(false);
|
||||
|
||||
// Start the validator tasks only once.
|
||||
late final List<ValidatorTask> _validatorTasks =
|
||||
_doctor.startValidatorTasks();
|
||||
late final List<ValidatorTask> _validatorTasks = _doctor.startValidatorTasks();
|
||||
|
||||
Future<String> _runDiagnosis(bool showPii) async {
|
||||
try {
|
||||
|
||||
@@ -91,8 +91,7 @@ class GroupedValidator extends DoctorValidator {
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
final List<ValidatorTask> tasks = <ValidatorTask>[
|
||||
for (final DoctorValidator validator in subValidators)
|
||||
ValidatorTask(validator,
|
||||
asyncGuard<ValidationResult>(() => validator.validate())),
|
||||
ValidatorTask(validator, asyncGuard<ValidationResult>(() => validator.validate())),
|
||||
];
|
||||
|
||||
final List<ValidationResult> results = <ValidationResult>[];
|
||||
@@ -144,20 +143,17 @@ class ValidationResult {
|
||||
ValidationResult(this.type, this.messages, {this.statusInfo});
|
||||
|
||||
factory ValidationResult.crash(Object error, [StackTrace? stackTrace]) {
|
||||
return ValidationResult(
|
||||
ValidationType.crash,
|
||||
<ValidationMessage>[
|
||||
const ValidationMessage.error(
|
||||
'Due to an error, the doctor check did not complete. '
|
||||
'If the error message below is not helpful, '
|
||||
'please let us know about this issue at https://github.com/flutter/flutter/issues.',
|
||||
),
|
||||
ValidationMessage.error('$error'),
|
||||
if (stackTrace != null)
|
||||
// Stacktrace is informational. Printed in verbose mode only.
|
||||
ValidationMessage('$stackTrace'),
|
||||
],
|
||||
statusInfo: 'the doctor check crashed');
|
||||
return ValidationResult(ValidationType.crash, <ValidationMessage>[
|
||||
const ValidationMessage.error(
|
||||
'Due to an error, the doctor check did not complete. '
|
||||
'If the error message below is not helpful, '
|
||||
'please let us know about this issue at https://github.com/flutter/flutter/issues.',
|
||||
),
|
||||
ValidationMessage.error('$error'),
|
||||
if (stackTrace != null)
|
||||
// Stacktrace is informational. Printed in verbose mode only.
|
||||
ValidationMessage('$stackTrace'),
|
||||
], statusInfo: 'the doctor check crashed');
|
||||
}
|
||||
|
||||
final ValidationType type;
|
||||
@@ -166,36 +162,32 @@ class ValidationResult {
|
||||
final List<ValidationMessage> messages;
|
||||
|
||||
String get leadingBox => switch (type) {
|
||||
ValidationType.crash => '[☠]',
|
||||
ValidationType.missing => '[✗]',
|
||||
ValidationType.success => '[✓]',
|
||||
ValidationType.notAvailable || ValidationType.partial => '[!]',
|
||||
};
|
||||
ValidationType.crash => '[☠]',
|
||||
ValidationType.missing => '[✗]',
|
||||
ValidationType.success => '[✓]',
|
||||
ValidationType.notAvailable || ValidationType.partial => '[!]',
|
||||
};
|
||||
|
||||
/// The time taken to perform the validation, set by [DoctorValidator.validate].
|
||||
Duration? get executionTime => _executionTime;
|
||||
Duration? _executionTime;
|
||||
|
||||
String get coloredLeadingBox {
|
||||
return globals.terminal.color(
|
||||
leadingBox,
|
||||
switch (type) {
|
||||
ValidationType.success => TerminalColor.green,
|
||||
ValidationType.crash || ValidationType.missing => TerminalColor.red,
|
||||
ValidationType.notAvailable ||
|
||||
ValidationType.partial =>
|
||||
TerminalColor.yellow,
|
||||
});
|
||||
return globals.terminal.color(leadingBox, switch (type) {
|
||||
ValidationType.success => TerminalColor.green,
|
||||
ValidationType.crash || ValidationType.missing => TerminalColor.red,
|
||||
ValidationType.notAvailable || ValidationType.partial => TerminalColor.yellow,
|
||||
});
|
||||
}
|
||||
|
||||
/// The string representation of the type.
|
||||
String get typeStr => switch (type) {
|
||||
ValidationType.crash => 'crash',
|
||||
ValidationType.missing => 'missing',
|
||||
ValidationType.success => 'installed',
|
||||
ValidationType.notAvailable => 'notAvailable',
|
||||
ValidationType.partial => 'partial',
|
||||
};
|
||||
ValidationType.crash => 'crash',
|
||||
ValidationType.missing => 'missing',
|
||||
ValidationType.success => 'installed',
|
||||
ValidationType.notAvailable => 'notAvailable',
|
||||
ValidationType.partial => 'partial',
|
||||
};
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -217,23 +209,22 @@ class ValidationMessage {
|
||||
///
|
||||
/// The [contextUrl] may be supplied to link to external resources. This
|
||||
/// is displayed after the informative message in verbose modes.
|
||||
const ValidationMessage(this.message,
|
||||
{this.contextUrl, String? piiStrippedMessage})
|
||||
: type = ValidationMessageType.information,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message;
|
||||
const ValidationMessage(this.message, {this.contextUrl, String? piiStrippedMessage})
|
||||
: type = ValidationMessageType.information,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message;
|
||||
|
||||
/// Create a validation message with information for a failing validator.
|
||||
const ValidationMessage.error(this.message, {String? piiStrippedMessage})
|
||||
: type = ValidationMessageType.error,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
: type = ValidationMessageType.error,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
|
||||
/// Create a validation message with information for a partially failing
|
||||
/// validator.
|
||||
const ValidationMessage.hint(this.message, {String? piiStrippedMessage})
|
||||
: type = ValidationMessageType.hint,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
: type = ValidationMessageType.hint,
|
||||
piiStrippedMessage = piiStrippedMessage ?? message,
|
||||
contextUrl = null;
|
||||
|
||||
final ValidationMessageType type;
|
||||
final String? contextUrl;
|
||||
@@ -249,19 +240,17 @@ class ValidationMessage {
|
||||
bool get isInformation => type == ValidationMessageType.information;
|
||||
|
||||
String get indicator => switch (type) {
|
||||
ValidationMessageType.error => '✗',
|
||||
ValidationMessageType.hint => '!',
|
||||
ValidationMessageType.information => '•',
|
||||
};
|
||||
ValidationMessageType.error => '✗',
|
||||
ValidationMessageType.hint => '!',
|
||||
ValidationMessageType.information => '•',
|
||||
};
|
||||
|
||||
String get coloredIndicator {
|
||||
return globals.terminal.color(
|
||||
indicator,
|
||||
switch (type) {
|
||||
ValidationMessageType.error => TerminalColor.red,
|
||||
ValidationMessageType.hint => TerminalColor.yellow,
|
||||
ValidationMessageType.information => TerminalColor.green,
|
||||
});
|
||||
return globals.terminal.color(indicator, switch (type) {
|
||||
ValidationMessageType.error => TerminalColor.red,
|
||||
ValidationMessageType.hint => TerminalColor.yellow,
|
||||
ValidationMessageType.information => TerminalColor.green,
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -18,8 +18,7 @@ const String kMaven = 'https://maven.google.com/';
|
||||
const String kPubDev = 'https://pub.dev/';
|
||||
|
||||
// Overridable environment variables.
|
||||
const String kPubDevOverride =
|
||||
'PUB_HOSTED_URL'; // https://dart.dev/tools/pub/environment-variables
|
||||
const String kPubDevOverride = 'PUB_HOSTED_URL'; // https://dart.dev/tools/pub/environment-variables
|
||||
|
||||
// Validator that checks all provided hosts are reachable and responsive
|
||||
class HttpHostValidator extends DoctorValidator {
|
||||
@@ -27,10 +26,10 @@ class HttpHostValidator extends DoctorValidator {
|
||||
required Platform platform,
|
||||
required FeatureFlags featureFlags,
|
||||
required HttpClient httpClient,
|
||||
}) : _platform = platform,
|
||||
_featureFlags = featureFlags,
|
||||
_httpClient = httpClient,
|
||||
super('Network resources');
|
||||
}) : _platform = platform,
|
||||
_featureFlags = featureFlags,
|
||||
_httpClient = httpClient,
|
||||
super('Network resources');
|
||||
|
||||
final Platform _platform;
|
||||
final FeatureFlags _featureFlags;
|
||||
@@ -101,8 +100,7 @@ class HttpHostValidator extends DoctorValidator {
|
||||
requiredHosts.add(Uri.parse(kPubDev));
|
||||
}
|
||||
if (_platform.environment.containsKey(kFlutterStorageBaseUrl)) {
|
||||
final Uri? url =
|
||||
_parseUrl(_platform.environment[kFlutterStorageBaseUrl]!);
|
||||
final Uri? url = _parseUrl(_platform.environment[kFlutterStorageBaseUrl]!);
|
||||
if (url == null) {
|
||||
availabilityResults.add(
|
||||
'Environment variable $kFlutterStorageBaseUrl does not specify a valid URL: "${_platform.environment[kFlutterStorageBaseUrl]}"\n'
|
||||
@@ -143,12 +141,9 @@ class HttpHostValidator extends DoctorValidator {
|
||||
if (failures == 0) {
|
||||
assert(successes > 0);
|
||||
assert(messages.isEmpty);
|
||||
return ValidationResult(
|
||||
ValidationType.success,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage('All expected network resources are available.')
|
||||
],
|
||||
);
|
||||
return ValidationResult(ValidationType.success, const <ValidationMessage>[
|
||||
ValidationMessage('All expected network resources are available.'),
|
||||
]);
|
||||
}
|
||||
assert(messages.isNotEmpty);
|
||||
return ValidationResult(
|
||||
|
||||
@@ -12,10 +12,10 @@ import 'doctor_validator.dart';
|
||||
/// validated along with `NO_PROXY`.
|
||||
class ProxyValidator extends DoctorValidator {
|
||||
ProxyValidator({required Platform platform})
|
||||
: shouldShow = _getEnv('HTTP_PROXY', platform).isNotEmpty,
|
||||
_httpProxy = _getEnv('HTTP_PROXY', platform),
|
||||
_noProxy = _getEnv('NO_PROXY', platform),
|
||||
super('Proxy Configuration');
|
||||
: shouldShow = _getEnv('HTTP_PROXY', platform).isNotEmpty,
|
||||
_httpProxy = _getEnv('HTTP_PROXY', platform),
|
||||
_noProxy = _getEnv('NO_PROXY', platform),
|
||||
super('Proxy Configuration');
|
||||
|
||||
final bool shouldShow;
|
||||
final String _httpProxy;
|
||||
@@ -32,8 +32,7 @@ class ProxyValidator extends DoctorValidator {
|
||||
@override
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
if (_httpProxy.isEmpty) {
|
||||
return ValidationResult(
|
||||
ValidationType.success, const <ValidationMessage>[]);
|
||||
return ValidationResult(ValidationType.success, const <ValidationMessage>[]);
|
||||
}
|
||||
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[
|
||||
@@ -50,16 +49,13 @@ class ProxyValidator extends DoctorValidator {
|
||||
],
|
||||
];
|
||||
|
||||
final bool hasIssues =
|
||||
messages.any((ValidationMessage msg) => msg.isHint || msg.isError);
|
||||
final bool hasIssues = messages.any((ValidationMessage msg) => msg.isHint || msg.isError);
|
||||
|
||||
return ValidationResult(
|
||||
hasIssues ? ValidationType.partial : ValidationType.success, messages);
|
||||
return ValidationResult(hasIssues ? ValidationType.partial : ValidationType.success, messages);
|
||||
}
|
||||
|
||||
Future<List<String>> _getLoopbackAddresses() async {
|
||||
final List<NetworkInterface> networkInterfaces =
|
||||
await listNetworkInterfaces(
|
||||
final List<NetworkInterface> networkInterfaces = await listNetworkInterfaces(
|
||||
includeLinkLocal: true,
|
||||
includeLoopback: true,
|
||||
);
|
||||
@@ -67,8 +63,7 @@ class ProxyValidator extends DoctorValidator {
|
||||
return <String>[
|
||||
'localhost',
|
||||
for (final NetworkInterface networkInterface in networkInterfaces)
|
||||
for (final InternetAddress internetAddress
|
||||
in networkInterface.addresses)
|
||||
for (final InternetAddress internetAddress in networkInterface.addresses)
|
||||
if (internetAddress.isLoopback) internetAddress.address,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,16 +28,15 @@ class VsCodeValidator extends DoctorValidator {
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
final List<ValidationMessage> validationMessages =
|
||||
List<ValidationMessage>.from(_vsCode.validationMessages);
|
||||
final List<ValidationMessage> validationMessages = List<ValidationMessage>.from(
|
||||
_vsCode.validationMessages,
|
||||
);
|
||||
|
||||
final String vsCodeVersionText = _vsCode.version == null
|
||||
? 'version unknown'
|
||||
: 'version ${_vsCode.version}';
|
||||
final String vsCodeVersionText =
|
||||
_vsCode.version == null ? 'version unknown' : 'version ${_vsCode.version}';
|
||||
|
||||
if (_vsCode.version == null) {
|
||||
validationMessages.add(const ValidationMessage.error(
|
||||
'Unable to determine VS Code version.'));
|
||||
validationMessages.add(const ValidationMessage.error('Unable to determine VS Code version.'));
|
||||
}
|
||||
|
||||
return ValidationResult(
|
||||
|
||||
@@ -45,12 +45,10 @@ abstract class ChromiumValidator extends DoctorValidator {
|
||||
|
||||
/// A validator that checks whether Chrome is installed and can run.
|
||||
class ChromeValidator extends ChromiumValidator {
|
||||
ChromeValidator({
|
||||
required Platform platform,
|
||||
required ChromiumLauncher chromiumLauncher,
|
||||
}) : _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Chrome - develop for the web');
|
||||
ChromeValidator({required Platform platform, required ChromiumLauncher chromiumLauncher})
|
||||
: _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Chrome - develop for the web');
|
||||
|
||||
@override
|
||||
final Platform _platform;
|
||||
@@ -64,12 +62,10 @@ class ChromeValidator extends ChromiumValidator {
|
||||
|
||||
/// A validator that checks whether Edge is installed and can run.
|
||||
class EdgeValidator extends ChromiumValidator {
|
||||
EdgeValidator({
|
||||
required Platform platform,
|
||||
required ChromiumLauncher chromiumLauncher,
|
||||
}) : _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Edge - develop for the web');
|
||||
EdgeValidator({required Platform platform, required ChromiumLauncher chromiumLauncher})
|
||||
: _platform = platform,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
super('Edge - develop for the web');
|
||||
|
||||
@override
|
||||
final Platform _platform;
|
||||
|
||||
@@ -10,12 +10,10 @@ import 'visual_studio.dart';
|
||||
VisualStudioValidator? get visualStudioValidator => context.get<VisualStudioValidator>();
|
||||
|
||||
class VisualStudioValidator extends DoctorValidator {
|
||||
VisualStudioValidator({
|
||||
required VisualStudio visualStudio,
|
||||
required UserMessages userMessages,
|
||||
}) : _visualStudio = visualStudio,
|
||||
_userMessages = userMessages,
|
||||
super('Visual Studio - develop Windows apps');
|
||||
VisualStudioValidator({required VisualStudio visualStudio, required UserMessages userMessages})
|
||||
: _visualStudio = visualStudio,
|
||||
_userMessages = userMessages,
|
||||
super('Visual Studio - develop Windows apps');
|
||||
|
||||
final VisualStudio _visualStudio;
|
||||
final UserMessages _userMessages;
|
||||
|
||||
@@ -14,8 +14,7 @@ const List<String> kUnsupportedVersions = <String>['6', '7', '8'];
|
||||
|
||||
/// Regex pattern for identifying line from systeminfo stdout with windows version
|
||||
/// (ie. 10.0.22631.4037)
|
||||
const String kWindowsOSVersionSemVerPattern =
|
||||
r'([0-9]+)\.([0-9]+)\.([0-9]+)\.?([0-9\.]+)?';
|
||||
const String kWindowsOSVersionSemVerPattern = r'([0-9]+)\.([0-9]+)\.([0-9]+)\.?([0-9\.]+)?';
|
||||
|
||||
/// Regex pattern for identifying a running instance of the Topaz OFD process.
|
||||
/// This is a known process that interferes with the build toolchain.
|
||||
@@ -28,10 +27,10 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
required OperatingSystemUtils operatingSystemUtils,
|
||||
required ProcessLister processLister,
|
||||
required WindowsVersionExtractor versionExtractor,
|
||||
}) : _operatingSystemUtils = operatingSystemUtils,
|
||||
_processLister = processLister,
|
||||
_versionExtractor = versionExtractor,
|
||||
super('Windows Version');
|
||||
}) : _operatingSystemUtils = operatingSystemUtils,
|
||||
_processLister = processLister,
|
||||
_versionExtractor = versionExtractor,
|
||||
super('Windows Version');
|
||||
|
||||
// See https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information
|
||||
static const int _lowestWindows11BuildNumber = 22000;
|
||||
@@ -42,47 +41,35 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
|
||||
Future<ValidationResult> _topazScan() async {
|
||||
if (!_processLister.canRunPowershell()) {
|
||||
return ValidationResult(
|
||||
ValidationType.missing,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'Failed to find ${ProcessLister.powershell} or ${ProcessLister.pwsh} on PATH'),
|
||||
],
|
||||
);
|
||||
return ValidationResult(ValidationType.missing, const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'Failed to find ${ProcessLister.powershell} or ${ProcessLister.pwsh} on PATH',
|
||||
),
|
||||
]);
|
||||
}
|
||||
final ProcessResult getProcessesResult =
|
||||
await _processLister.getProcessesWithPath();
|
||||
final ProcessResult getProcessesResult = await _processLister.getProcessesWithPath();
|
||||
if (getProcessesResult.exitCode != 0) {
|
||||
return ValidationResult(
|
||||
ValidationType.missing,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint('Get-Process failed to complete'),
|
||||
],
|
||||
);
|
||||
return ValidationResult(ValidationType.missing, const <ValidationMessage>[
|
||||
ValidationMessage.hint('Get-Process failed to complete'),
|
||||
]);
|
||||
}
|
||||
final RegExp topazRegex =
|
||||
RegExp(kCoreProcessPattern, caseSensitive: false, multiLine: true);
|
||||
final RegExp topazRegex = RegExp(kCoreProcessPattern, caseSensitive: false, multiLine: true);
|
||||
final String processes = getProcessesResult.stdout as String;
|
||||
final bool topazFound = topazRegex.hasMatch(processes);
|
||||
if (topazFound) {
|
||||
return ValidationResult(
|
||||
ValidationType.missing,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'The Topaz OFD Security Module was detected on your machine. '
|
||||
'You may need to disable it to build Flutter applications.',
|
||||
),
|
||||
],
|
||||
);
|
||||
return ValidationResult(ValidationType.missing, const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'The Topaz OFD Security Module was detected on your machine. '
|
||||
'You may need to disable it to build Flutter applications.',
|
||||
),
|
||||
]);
|
||||
}
|
||||
return ValidationResult(
|
||||
ValidationType.success, const <ValidationMessage>[]);
|
||||
return ValidationResult(ValidationType.success, const <ValidationMessage>[]);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
final RegExp regex =
|
||||
RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
|
||||
final RegExp regex = RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
|
||||
final String commandResult = _operatingSystemUtils.name;
|
||||
final Iterable<RegExpMatch> matches = regex.allMatches(commandResult);
|
||||
|
||||
@@ -91,15 +78,13 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
ValidationType windowsVersionStatus;
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
String statusInfo;
|
||||
if (matches.length == 1 &&
|
||||
!kUnsupportedVersions.contains(matches.elementAt(0).group(1))) {
|
||||
if (matches.length == 1 && !kUnsupportedVersions.contains(matches.elementAt(0).group(1))) {
|
||||
windowsVersionStatus = ValidationType.success;
|
||||
final WindowsVersionExtractionResult details =
|
||||
await _versionExtractor.getDetails();
|
||||
final WindowsVersionExtractionResult details = await _versionExtractor.getDetails();
|
||||
String? caption = details.caption;
|
||||
if (caption == null || caption.isEmpty) {
|
||||
final bool isWindows11 = int.parse(matches.elementAt(0).group(3)!) >
|
||||
_lowestWindows11BuildNumber;
|
||||
final bool isWindows11 =
|
||||
int.parse(matches.elementAt(0).group(3)!) > _lowestWindows11BuildNumber;
|
||||
if (isWindows11) {
|
||||
caption = 'Windows 11 or higher';
|
||||
} else {
|
||||
@@ -114,9 +99,7 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
|
||||
// Check if the Topaz OFD security module is running, and warn the user if it is.
|
||||
// See https://github.com/flutter/flutter/issues/121366
|
||||
final List<ValidationResult> subResults = <ValidationResult>[
|
||||
await _topazScan()
|
||||
];
|
||||
final List<ValidationResult> subResults = <ValidationResult>[await _topazScan()];
|
||||
for (final ValidationResult subResult in subResults) {
|
||||
if (subResult.type != ValidationType.success) {
|
||||
statusInfo = 'Problem detected with Windows installation';
|
||||
@@ -126,12 +109,10 @@ class WindowsVersionValidator extends DoctorValidator {
|
||||
}
|
||||
} else {
|
||||
windowsVersionStatus = ValidationType.missing;
|
||||
statusInfo =
|
||||
'Unable to determine Windows version (command `ver` returned $commandResult)';
|
||||
statusInfo = 'Unable to determine Windows version (command `ver` returned $commandResult)';
|
||||
}
|
||||
|
||||
return ValidationResult(windowsVersionStatus, messages,
|
||||
statusInfo: statusInfo);
|
||||
return ValidationResult(windowsVersionStatus, messages, statusInfo: statusInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,10 +147,9 @@ class ProcessLister {
|
||||
/// the edition and the processor architecture), releaseId and displayVersion and are returned via the
|
||||
/// [WindowsVersionExtractionResult] class.
|
||||
class WindowsVersionExtractor {
|
||||
WindowsVersionExtractor(
|
||||
{required ProcessManager processManager, required Logger logger})
|
||||
: _logger = logger,
|
||||
_processManager = processManager;
|
||||
WindowsVersionExtractor({required ProcessManager processManager, required Logger logger})
|
||||
: _logger = logger,
|
||||
_processManager = processManager;
|
||||
|
||||
final ProcessManager _processManager;
|
||||
final Logger _logger;
|
||||
@@ -189,16 +169,12 @@ class WindowsVersionExtractor {
|
||||
if (output != null) {
|
||||
final List<String> parts = output.split('\n');
|
||||
if (parts.length >= 2) {
|
||||
caption = parts[1]
|
||||
.replaceAll('Microsoft Windows', '')
|
||||
.replaceAll(' ', ' ')
|
||||
.trim();
|
||||
caption = parts[1].replaceAll('Microsoft Windows', '').replaceAll(' ', ' ').trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
} on ProcessException catch (e) {
|
||||
_logger
|
||||
.printTrace('Failed to get Caption and OSArchitecture from WMI: $e');
|
||||
_logger.printTrace('Failed to get Caption and OSArchitecture from WMI: $e');
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -214,13 +190,9 @@ class WindowsVersionExtractor {
|
||||
final String? output = osDetails.stdout as String?;
|
||||
if (output != null) {
|
||||
final Map<String, String> data = Map<String, String>.fromEntries(
|
||||
output
|
||||
.split('\n')
|
||||
.where((String line) => line.contains('REG_SZ'))
|
||||
.map((String line) {
|
||||
output.split('\n').where((String line) => line.contains('REG_SZ')).map((String line) {
|
||||
final List<String> parts = line.split('REG_SZ');
|
||||
return MapEntry<String, String>(
|
||||
parts.first.trim(), parts.last.trim());
|
||||
return MapEntry<String, String>(parts.first.trim(), parts.last.trim());
|
||||
}),
|
||||
);
|
||||
releaseId = data['ReleaseId'];
|
||||
@@ -228,8 +200,7 @@ class WindowsVersionExtractor {
|
||||
}
|
||||
}
|
||||
} on ProcessException catch (e) {
|
||||
_logger.printTrace(
|
||||
'Failed to get ReleaseId and DisplayVersion from registry: $e');
|
||||
_logger.printTrace('Failed to get ReleaseId and DisplayVersion from registry: $e');
|
||||
}
|
||||
|
||||
return WindowsVersionExtractionResult(
|
||||
@@ -250,8 +221,7 @@ final class WindowsVersionExtractionResult {
|
||||
});
|
||||
|
||||
factory WindowsVersionExtractionResult.empty() {
|
||||
return WindowsVersionExtractionResult(
|
||||
caption: null, releaseId: null, displayVersion: null);
|
||||
return WindowsVersionExtractionResult(caption: null, releaseId: null, displayVersion: null);
|
||||
}
|
||||
|
||||
final String? caption;
|
||||
|
||||
@@ -44,8 +44,7 @@ void main() {
|
||||
fs = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'ValidationMessage equality and hashCode includes contextUrl', () {
|
||||
testWithoutContext('ValidationMessage equality and hashCode includes contextUrl', () {
|
||||
const ValidationMessage messageA = ValidationMessage('ab', contextUrl: 'a');
|
||||
const ValidationMessage messageB = ValidationMessage('ab', contextUrl: 'b');
|
||||
|
||||
@@ -66,8 +65,7 @@ void main() {
|
||||
ValidationMessage message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('VS Code '),
|
||||
);
|
||||
expect(message.message,
|
||||
'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
expect(message.message, 'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
|
||||
message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('Flutter '),
|
||||
@@ -76,8 +74,7 @@ void main() {
|
||||
expect(message.isError, isFalse);
|
||||
});
|
||||
|
||||
testUsingContext('No IDE Validator includes expected installation messages',
|
||||
() async {
|
||||
testUsingContext('No IDE Validator includes expected installation messages', () async {
|
||||
final ValidationResult result = await NoIdeValidator().validate();
|
||||
expect(result.type, ValidationType.notAvailable);
|
||||
|
||||
@@ -92,9 +89,8 @@ void main() {
|
||||
VsCodeValidatorTestTargets.installedWithExtension64bit.title,
|
||||
'VS Code, 64-bit edition',
|
||||
);
|
||||
final ValidationResult result = await VsCodeValidatorTestTargets
|
||||
.installedWithExtension64bit
|
||||
.validate();
|
||||
final ValidationResult result =
|
||||
await VsCodeValidatorTestTargets.installedWithExtension64bit.validate();
|
||||
expect(result.type, ValidationType.success);
|
||||
expect(result.statusInfo, 'version 1.2.3');
|
||||
expect(result.messages, hasLength(2));
|
||||
@@ -102,8 +98,7 @@ void main() {
|
||||
ValidationMessage message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('VS Code '),
|
||||
);
|
||||
expect(message.message,
|
||||
'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
expect(message.message, 'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
|
||||
message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('Flutter '),
|
||||
@@ -121,14 +116,12 @@ void main() {
|
||||
ValidationMessage message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('VS Code '),
|
||||
);
|
||||
expect(message.message,
|
||||
'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
expect(message.message, 'VS Code at ${VsCodeValidatorTestTargets.validInstall}');
|
||||
|
||||
message = result.messages.firstWhere(
|
||||
(ValidationMessage m) => m.message.startsWith('Flutter '),
|
||||
);
|
||||
expect(message.message,
|
||||
startsWith('Flutter extension can be installed from'));
|
||||
expect(message.message, startsWith('Flutter extension can be installed from'));
|
||||
expect(
|
||||
message.contextUrl,
|
||||
'https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter',
|
||||
@@ -152,8 +145,8 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('diagnostic message', () async {
|
||||
final FakeDeviceManager deviceManager = FakeDeviceManager()
|
||||
..diagnostics = <String>['Device locked'];
|
||||
final FakeDeviceManager deviceManager =
|
||||
FakeDeviceManager()..diagnostics = <String>['Device locked'];
|
||||
|
||||
final DeviceValidator deviceValidator = DeviceValidator(
|
||||
deviceManager: deviceManager,
|
||||
@@ -161,16 +154,16 @@ void main() {
|
||||
);
|
||||
final ValidationResult result = await deviceValidator.validate();
|
||||
expect(result.type, ValidationType.notAvailable);
|
||||
expect(result.messages,
|
||||
const <ValidationMessage>[ValidationMessage.hint('Device locked')]);
|
||||
expect(result.messages, const <ValidationMessage>[ValidationMessage.hint('Device locked')]);
|
||||
expect(result.statusInfo, isNull);
|
||||
});
|
||||
|
||||
testWithoutContext('diagnostic message and devices', () async {
|
||||
final FakeDevice device = FakeDevice();
|
||||
final FakeDeviceManager deviceManager = FakeDeviceManager()
|
||||
..devices = <Device>[device]
|
||||
..diagnostics = <String>['Device locked'];
|
||||
final FakeDeviceManager deviceManager =
|
||||
FakeDeviceManager()
|
||||
..devices = <Device>[device]
|
||||
..diagnostics = <String>['Device locked'];
|
||||
|
||||
final DeviceValidator deviceValidator = DeviceValidator(
|
||||
deviceManager: deviceManager,
|
||||
@@ -191,8 +184,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate non-verbose output format for run without issues',
|
||||
() async {
|
||||
final Doctor doctor =
|
||||
Doctor(logger: logger, clock: const SystemClock());
|
||||
final Doctor doctor = Doctor(logger: logger, clock: const SystemClock());
|
||||
expect(await doctor.diagnose(verbose: false), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
@@ -223,15 +215,13 @@ void main() {
|
||||
testUsingContext(
|
||||
'contains installed',
|
||||
() async {
|
||||
final Doctor doctor =
|
||||
Doctor(logger: logger, clock: const SystemClock());
|
||||
final Doctor doctor = Doctor(logger: logger, clock: const SystemClock());
|
||||
await doctor.diagnose(verbose: false);
|
||||
|
||||
expect(testUsage.events.length, 3);
|
||||
expect(
|
||||
testUsage.events,
|
||||
contains(const TestUsageEvent('doctor-result', 'PassingValidator',
|
||||
label: 'installed')),
|
||||
contains(const TestUsageEvent('doctor-result', 'PassingValidator', label: 'installed')),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
@@ -246,14 +236,10 @@ void main() {
|
||||
expect(
|
||||
testUsage.events,
|
||||
unorderedEquals(<TestUsageEvent>[
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithHintsOnly',
|
||||
label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithErrors',
|
||||
label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithHintsOnly', label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithErrors', label: 'partial'),
|
||||
]),
|
||||
);
|
||||
}, overrides: <Type, Generator>{Usage: () => testUsage});
|
||||
@@ -264,16 +250,11 @@ void main() {
|
||||
expect(
|
||||
testUsage.events,
|
||||
unorderedEquals(<TestUsageEvent>[
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'MissingValidator',
|
||||
label: 'missing'),
|
||||
const TestUsageEvent('doctor-result', 'NotAvailableValidator',
|
||||
label: 'notAvailable'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithHintsOnly',
|
||||
label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithErrors',
|
||||
label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PassingValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'MissingValidator', label: 'missing'),
|
||||
const TestUsageEvent('doctor-result', 'NotAvailableValidator', label: 'notAvailable'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithHintsOnly', label: 'partial'),
|
||||
const TestUsageEvent('doctor-result', 'PartialValidatorWithErrors', label: 'partial'),
|
||||
]),
|
||||
);
|
||||
}, overrides: <Type, Generator>{Usage: () => testUsage});
|
||||
@@ -286,14 +267,10 @@ void main() {
|
||||
expect(
|
||||
testUsage.events,
|
||||
unorderedEquals(<TestUsageEvent>[
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'MissingGroupedValidator',
|
||||
label: 'missing'),
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PassingGroupedValidator', label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'MissingGroupedValidator', label: 'missing'),
|
||||
]),
|
||||
);
|
||||
},
|
||||
@@ -301,8 +278,7 @@ void main() {
|
||||
);
|
||||
|
||||
testUsingContext('sending events can be skipped', () async {
|
||||
await FakePassingDoctor(logger)
|
||||
.diagnose(verbose: false, sendEvent: false);
|
||||
await FakePassingDoctor(logger).diagnose(verbose: false, sendEvent: false);
|
||||
|
||||
expect(testUsage.events, isEmpty);
|
||||
}, overrides: <Type, Generator>{Usage: () => testUsage});
|
||||
@@ -332,8 +308,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate non-verbose output format for run with crash',
|
||||
() async {
|
||||
expect(
|
||||
await FakeCrashingDoctor(logger).diagnose(verbose: false), isFalse);
|
||||
expect(await FakeCrashingDoctor(logger).diagnose(verbose: false), isFalse);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals(
|
||||
@@ -354,9 +329,7 @@ void main() {
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'validate verbose output format contains trace for run with crash',
|
||||
() async {
|
||||
testUsingContext('validate verbose output format contains trace for run with crash', () async {
|
||||
expect(await FakeCrashingDoctor(logger).diagnose(), isFalse);
|
||||
expect(logger.statusText, contains('#0 CrashingValidator.validate'));
|
||||
});
|
||||
@@ -373,8 +346,7 @@ void main() {
|
||||
|
||||
expect(
|
||||
logger.statusText,
|
||||
contains(
|
||||
'Stuck validator that never completes exceeded maximum allowed duration of '),
|
||||
contains('Stuck validator that never completes exceeded maximum allowed duration of '),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -386,9 +358,7 @@ void main() {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
await FakeAsync().run((FakeAsync time) {
|
||||
unawaited(
|
||||
FakeAsyncCrashingDoctor(time, logger)
|
||||
.diagnose(verbose: false)
|
||||
.then((bool r) {
|
||||
FakeAsyncCrashingDoctor(time, logger).diagnose(verbose: false).then((bool r) {
|
||||
expect(r, isFalse);
|
||||
completer.complete();
|
||||
}),
|
||||
@@ -420,8 +390,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate non-verbose output format when only one category fails',
|
||||
() async {
|
||||
expect(await FakeSinglePassingDoctor(logger).diagnose(verbose: false),
|
||||
isTrue);
|
||||
expect(await FakeSinglePassingDoctor(logger).diagnose(verbose: false), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals(
|
||||
@@ -439,8 +408,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate non-verbose output format for a passing run',
|
||||
() async {
|
||||
expect(
|
||||
await FakePassingDoctor(logger).diagnose(verbose: false), isTrue);
|
||||
expect(await FakePassingDoctor(logger).diagnose(verbose: false), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals(
|
||||
@@ -491,55 +459,60 @@ void main() {
|
||||
testUsingContext('validate verbose output format', () async {
|
||||
expect(await FakeDoctor(logger).diagnose(), isFalse);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals('[✓] Passing Validator (with statusInfo) [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A second, somewhat longer helpful message\n'
|
||||
'\n'
|
||||
'[✗] Missing Validator [0ms]\n'
|
||||
' ✗ A useful error message\n'
|
||||
' • A message that is not an error\n'
|
||||
' ! A hint message\n'
|
||||
'\n'
|
||||
'[!] Not Available Validator [0ms]\n'
|
||||
' ✗ A useful error message\n'
|
||||
' • A message that is not an error\n'
|
||||
' ! A hint message\n'
|
||||
'\n'
|
||||
'[!] Partial Validator with only a Hint [0ms]\n'
|
||||
' ! There is a hint here\n'
|
||||
' • But there is no error\n'
|
||||
'\n'
|
||||
'[!] Partial Validator with Errors [0ms]\n'
|
||||
' ✗ An error message indicating partial installation\n'
|
||||
' ! Maybe a hint will help the user\n'
|
||||
' • An extra message with some verbose details\n'
|
||||
'\n'
|
||||
'! Doctor found issues in 4 categories.\n'));
|
||||
}, overrides: <Type, Generator>{
|
||||
AnsiTerminal: () => FakeTerminal(),
|
||||
});
|
||||
logger.statusText,
|
||||
equals(
|
||||
'[✓] Passing Validator (with statusInfo) [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A second, somewhat longer helpful message\n'
|
||||
'\n'
|
||||
'[✗] Missing Validator [0ms]\n'
|
||||
' ✗ A useful error message\n'
|
||||
' • A message that is not an error\n'
|
||||
' ! A hint message\n'
|
||||
'\n'
|
||||
'[!] Not Available Validator [0ms]\n'
|
||||
' ✗ A useful error message\n'
|
||||
' • A message that is not an error\n'
|
||||
' ! A hint message\n'
|
||||
'\n'
|
||||
'[!] Partial Validator with only a Hint [0ms]\n'
|
||||
' ! There is a hint here\n'
|
||||
' • But there is no error\n'
|
||||
'\n'
|
||||
'[!] Partial Validator with Errors [0ms]\n'
|
||||
' ✗ An error message indicating partial installation\n'
|
||||
' ! Maybe a hint will help the user\n'
|
||||
' • An extra message with some verbose details\n'
|
||||
'\n'
|
||||
'! Doctor found issues in 4 categories.\n',
|
||||
),
|
||||
);
|
||||
}, overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()});
|
||||
|
||||
testUsingContext('validate PII can be hidden', () async {
|
||||
expect(await FakePiiDoctor(logger).diagnose(showPii: false), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals('[✓] PII Validator [0ms]\n'
|
||||
' • Does not contain PII\n'
|
||||
'\n'
|
||||
'• No issues found!\n'));
|
||||
logger.statusText,
|
||||
equals(
|
||||
'[✓] PII Validator [0ms]\n'
|
||||
' • Does not contain PII\n'
|
||||
'\n'
|
||||
'• No issues found!\n',
|
||||
),
|
||||
);
|
||||
logger.clear();
|
||||
// PII shown.
|
||||
expect(await FakePiiDoctor(logger).diagnose(), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals('[✓] PII Validator [0ms]\n'
|
||||
' • Contains PII path/to/username\n'
|
||||
'\n'
|
||||
'• No issues found!\n'));
|
||||
}, overrides: <Type, Generator>{
|
||||
AnsiTerminal: () => FakeTerminal(),
|
||||
});
|
||||
logger.statusText,
|
||||
equals(
|
||||
'[✓] PII Validator [0ms]\n'
|
||||
' • Contains PII path/to/username\n'
|
||||
'\n'
|
||||
'• No issues found!\n',
|
||||
),
|
||||
);
|
||||
}, overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()});
|
||||
});
|
||||
|
||||
group('doctor diagnosis wrapper', () {
|
||||
@@ -556,11 +529,13 @@ void main() {
|
||||
() async {
|
||||
final Doctor fakeDoctor = FakePiiDoctor(logger);
|
||||
final DoctorText doctorText = DoctorText(logger, doctor: fakeDoctor);
|
||||
const String expectedPiiText = '[✓] PII Validator [0ms]\n'
|
||||
const String expectedPiiText =
|
||||
'[✓] PII Validator [0ms]\n'
|
||||
' • Contains PII path/to/username\n'
|
||||
'\n'
|
||||
'• No issues found!\n';
|
||||
const String expectedPiiStrippedText = '[✓] PII Validator [0ms]\n'
|
||||
const String expectedPiiStrippedText =
|
||||
'[✓] PII Validator [0ms]\n'
|
||||
' • Does not contain PII\n'
|
||||
'\n'
|
||||
'• No issues found!\n';
|
||||
@@ -575,14 +550,10 @@ void main() {
|
||||
|
||||
// Only one event sent.
|
||||
expect(testUsage.events, <TestUsageEvent>[
|
||||
const TestUsageEvent('doctor-result', 'PiiValidator',
|
||||
label: 'installed'),
|
||||
const TestUsageEvent('doctor-result', 'PiiValidator', label: 'installed'),
|
||||
]);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
AnsiTerminal: () => FakeTerminal(),
|
||||
Usage: () => testUsage
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal(), Usage: () => testUsage},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
@@ -687,50 +658,57 @@ void main() {
|
||||
}, overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()});
|
||||
|
||||
group('doctor with grouped validators', () {
|
||||
testUsingContext('validate diagnose combines validator output', () async {
|
||||
expect(await FakeGroupedDoctor(logger).diagnose(), isTrue);
|
||||
expect(
|
||||
testUsingContext(
|
||||
'validate diagnose combines validator output',
|
||||
() async {
|
||||
expect(await FakeGroupedDoctor(logger).diagnose(), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals('[✓] Category 1 [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A helpful message\n'
|
||||
'\n'
|
||||
'[!] Category 2 [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' ✗ A useful error message\n'
|
||||
'\n'
|
||||
'! Doctor found issues in 1 category.\n'));
|
||||
}, overrides: <Type, Generator>{
|
||||
AnsiTerminal: () => FakeTerminal(),
|
||||
});
|
||||
equals(
|
||||
'[✓] Category 1 [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A helpful message\n'
|
||||
'\n'
|
||||
'[!] Category 2 [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' ✗ A useful error message\n'
|
||||
'\n'
|
||||
'! Doctor found issues in 1 category.\n',
|
||||
),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
);
|
||||
|
||||
testUsingContext('validate merging assigns statusInfo and title', () async {
|
||||
// There are two subvalidators. Only the second contains statusInfo.
|
||||
expect(await FakeGroupedDoctorWithStatus(logger).diagnose(), isTrue);
|
||||
expect(
|
||||
testUsingContext(
|
||||
'validate merging assigns statusInfo and title',
|
||||
() async {
|
||||
// There are two subvalidators. Only the second contains statusInfo.
|
||||
expect(await FakeGroupedDoctorWithStatus(logger).diagnose(), isTrue);
|
||||
expect(
|
||||
logger.statusText,
|
||||
equals('[✓] First validator title (A status message) [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A different message\n'
|
||||
'\n'
|
||||
'• No issues found!\n'));
|
||||
}, overrides: <Type, Generator>{
|
||||
AnsiTerminal: () => FakeTerminal(),
|
||||
});
|
||||
equals(
|
||||
'[✓] First validator title (A status message) [0ms]\n'
|
||||
' • A helpful message\n'
|
||||
' • A different message\n'
|
||||
'\n'
|
||||
'• No issues found!\n',
|
||||
),
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
);
|
||||
});
|
||||
|
||||
group('grouped validator merging results', () {
|
||||
final PassingGroupedValidator installed =
|
||||
PassingGroupedValidator('Category');
|
||||
final PassingGroupedValidator installed = PassingGroupedValidator('Category');
|
||||
final PartialGroupedValidator partial = PartialGroupedValidator('Category');
|
||||
final MissingGroupedValidator missing = MissingGroupedValidator('Category');
|
||||
|
||||
testUsingContext(
|
||||
'validate installed + installed = installed',
|
||||
() async {
|
||||
expect(
|
||||
await FakeSmallGroupDoctor(logger, installed, installed).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, installed, installed).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[✓]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -739,9 +717,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate installed + partial = partial',
|
||||
() async {
|
||||
expect(
|
||||
await FakeSmallGroupDoctor(logger, installed, partial).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, installed, partial).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -750,9 +726,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate installed + missing = partial',
|
||||
() async {
|
||||
expect(
|
||||
await FakeSmallGroupDoctor(logger, installed, missing).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, installed, missing).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -761,9 +735,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate partial + installed = partial',
|
||||
() async {
|
||||
expect(
|
||||
await FakeSmallGroupDoctor(logger, partial, installed).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, partial, installed).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -772,8 +744,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate partial + partial = partial',
|
||||
() async {
|
||||
expect(await FakeSmallGroupDoctor(logger, partial, partial).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, partial, partial).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -782,8 +753,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate partial + missing = partial',
|
||||
() async {
|
||||
expect(await FakeSmallGroupDoctor(logger, partial, missing).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, partial, missing).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -792,9 +762,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate missing + installed = partial',
|
||||
() async {
|
||||
expect(
|
||||
await FakeSmallGroupDoctor(logger, missing, installed).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, missing, installed).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -803,8 +771,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate missing + partial = partial',
|
||||
() async {
|
||||
expect(await FakeSmallGroupDoctor(logger, missing, partial).diagnose(),
|
||||
isTrue);
|
||||
expect(await FakeSmallGroupDoctor(logger, missing, partial).diagnose(), isTrue);
|
||||
expect(logger.statusText, startsWith('[!]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -813,8 +780,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'validate missing + missing = missing',
|
||||
() async {
|
||||
expect(await FakeSmallGroupDoctor(logger, missing, missing).diagnose(),
|
||||
isFalse);
|
||||
expect(await FakeSmallGroupDoctor(logger, missing, missing).diagnose(), isFalse);
|
||||
expect(logger.statusText, startsWith('[✗]'));
|
||||
},
|
||||
overrides: <Type, Generator>{AnsiTerminal: () => FakeTerminal()},
|
||||
@@ -824,10 +790,11 @@ void main() {
|
||||
testUsingContext(
|
||||
'WebWorkflow is a part of validator workflows if enabled',
|
||||
() async {
|
||||
final List<Workflow> workflows = DoctorValidatorsProvider.test(
|
||||
featureFlags: TestFeatureFlags(isWebEnabled: true),
|
||||
platform: FakePlatform(),
|
||||
).workflows;
|
||||
final List<Workflow> workflows =
|
||||
DoctorValidatorsProvider.test(
|
||||
featureFlags: TestFeatureFlags(isWebEnabled: true),
|
||||
platform: FakePlatform(),
|
||||
).workflows;
|
||||
expect(workflows, contains(isA<WebWorkflow>()));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
@@ -839,16 +806,14 @@ void main() {
|
||||
testUsingContext(
|
||||
'CustomDevicesWorkflow is a part of validator workflows if enabled',
|
||||
() async {
|
||||
final List<Workflow> workflows = DoctorValidatorsProvider.test(
|
||||
featureFlags: TestFeatureFlags(areCustomDevicesEnabled: true),
|
||||
platform: FakePlatform(),
|
||||
).workflows;
|
||||
final List<Workflow> workflows =
|
||||
DoctorValidatorsProvider.test(
|
||||
featureFlags: TestFeatureFlags(areCustomDevicesEnabled: true),
|
||||
platform: FakePlatform(),
|
||||
).workflows;
|
||||
expect(workflows, contains(isA<CustomDeviceWorkflow>()));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => fakeProcessManager
|
||||
},
|
||||
overrides: <Type, Generator>{FileSystem: () => fs, ProcessManager: () => fakeProcessManager},
|
||||
);
|
||||
|
||||
group('FlutterValidator', () {
|
||||
@@ -871,21 +836,17 @@ void main() {
|
||||
final Directory devtoolsDir = fs.directory(
|
||||
'/path/to/flutter/bin/cache/dart-sdk/bin/resources/devtools',
|
||||
)..createSync(recursive: true);
|
||||
fs
|
||||
.directory('/path/to/flutter/bin/cache/artifacts')
|
||||
.createSync(recursive: true);
|
||||
devtoolsDir
|
||||
.childFile('version.json')
|
||||
.writeAsStringSync('{"version": "123"}');
|
||||
fs.directory('/path/to/flutter/bin/cache/artifacts').createSync(recursive: true);
|
||||
devtoolsDir.childFile('version.json').writeAsStringSync('{"version": "123"}');
|
||||
fakeProcessManager.addCommands(const <FakeCommand>[
|
||||
FakeCommand(command: <String>['which', 'java']),
|
||||
]);
|
||||
final List<DoctorValidator> validators = DoctorValidatorsProvider.test(
|
||||
featureFlags: featureFlags,
|
||||
platform: FakePlatform(),
|
||||
).validators;
|
||||
final FlutterValidator flutterValidator =
|
||||
validators.whereType<FlutterValidator>().first;
|
||||
final List<DoctorValidator> validators =
|
||||
DoctorValidatorsProvider.test(
|
||||
featureFlags: featureFlags,
|
||||
platform: FakePlatform(),
|
||||
).validators;
|
||||
final FlutterValidator flutterValidator = validators.whereType<FlutterValidator>().first;
|
||||
final ValidationResult result = await flutterValidator.validate();
|
||||
expect(
|
||||
result.messages.map((ValidationMessage msg) => msg.message),
|
||||
@@ -893,7 +854,8 @@ void main() {
|
||||
);
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
Cache: () => Cache.test(
|
||||
Cache:
|
||||
() => Cache.test(
|
||||
rootOverride: fs.directory('/path/to/flutter'),
|
||||
fileSystem: fs,
|
||||
processManager: fakeProcessManager,
|
||||
@@ -912,10 +874,8 @@ void main() {
|
||||
final DoctorValidatorsProvider provider = DoctorValidatorsProvider.test(
|
||||
featureFlags: TestFeatureFlags(isAndroidEnabled: false),
|
||||
);
|
||||
expect(
|
||||
provider.validators, isNot(contains(isA<AndroidStudioValidator>())));
|
||||
expect(provider.validators,
|
||||
isNot(contains(isA<NoAndroidStudioValidator>())));
|
||||
expect(provider.validators, isNot(contains(isA<AndroidStudioValidator>())));
|
||||
expect(provider.validators, isNot(contains(isA<NoAndroidStudioValidator>())));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
AndroidWorkflow: () => FakeAndroidWorkflow(appliesToHostPlatform: false),
|
||||
@@ -966,16 +926,13 @@ void main() {
|
||||
);
|
||||
expect(fakeAnalytics.sentEvents, contains(eventToFind));
|
||||
},
|
||||
overrides: <Type, Generator>{
|
||||
DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider()
|
||||
},
|
||||
overrides: <Type, Generator>{DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider()},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'contains installed and partial',
|
||||
() async {
|
||||
await FakePassingDoctor(logger, clock: fakeSystemClock)
|
||||
.diagnose(verbose: false);
|
||||
await FakePassingDoctor(logger, clock: fakeSystemClock).diagnose(verbose: false);
|
||||
|
||||
expect(fakeAnalytics.sentEvents, hasLength(4));
|
||||
expect(
|
||||
@@ -1019,8 +976,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'contains installed, missing and partial',
|
||||
() async {
|
||||
await FakeDoctor(logger, clock: fakeSystemClock)
|
||||
.diagnose(verbose: false);
|
||||
await FakeDoctor(logger, clock: fakeSystemClock).diagnose(verbose: false);
|
||||
|
||||
expect(fakeAnalytics.sentEvents, hasLength(5));
|
||||
expect(
|
||||
@@ -1069,8 +1025,7 @@ void main() {
|
||||
testUsingContext(
|
||||
'events for grouped validators are properly decomposed',
|
||||
() async {
|
||||
await FakeGroupedDoctor(logger, clock: fakeSystemClock)
|
||||
.diagnose(verbose: false);
|
||||
await FakeGroupedDoctor(logger, clock: fakeSystemClock).diagnose(verbose: false);
|
||||
|
||||
expect(fakeAnalytics.sentEvents, hasLength(4));
|
||||
expect(
|
||||
@@ -1112,18 +1067,14 @@ void main() {
|
||||
testUsingContext(
|
||||
'grouped validator subresult and subvalidators different lengths',
|
||||
() async {
|
||||
final FakeGroupedDoctorWithCrash fakeDoctor =
|
||||
FakeGroupedDoctorWithCrash(
|
||||
final FakeGroupedDoctorWithCrash fakeDoctor = FakeGroupedDoctorWithCrash(
|
||||
logger,
|
||||
clock: fakeSystemClock,
|
||||
);
|
||||
await fakeDoctor.diagnose(verbose: false);
|
||||
|
||||
expect(fakeDoctor.validators, hasLength(1));
|
||||
expect(
|
||||
fakeDoctor.validators.first.runtimeType ==
|
||||
FakeGroupedValidatorWithCrash,
|
||||
true);
|
||||
expect(fakeDoctor.validators.first.runtimeType == FakeGroupedValidatorWithCrash, true);
|
||||
expect(fakeAnalytics.sentEvents, hasLength(0));
|
||||
|
||||
// Attempt to send a random event to ensure that the
|
||||
@@ -1138,16 +1089,14 @@ void main() {
|
||||
);
|
||||
|
||||
testUsingContext('sending events can be skipped', () async {
|
||||
await FakePassingDoctor(logger)
|
||||
.diagnose(verbose: false, sendEvent: false);
|
||||
await FakePassingDoctor(logger).diagnose(verbose: false, sendEvent: false);
|
||||
expect(fakeAnalytics.sentEvents, isEmpty);
|
||||
}, overrides: <Type, Generator>{Analytics: () => fakeAnalytics});
|
||||
});
|
||||
}
|
||||
|
||||
class FakeAndroidWorkflow extends Fake implements AndroidWorkflow {
|
||||
FakeAndroidWorkflow(
|
||||
{this.canListDevices = true, this.appliesToHostPlatform = true});
|
||||
FakeAndroidWorkflow({this.canListDevices = true, this.appliesToHostPlatform = true});
|
||||
|
||||
@override
|
||||
final bool canListDevices;
|
||||
@@ -1165,8 +1114,11 @@ class PassingValidator extends DoctorValidator {
|
||||
ValidationMessage('A helpful message'),
|
||||
ValidationMessage('A second, somewhat longer helpful message'),
|
||||
];
|
||||
return ZeroExecutionTimeValidationResult(ValidationType.success, messages,
|
||||
statusInfo: 'with statusInfo');
|
||||
return ZeroExecutionTimeValidationResult(
|
||||
ValidationType.success,
|
||||
messages,
|
||||
statusInfo: 'with statusInfo',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1209,8 +1161,7 @@ class NotAvailableValidator extends DoctorValidator {
|
||||
ValidationMessage('A message that is not an error'),
|
||||
ValidationMessage.hint('A hint message'),
|
||||
];
|
||||
return ZeroExecutionTimeValidationResult(
|
||||
ValidationType.notAvailable, messages);
|
||||
return ZeroExecutionTimeValidationResult(ValidationType.notAvailable, messages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1232,8 +1183,7 @@ class PartialValidatorWithErrors extends DoctorValidator {
|
||||
@override
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
const List<ValidationMessage> messages = <ValidationMessage>[
|
||||
ValidationMessage.error(
|
||||
'An error message indicating partial installation'),
|
||||
ValidationMessage.error('An error message indicating partial installation'),
|
||||
ValidationMessage.hint('Maybe a hint will help the user'),
|
||||
ValidationMessage('An extra message with some verbose details'),
|
||||
];
|
||||
@@ -1283,8 +1233,7 @@ class AsyncCrashingValidator extends DoctorValidator {
|
||||
|
||||
/// A doctor that fails with a missing [ValidationResult].
|
||||
class FakeDoctor extends Doctor {
|
||||
FakeDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1298,8 +1247,7 @@ class FakeDoctor extends Doctor {
|
||||
|
||||
/// A doctor that should pass, but still has issues in some categories.
|
||||
class FakePassingDoctor extends Doctor {
|
||||
FakePassingDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakePassingDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1314,18 +1262,15 @@ class FakePassingDoctor extends Doctor {
|
||||
/// categories.
|
||||
class FakeSinglePassingDoctor extends Doctor {
|
||||
FakeSinglePassingDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
: super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
PartialValidatorWithHintsOnly()
|
||||
];
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[PartialValidatorWithHintsOnly()];
|
||||
}
|
||||
|
||||
/// A doctor that passes and has no issues anywhere.
|
||||
class FakeQuietDoctor extends Doctor {
|
||||
FakeQuietDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeQuietDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1338,19 +1283,15 @@ class FakeQuietDoctor extends Doctor {
|
||||
|
||||
/// A doctor that passes and contains PII that can be hidden.
|
||||
class FakePiiDoctor extends Doctor {
|
||||
FakePiiDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakePiiDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
PiiValidator()
|
||||
];
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[PiiValidator()];
|
||||
}
|
||||
|
||||
/// A doctor with a validator that throws an exception.
|
||||
class FakeCrashingDoctor extends Doctor {
|
||||
FakeCrashingDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeCrashingDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1364,8 +1305,7 @@ class FakeCrashingDoctor extends Doctor {
|
||||
|
||||
/// A doctor with a validator that will never finish.
|
||||
class FakeAsyncStuckDoctor extends Doctor {
|
||||
FakeAsyncStuckDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeAsyncStuckDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1379,9 +1319,8 @@ class FakeAsyncStuckDoctor extends Doctor {
|
||||
|
||||
/// A doctor with a validator that throws an exception.
|
||||
class FakeAsyncCrashingDoctor extends Doctor {
|
||||
FakeAsyncCrashingDoctor(this._time, Logger logger,
|
||||
{super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeAsyncCrashingDoctor(this._time, Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
|
||||
final FakeAsync _time;
|
||||
|
||||
@@ -1400,10 +1339,10 @@ class FakeAsyncCrashingDoctor extends Doctor {
|
||||
class FakeDoctorValidatorsProvider implements DoctorValidatorsProvider {
|
||||
@override
|
||||
List<DoctorValidator> get validators => <DoctorValidator>[
|
||||
PassingValidator('Passing Validator'),
|
||||
PassingValidator('Another Passing Validator'),
|
||||
PassingValidator('Providing validators is fun'),
|
||||
];
|
||||
PassingValidator('Passing Validator'),
|
||||
PassingValidator('Another Passing Validator'),
|
||||
PassingValidator('Providing validators is fun'),
|
||||
];
|
||||
|
||||
@override
|
||||
List<Workflow> get workflows => <Workflow>[];
|
||||
@@ -1453,23 +1392,25 @@ class PassingGroupedValidatorWithStatus extends DoctorValidator {
|
||||
const List<ValidationMessage> messages = <ValidationMessage>[
|
||||
ValidationMessage('A different message'),
|
||||
];
|
||||
return ZeroExecutionTimeValidationResult(ValidationType.success, messages,
|
||||
statusInfo: 'A status message');
|
||||
return ZeroExecutionTimeValidationResult(
|
||||
ValidationType.success,
|
||||
messages,
|
||||
statusInfo: 'A status message',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A doctor that has two groups of two validators each.
|
||||
class FakeGroupedDoctor extends Doctor {
|
||||
FakeGroupedDoctor(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeGroupedDoctor(Logger logger, {super.clock = const SystemClock()}) : super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
GroupedValidator(<DoctorValidator>[
|
||||
FakeGroupedValidator(<DoctorValidator>[
|
||||
PassingGroupedValidator('Category 1'),
|
||||
PassingGroupedValidator('Category 1'),
|
||||
]),
|
||||
GroupedValidator(<DoctorValidator>[
|
||||
FakeGroupedValidator(<DoctorValidator>[
|
||||
PassingGroupedValidator('Category 2'),
|
||||
MissingGroupedValidator('Category 2'),
|
||||
]),
|
||||
@@ -1479,7 +1420,7 @@ class FakeGroupedDoctor extends Doctor {
|
||||
/// Fake grouped doctor that is intended to be used with [FakeGroupedValidatorWithCrash].
|
||||
class FakeGroupedDoctorWithCrash extends Doctor {
|
||||
FakeGroupedDoctorWithCrash(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
: super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
@@ -1505,14 +1446,27 @@ class FakeGroupedValidatorWithCrash extends GroupedValidator {
|
||||
List<ValidationResult> get subResults => <ValidationResult>[];
|
||||
}
|
||||
|
||||
class FakeGroupedValidator extends GroupedValidator {
|
||||
FakeGroupedValidator(super.subValidator);
|
||||
|
||||
@override
|
||||
Future<ValidationResult> validateImpl() async {
|
||||
final ValidationResult result = await super.validateImpl();
|
||||
return ZeroExecutionTimeValidationResult(
|
||||
result.type,
|
||||
result.messages,
|
||||
statusInfo: result.statusInfo,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FakeGroupedDoctorWithStatus extends Doctor {
|
||||
FakeGroupedDoctorWithStatus(Logger logger,
|
||||
{super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
FakeGroupedDoctorWithStatus(Logger logger, {super.clock = const SystemClock()})
|
||||
: super(logger: logger);
|
||||
|
||||
@override
|
||||
late final List<DoctorValidator> validators = <DoctorValidator>[
|
||||
GroupedValidator(<DoctorValidator>[
|
||||
FakeGroupedValidator(<DoctorValidator>[
|
||||
PassingGroupedValidator('First validator title'),
|
||||
PassingGroupedValidatorWithStatus('Second validator title'),
|
||||
]),
|
||||
@@ -1527,10 +1481,10 @@ class FakeSmallGroupDoctor extends Doctor {
|
||||
DoctorValidator val1,
|
||||
DoctorValidator val2, {
|
||||
super.clock = const SystemClock(),
|
||||
}) : validators = <DoctorValidator>[
|
||||
GroupedValidator(<DoctorValidator>[val1, val2]),
|
||||
],
|
||||
super(logger: logger);
|
||||
}) : validators = <DoctorValidator>[
|
||||
FakeGroupedValidator(<DoctorValidator>[val1, val2]),
|
||||
],
|
||||
super(logger: logger);
|
||||
|
||||
@override
|
||||
final List<DoctorValidator> validators;
|
||||
@@ -1542,26 +1496,24 @@ class VsCodeValidatorTestTargets extends VsCodeValidator {
|
||||
String extensionDirectory, {
|
||||
String? edition,
|
||||
}) : super(
|
||||
VsCode.fromDirectory(
|
||||
installDirectory,
|
||||
extensionDirectory,
|
||||
edition: edition,
|
||||
fileSystem: globals.fs,
|
||||
),
|
||||
);
|
||||
VsCode.fromDirectory(
|
||||
installDirectory,
|
||||
extensionDirectory,
|
||||
edition: edition,
|
||||
fileSystem: globals.fs,
|
||||
),
|
||||
);
|
||||
|
||||
static VsCodeValidatorTestTargets get installedWithExtension =>
|
||||
VsCodeValidatorTestTargets._(validInstall, validExtensions);
|
||||
|
||||
static VsCodeValidatorTestTargets get installedWithExtension64bit =>
|
||||
VsCodeValidatorTestTargets._(validInstall, validExtensions,
|
||||
edition: '64-bit edition');
|
||||
VsCodeValidatorTestTargets._(validInstall, validExtensions, edition: '64-bit edition');
|
||||
|
||||
static VsCodeValidatorTestTargets get installedWithoutExtension =>
|
||||
VsCodeValidatorTestTargets._(validInstall, missingExtensions);
|
||||
|
||||
static final String validInstall =
|
||||
globals.fs.path.join('test', 'data', 'vscode', 'application');
|
||||
static final String validInstall = globals.fs.path.join('test', 'data', 'vscode', 'application');
|
||||
static final String validExtensions = globals.fs.path.join(
|
||||
'test',
|
||||
'data',
|
||||
@@ -1581,15 +1533,13 @@ class FakeDeviceManager extends Fake implements DeviceManager {
|
||||
List<Device> devices = <Device>[];
|
||||
|
||||
@override
|
||||
Future<List<Device>> getAllDevices({DeviceDiscoveryFilter? filter}) async =>
|
||||
devices;
|
||||
Future<List<Device>> getAllDevices({DeviceDiscoveryFilter? filter}) async => devices;
|
||||
|
||||
@override
|
||||
Future<List<Device>> refreshAllDevices({
|
||||
Duration? timeout,
|
||||
DeviceDiscoveryFilter? filter,
|
||||
}) async =>
|
||||
devices;
|
||||
}) async => devices;
|
||||
|
||||
@override
|
||||
Future<List<String>> getDeviceDiagnostics() async => diagnostics;
|
||||
@@ -1621,8 +1571,7 @@ class FakeDevice extends Fake implements Device {
|
||||
Future<String> get sdkNameAndVersion async => '1.2.3';
|
||||
|
||||
@override
|
||||
Future<TargetPlatform> get targetPlatform =>
|
||||
Future<TargetPlatform>.value(TargetPlatform.android);
|
||||
Future<TargetPlatform> get targetPlatform => Future<TargetPlatform>.value(TargetPlatform.android);
|
||||
}
|
||||
|
||||
class FakeTerminal extends Fake implements AnsiTerminal {
|
||||
@@ -1634,8 +1583,7 @@ class FakeTerminal extends Fake implements AnsiTerminal {
|
||||
}
|
||||
|
||||
class ZeroExecutionTimeValidationResult extends ValidationResult {
|
||||
ZeroExecutionTimeValidationResult(super.type, super.messages,
|
||||
{super.statusInfo});
|
||||
ZeroExecutionTimeValidationResult(super.type, super.messages, {super.statusInfo});
|
||||
|
||||
@override
|
||||
Duration? get executionTime => Duration.zero;
|
||||
|
||||
@@ -14,20 +14,15 @@ import '../src/context.dart';
|
||||
import '../src/fake_process_manager.dart';
|
||||
|
||||
/// Fake [_WindowsUtils] to use for testing
|
||||
class FakeValidOperatingSystemUtils extends Fake
|
||||
implements OperatingSystemUtils {
|
||||
FakeValidOperatingSystemUtils(
|
||||
[this.name = 'Microsoft Windows [Version 11.0.22621.963]']);
|
||||
class FakeValidOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
||||
FakeValidOperatingSystemUtils([this.name = 'Microsoft Windows [Version 11.0.22621.963]']);
|
||||
|
||||
@override
|
||||
final String name;
|
||||
}
|
||||
|
||||
class FakeProcessLister extends Fake implements ProcessLister {
|
||||
FakeProcessLister(
|
||||
{required this.result,
|
||||
this.exitCode = 0,
|
||||
this.powershellAvailable = true});
|
||||
FakeProcessLister({required this.result, this.exitCode = 0, this.powershellAvailable = true});
|
||||
final String result;
|
||||
final int exitCode;
|
||||
final bool powershellAvailable;
|
||||
@@ -42,13 +37,11 @@ class FakeProcessLister extends Fake implements ProcessLister {
|
||||
}
|
||||
|
||||
FakeProcessLister ofdRunning() {
|
||||
return FakeProcessLister(
|
||||
result: r'Path: "C:\Program Files\Topaz OFD\Warsaw\core.exe"');
|
||||
return FakeProcessLister(result: r'Path: "C:\Program Files\Topaz OFD\Warsaw\core.exe"');
|
||||
}
|
||||
|
||||
FakeProcessLister ofdNotRunning() {
|
||||
return FakeProcessLister(
|
||||
result: r'Path: "C:\Program Files\Google\Chrome\Application\chrome.exe');
|
||||
return FakeProcessLister(result: r'Path: "C:\Program Files\Google\Chrome\Application\chrome.exe');
|
||||
}
|
||||
|
||||
FakeProcessLister failure() {
|
||||
@@ -78,44 +71,37 @@ ValidationResult invalidWindowsValidationResult = ValidationResult(
|
||||
statusInfo: 'Unable to confirm if installed Windows version is 10 or greater',
|
||||
);
|
||||
|
||||
ValidationResult ofdFoundRunning = ValidationResult(
|
||||
ValidationType.partial,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'The Topaz OFD Security Module was detected on your machine. '
|
||||
'You may need to disable it to build Flutter applications.',
|
||||
),
|
||||
],
|
||||
statusInfo: 'Problem detected with Windows installation',
|
||||
);
|
||||
ValidationResult ofdFoundRunning =
|
||||
ValidationResult(ValidationType.partial, const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'The Topaz OFD Security Module was detected on your machine. '
|
||||
'You may need to disable it to build Flutter applications.',
|
||||
),
|
||||
], statusInfo: 'Problem detected with Windows installation');
|
||||
|
||||
ValidationResult powershellUnavailableResult = ValidationResult(
|
||||
ValidationType.partial,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'Failed to find ${ProcessLister.powershell} or ${ProcessLister.pwsh} on PATH'),
|
||||
],
|
||||
statusInfo: 'Problem detected with Windows installation',
|
||||
);
|
||||
ValidationResult powershellUnavailableResult =
|
||||
ValidationResult(ValidationType.partial, const <ValidationMessage>[
|
||||
ValidationMessage.hint(
|
||||
'Failed to find ${ProcessLister.powershell} or ${ProcessLister.pwsh} on PATH',
|
||||
),
|
||||
], statusInfo: 'Problem detected with Windows installation');
|
||||
|
||||
ValidationResult getProcessFailed = ValidationResult(
|
||||
ValidationType.partial,
|
||||
const <ValidationMessage>[
|
||||
ValidationMessage.hint('Get-Process failed to complete'),
|
||||
],
|
||||
const <ValidationMessage>[ValidationMessage.hint('Get-Process failed to complete')],
|
||||
statusInfo: 'Problem detected with Windows installation',
|
||||
);
|
||||
|
||||
class FakeVersionExtractor extends Fake implements WindowsVersionExtractor {
|
||||
FakeVersionExtractor({required this.mockData});
|
||||
FakeVersionExtractor.win11ProX64()
|
||||
: this(
|
||||
mockData: WindowsVersionExtractionResult(
|
||||
caption: '11 Pro 64-bit',
|
||||
releaseId: '2009',
|
||||
displayVersion: '23H2',
|
||||
),
|
||||
);
|
||||
: this(
|
||||
mockData: WindowsVersionExtractionResult(
|
||||
caption: '11 Pro 64-bit',
|
||||
releaseId: '2009',
|
||||
displayVersion: '23H2',
|
||||
),
|
||||
);
|
||||
final WindowsVersionExtractionResult mockData;
|
||||
|
||||
@override
|
||||
@@ -125,10 +111,8 @@ class FakeVersionExtractor extends Fake implements WindowsVersionExtractor {
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWithoutContext('Successfully running windows version check on windows 10',
|
||||
() async {
|
||||
final WindowsVersionValidator windowsVersionValidator =
|
||||
WindowsVersionValidator(
|
||||
testWithoutContext('Successfully running windows version check on windows 10', () async {
|
||||
final WindowsVersionValidator windowsVersionValidator = WindowsVersionValidator(
|
||||
operatingSystemUtils: FakeValidOperatingSystemUtils(),
|
||||
processLister: ofdNotRunning(),
|
||||
versionExtractor: FakeVersionExtractor.win11ProX64(),
|
||||
@@ -148,11 +132,8 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext(
|
||||
'Successfully running windows version check on windows 10 for BR',
|
||||
() async {
|
||||
final WindowsVersionValidator windowsVersionValidator =
|
||||
WindowsVersionValidator(
|
||||
testWithoutContext('Successfully running windows version check on windows 10 for BR', () async {
|
||||
final WindowsVersionValidator windowsVersionValidator = WindowsVersionValidator(
|
||||
operatingSystemUtils: FakeValidOperatingSystemUtils(
|
||||
'Microsoft Windows [versão 10.0.22621.1105]',
|
||||
),
|
||||
@@ -175,8 +156,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWithoutContext('Identifying a windows version before 10', () async {
|
||||
final WindowsVersionValidator windowsVersionValidator =
|
||||
WindowsVersionValidator(
|
||||
final WindowsVersionValidator windowsVersionValidator = WindowsVersionValidator(
|
||||
operatingSystemUtils: FakeValidOperatingSystemUtils(
|
||||
'Microsoft Windows [Version 8.0.22621.1105]',
|
||||
),
|
||||
@@ -205,16 +185,13 @@ OS Version: .0.19044 N/A Build 19044
|
||||
OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
''';
|
||||
|
||||
final RegExp regex =
|
||||
RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
|
||||
final RegExp regex = RegExp(kWindowsOSVersionSemVerPattern, multiLine: true);
|
||||
final Iterable<RegExpMatch> matches = regex.allMatches(testStr);
|
||||
|
||||
expect(matches.length, 5,
|
||||
reason: 'There should be only 5 matches for the pattern provided');
|
||||
expect(matches.length, 5, reason: 'There should be only 5 matches for the pattern provided');
|
||||
});
|
||||
|
||||
testWithoutContext('Successfully checks for Topaz OFD when it is running',
|
||||
() async {
|
||||
testWithoutContext('Successfully checks for Topaz OFD when it is running', () async {
|
||||
final WindowsVersionValidator validator = WindowsVersionValidator(
|
||||
operatingSystemUtils: FakeValidOperatingSystemUtils(),
|
||||
processLister: ofdRunning(),
|
||||
@@ -276,8 +253,7 @@ OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
final WindowsVersionValidator validator = WindowsVersionValidator(
|
||||
operatingSystemUtils: FakeValidOperatingSystemUtils(),
|
||||
processLister: failure(),
|
||||
versionExtractor: FakeVersionExtractor(
|
||||
mockData: WindowsVersionExtractionResult.empty()),
|
||||
versionExtractor: FakeVersionExtractor(mockData: WindowsVersionExtractionResult.empty()),
|
||||
);
|
||||
final ValidationResult result = await validator.validate();
|
||||
expect(
|
||||
@@ -302,20 +278,14 @@ OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
);
|
||||
});
|
||||
|
||||
testWithoutContext('getProcessesWithPath successfully runs with powershell',
|
||||
() async {
|
||||
testWithoutContext('getProcessesWithPath successfully runs with powershell', () async {
|
||||
final ProcessLister processLister = ProcessLister(
|
||||
FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
ProcessLister.powershell,
|
||||
'-command',
|
||||
'Get-Process | Format-List Path'
|
||||
],
|
||||
command: <String>[ProcessLister.powershell, '-command', 'Get-Process | Format-List Path'],
|
||||
stdout: ProcessLister.powershell,
|
||||
),
|
||||
])
|
||||
..excludedExecutables.add(ProcessLister.pwsh),
|
||||
])..excludedExecutables.add(ProcessLister.pwsh),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -333,15 +303,10 @@ OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
final ProcessLister processLister = ProcessLister(
|
||||
FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
ProcessLister.pwsh,
|
||||
'-command',
|
||||
'Get-Process | Format-List Path'
|
||||
],
|
||||
command: <String>[ProcessLister.pwsh, '-command', 'Get-Process | Format-List Path'],
|
||||
stdout: ProcessLister.pwsh,
|
||||
),
|
||||
])
|
||||
..excludedExecutables.add(ProcessLister.powershell),
|
||||
])..excludedExecutables.add(ProcessLister.powershell),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -359,8 +324,7 @@ OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
() async {
|
||||
final ProcessLister processLister = ProcessLister(
|
||||
FakeProcessManager.empty()
|
||||
..excludedExecutables
|
||||
.addAll(<String>[ProcessLister.powershell, ProcessLister.pwsh]),
|
||||
..excludedExecutables.addAll(<String>[ProcessLister.powershell, ProcessLister.pwsh]),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -378,8 +342,7 @@ OS 版本: 10.0.22621 暂缺 Build 22621
|
||||
testWithoutContext(
|
||||
'Parses Caption, OSArchitecture, releaseId, and CurrentVersion from the OS',
|
||||
() async {
|
||||
final FakeProcessManager processManager =
|
||||
FakeProcessManager.list(<FakeCommand>[
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <Pattern>['wmic', 'os', 'get', 'Caption,OSArchitecture'],
|
||||
stdout: '''
|
||||
@@ -439,8 +402,7 @@ End of search: 22 match(es) found.
|
||||
},
|
||||
);
|
||||
|
||||
testWithoutContext('Differentiates Windows 11 from 10 when wmic call fails',
|
||||
() async {
|
||||
testWithoutContext('Differentiates Windows 11 from 10 when wmic call fails', () async {
|
||||
const String windows10RegQueryOutput = r'''
|
||||
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
|
||||
SystemRoot REG_SZ C:\WINDOWS
|
||||
@@ -468,14 +430,8 @@ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion
|
||||
End of search: 21 match(es) found.
|
||||
|
||||
''';
|
||||
const List<String> wmicCommand = <String>[
|
||||
'wmic',
|
||||
'os',
|
||||
'get',
|
||||
'Caption,OSArchitecture'
|
||||
];
|
||||
final FakeProcessManager processManager =
|
||||
FakeProcessManager.list(<FakeCommand>[
|
||||
const List<String> wmicCommand = <String>['wmic', 'os', 'get', 'Caption,OSArchitecture'];
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
FakeCommand(
|
||||
command: wmicCommand,
|
||||
exception: ProcessException(wmicCommand[0], wmicCommand.sublist(1)),
|
||||
@@ -506,12 +462,7 @@ End of search: 21 match(es) found.
|
||||
});
|
||||
|
||||
testWithoutContext('Handles reg call failing', () async {
|
||||
const List<String> wmicCommand = <String>[
|
||||
'wmic',
|
||||
'os',
|
||||
'get',
|
||||
'Caption,OSArchitecture'
|
||||
];
|
||||
const List<String> wmicCommand = <String>['wmic', 'os', 'get', 'Caption,OSArchitecture'];
|
||||
const List<String> regCommand = <String>[
|
||||
'reg',
|
||||
'query',
|
||||
@@ -519,8 +470,7 @@ End of search: 21 match(es) found.
|
||||
'/t',
|
||||
'REG_SZ',
|
||||
];
|
||||
final FakeProcessManager processManager =
|
||||
FakeProcessManager.list(<FakeCommand>[
|
||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: wmicCommand,
|
||||
stdout: r'''
|
||||
|
||||
Reference in New Issue
Block a user