-
Notifications
You must be signed in to change notification settings - Fork 28.6k
Windows version check in doctor #110013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows version check in doctor #110013
Conversation
merging version check
Example return from a
Each line will be parsed by the windows version validator by filtering for the line that is relevant. Actual results for |
cc @Jasguerrero |
packages/flutter_tools/lib/src/windows/windows_version_validator.dart
Outdated
Show resolved
Hide resolved
version = null; | ||
} | ||
|
||
ValidationType windowsVersionStatus = ValidationType.missing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be final and set it to ValidationType.missing
on the else
bool versionText = false; | ||
bool versionSemver = false; | ||
String? version; | ||
for (int i = 0; i < systemInfoElements.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can iterate directly over the systemInfoElements
(as well as the lineElements
) and avoid using .elementAt
for (final String curLine in systemInfoElements) {...}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, i meant to actually refactor this to use that notation
@@ -50,7 +50,7 @@ class WindowsVersionValidator extends DoctorValidator { | |||
// semantic versioned strings | |||
// (ie. 10.5.4123) | |||
final RegExp regex = | |||
RegExp(r'\n(OS Version:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)\n'); | |||
RegExp(r'\n?(OS Version:\s*)([0-9]+\.[0-9]+\.[0-9]+)(.*)\n?'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does adding the question mark not make this also match 'BIOS Version:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so, the question mark should be only looking for 0 or 1 newline characters before OS
. Unless I had the wrong assumption there?
I added the question mark incase there was no new line character before the OS Version
line on print out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in "BIOS Version:" won't there be 0 newline characters before "OS"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whether i'm right or wrong, this should be test cases in the unit tests :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean now, I'm going to try a refactor with multiLine
enabled so that I can specify the start of the line as a reference point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll build some test cases with multiline enabled when i get back. thanks for the review! 😁
Oops. I fatfingered the ready for review button on mobile, but there's no way in the mobile UI to change back to draft... |
Switch to desktop view 😁 |
Windows version check in doctor
updating feature branch with upstream master
packages/flutter_tools/lib/src/windows/windows_version_validator.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/lib/src/windows/windows_version_validator.dart
Outdated
Show resolved
Hide resolved
static Iterable<RegExpMatch> validateString(String pattern, String str, | ||
{bool multiLine = true}) { | ||
final RegExp regex = RegExp( | ||
pattern, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really think this helper method is carrying its weight. First, I would move the regex string to a top level and document there what it is intended to match. Then you can replace it with regex.allMaches(contents)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think from reading @christopherfujino's comment, the idea was to embed the version matching pattern in this method to make it easy to test.
From reading the test cases, I think it would work OK without this as a public method. But if you're not going to specifically test it you should drop this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Chris mentioned that it would be helpful to make this regex helper a method that we can unit test independently, so that we can feed it test strings as we start to encounter newer versions of the stdout
from systeminfo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're basically not testing this method, though, because this method itself is trivial. I would just test the regex itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that this helper method would also include lines 58-61 and return a boolean. Also the rather than passing the pattern (which is actually what you want to test), that the function would receive resultStdout
.
Then your test can look (something) like:
test('validateVersionString() correctly validates the output of `systeminfo`', () {
bool result = validateVersionString('123');
expect(result, isFalse);
result = validateVersionString('OS Version: 8.0.0');
// Too old
expect(result, isFalse);
result = validateVersionString('OS Version: 11.1.2');
expect(result, isTrue);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is fine too, its the middle ground that isn't very useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree with @jonahwilliams that the static method was very trivial but @christopherfujino what your test looks like is essentially what the entire validator was built to check.
I shied away from creating a regex method that returned a boolean because I didn't want to assume that there would only be one match within the stdout
. The conditionals beginning on line 60 were added to ensure that the matches only returned 1 result AND that the major version was valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, makes sense, i'm fine with you removing this function
packages/flutter_tools/test/general.shard/windows_version_validator_test.dart
Show resolved
Hide resolved
packages/flutter_tools/lib/src/windows/windows_version_validator.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Pre-launch Checklist
///
).Addresses #102607 stating that a warning should be emitted during a
flutter doctor
run to warn users on Windows versions less than 10