Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d2a95ee3
Unverified
Commit
d2a95ee3
authored
Sep 25, 2019
by
Francisco Magdaleno
Committed by
GitHub
Sep 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix crash on vswhere query on missing installations (#40786)
parent
ae529d8b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
25 deletions
+74
-25
visual_studio_validator.dart
...lutter_tools/lib/src/windows/visual_studio_validator.dart
+3
-1
visual_studio_test.dart
..._tools/test/general.shard/windows/visual_studio_test.dart
+42
-10
visual_studio_validator_test.dart
...t/general.shard/windows/visual_studio_validator_test.dart
+29
-14
No files found.
packages/flutter_tools/lib/src/windows/visual_studio_validator.dart
View file @
d2a95ee3
...
...
@@ -12,7 +12,9 @@ VisualStudioValidator get visualStudioValidator => context.get<VisualStudioValid
class
VisualStudioValidator
extends
DoctorValidator
{
const
VisualStudioValidator
()
:
super
(
'Visual Studio - develop for Windows'
);
int
get
majorVersion
=>
int
.
tryParse
(
visualStudio
.
fullVersion
.
split
(
'.'
)[
0
]);
int
get
majorVersion
=>
visualStudio
.
fullVersion
!=
null
?
int
.
tryParse
(
visualStudio
.
fullVersion
.
split
(
'.'
)[
0
])
:
null
;
@override
Future
<
ValidationResult
>
validate
()
async
{
...
...
packages/flutter_tools/test/general.shard/windows/visual_studio_test.dart
View file @
d2a95ee3
...
...
@@ -35,20 +35,20 @@ void main() {
// A minimum version of a response where a VS installation was found.
const
Map
<
String
,
dynamic
>
_defaultResponse
=
<
String
,
dynamic
>{
'installationPath'
:
visualStudioPath
,
'displayName'
:
'Visual Studio Community 201
7
'
,
'installationVersion'
:
'1
5.9.28307.665
'
,
'displayName'
:
'Visual Studio Community 201
9
'
,
'installationVersion'
:
'1
6.2.29306.81
'
,
'isRebootRequired'
:
false
,
'isComplete'
:
true
,
'isLaunchable'
:
true
,
'isPrerelease'
:
false
,
'catalog'
:
<
String
,
dynamic
>{
'productDisplayVersion'
:
'1
5.9.12
'
,
}
,
'productDisplayVersion'
:
'1
6.2.5
'
,
}
};
// A version of a response that doesn't include certain installation status
// information that might be missing in older Visual Studio versions.
const
Map
<
String
,
dynamic
>
_
old
Response
=
<
String
,
dynamic
>{
const
Map
<
String
,
dynamic
>
_
missingStatus
Response
=
<
String
,
dynamic
>{
'installationPath'
:
visualStudioPath
,
'displayName'
:
'Visual Studio Community 2017'
,
'installationVersion'
:
'15.9.28307.665'
,
...
...
@@ -205,10 +205,32 @@ void main() {
ProcessManager:
()
=>
mockProcessManager
,
});
testUsingContext
(
'necessaryComponentDescriptions suggest the right VS tools on major version 15'
,
()
{
visualStudio
=
VisualStudio
();
final
String
toolsString
=
visualStudio
.
necessaryComponentDescriptions
(
15
)[
1
];
expect
(
toolsString
.
contains
(
'v141'
),
true
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFilesystem
,
Platform:
()
=>
windowsPlatform
,
ProcessManager:
()
=>
mockProcessManager
,
});
testUsingContext
(
'necessaryComponentDescriptions suggest the right VS tools on major version != 15'
,
()
{
visualStudio
=
VisualStudio
();
final
String
toolsString
=
visualStudio
.
necessaryComponentDescriptions
(
16
)[
1
];
expect
(
toolsString
.
contains
(
'v142'
),
true
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFilesystem
,
Platform:
()
=>
windowsPlatform
,
ProcessManager:
()
=>
mockProcessManager
,
});
testUsingContext
(
'isInstalled returns true even with missing status information'
,
()
{
setMockCompatibleVisualStudioInstallation
(
null
);
setMockPrereleaseVisualStudioInstallation
(
null
);
setMockAnyVisualStudioInstallation
(
_
old
Response
);
setMockAnyVisualStudioInstallation
(
_
missingStatus
Response
);
visualStudio
=
VisualStudio
();
expect
(
visualStudio
.
isInstalled
,
true
);
...
...
@@ -360,10 +382,10 @@ void main() {
setMockAnyVisualStudioInstallation
(
_defaultResponse
);
visualStudio
=
VisualStudio
();
expect
(
visualStudio
.
displayName
,
equals
(
'Visual Studio Community 201
7
'
));
expect
(
visualStudio
.
displayVersion
,
equals
(
'1
5.9.12
'
));
expect
(
visualStudio
.
displayName
,
equals
(
'Visual Studio Community 201
9
'
));
expect
(
visualStudio
.
displayVersion
,
equals
(
'1
6.2.5
'
));
expect
(
visualStudio
.
installLocation
,
equals
(
visualStudioPath
));
expect
(
visualStudio
.
fullVersion
,
equals
(
'1
5.9.28307.665
'
));
expect
(
visualStudio
.
fullVersion
,
equals
(
'1
6.2.29306.81
'
));
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
memoryFilesystem
,
Platform:
()
=>
windowsPlatform
,
...
...
@@ -386,7 +408,17 @@ void main() {
});
testUsingContext
(
'Metadata is for compatible version when latest is missing components'
,
()
{
setMockCompatibleVisualStudioInstallation
(
_defaultResponse
);
// Return a different version for queries without the required packages.
final
Map
<
String
,
dynamic
>
olderButCompleteVersionResponse
=
<
String
,
dynamic
>{
'installationPath'
:
visualStudioPath
,
'displayName'
:
'Visual Studio Community 2017'
,
'installationVersion'
:
'15.9.28307.665'
,
'catalog'
:
<
String
,
dynamic
>{
'productDisplayVersion'
:
'15.9.12'
,
}
};
setMockCompatibleVisualStudioInstallation
(
olderButCompleteVersionResponse
);
setMockPrereleaseVisualStudioInstallation
(
null
);
// Return a different version for queries without the required packages.
final
Map
<
String
,
dynamic
>
incompleteVersionResponse
=
<
String
,
dynamic
>{
...
...
packages/flutter_tools/test/general.shard/windows/visual_studio_validator_test.dart
View file @
d2a95ee3
...
...
@@ -19,19 +19,35 @@ void main() {
setUp
(()
{
mockVisualStudio
=
MockVisualStudio
();
// Mock a valid VS installation.
// Default values regardless of whether VS is installed or not.
when
(
mockVisualStudio
.
workloadDescription
).
thenReturn
(
'Desktop development'
);
when
(
mockVisualStudio
.
necessaryComponentDescriptions
(
any
)).
thenReturn
(<
String
>[
'A'
,
'B'
]);
});
// Assigns default values for a complete VS installation with necessary components.
void
_configureMockVisualStudioAsInstalled
()
{
when
(
mockVisualStudio
.
isInstalled
).
thenReturn
(
true
);
when
(
mockVisualStudio
.
isPrerelease
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
isComplete
).
thenReturn
(
true
);
when
(
mockVisualStudio
.
isLaunchable
).
thenReturn
(
true
);
when
(
mockVisualStudio
.
isRebootRequired
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
hasNecessaryComponents
).
thenReturn
(
true
);
when
(
mockVisualStudio
.
workloadDescription
).
thenReturn
(
'Desktop development'
);
when
(
mockVisualStudio
.
necessaryComponentDescriptions
(
any
)).
thenReturn
(<
String
>[
'A'
,
'B'
]);
when
(
mockVisualStudio
.
fullVersion
).
thenReturn
(
'15.1'
);
});
when
(
mockVisualStudio
.
displayName
).
thenReturn
(
'Visual Studio Community 2019'
);
}
// Assigns default values for a missing VS installation.
void
_configureMockVisualStudioAsNotInstalled
()
{
when
(
mockVisualStudio
.
isInstalled
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
isPrerelease
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
isComplete
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
isLaunchable
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
isRebootRequired
).
thenReturn
(
false
);
when
(
mockVisualStudio
.
hasNecessaryComponents
).
thenReturn
(
false
);
}
testUsingContext
(
'Emits a message when Visual Studio is a pre-release version'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
when
(
visualStudio
.
isPrerelease
).
thenReturn
(
true
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
...
...
@@ -42,16 +58,8 @@ void main() {
VisualStudio:
()
=>
mockVisualStudio
,
});
testUsingContext
(
'Emits missing status when Visual Studio is not installed'
,
()
async
{
when
(
visualStudio
.
isInstalled
).
thenReturn
(
false
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
final
ValidationResult
result
=
await
validator
.
validate
();
expect
(
result
.
type
,
ValidationType
.
missing
);
},
overrides:
<
Type
,
Generator
>{
VisualStudio:
()
=>
mockVisualStudio
,
});
testUsingContext
(
'Emits a partial status when Visual Studio installation is incomplete'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
when
(
visualStudio
.
isComplete
).
thenReturn
(
false
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
...
...
@@ -64,6 +72,7 @@ void main() {
});
testUsingContext
(
'Emits a partial status when Visual Studio installation needs rebooting'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
when
(
visualStudio
.
isRebootRequired
).
thenReturn
(
true
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
...
...
@@ -76,6 +85,7 @@ void main() {
});
testUsingContext
(
'Emits a partial status when Visual Studio installation is not launchable'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
when
(
visualStudio
.
isLaunchable
).
thenReturn
(
false
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
...
...
@@ -89,6 +99,7 @@ void main() {
testUsingContext
(
'Emits partial status when Visual Studio is installed without necessary components'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
when
(
visualStudio
.
hasNecessaryComponents
).
thenReturn
(
false
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
final
ValidationResult
result
=
await
validator
.
validate
();
...
...
@@ -98,15 +109,19 @@ void main() {
});
testUsingContext
(
'Emits installed status when Visual Studio is installed with necessary components'
,
()
async
{
_configureMockVisualStudioAsInstalled
();
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
final
ValidationResult
result
=
await
validator
.
validate
();
final
ValidationMessage
expectedDisplayNameMessage
=
ValidationMessage
(
userMessages
.
visualStudioVersion
(
visualStudio
.
displayName
,
visualStudio
.
fullVersion
));
expect
(
result
.
messages
.
contains
(
expectedDisplayNameMessage
),
true
);
expect
(
result
.
type
,
ValidationType
.
installed
);
},
overrides:
<
Type
,
Generator
>{
VisualStudio:
()
=>
mockVisualStudio
,
});
testUsingContext
(
'Emits missing status when Visual Studio is not installed'
,
()
async
{
when
(
visualStudio
.
isInstalled
).
thenReturn
(
false
);
_configureMockVisualStudioAsNotInstalled
(
);
const
VisualStudioValidator
validator
=
VisualStudioValidator
();
final
ValidationResult
result
=
await
validator
.
validate
();
final
ValidationMessage
expectedMessage
=
ValidationMessage
.
error
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment