handle format error from vswhere (#43402)
This commit is contained in:
committed by
Zachary Anderson
parent
2b272f8151
commit
096a8ac40a
@@ -208,6 +208,8 @@ class VisualStudio {
|
||||
// Thrown if vswhere doesnt' exist; ignore and return null below.
|
||||
} on ProcessException {
|
||||
// Ignored, return null below.
|
||||
} on FormatException {
|
||||
// may be thrown if invalid JSON is returned.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ void main() {
|
||||
List<String> requiredComponents,
|
||||
List<String> additionalArguments,
|
||||
Map<String, dynamic> response,
|
||||
String responseOverride,
|
||||
]) {
|
||||
fs.file(vswherePath).createSync(recursive: true);
|
||||
fs.file(vcvarsPath).createSync(recursive: true);
|
||||
@@ -78,7 +79,7 @@ void main() {
|
||||
final MockProcessResult result = MockProcessResult();
|
||||
when(result.exitCode).thenReturn(0);
|
||||
|
||||
final String finalResponse =
|
||||
final String finalResponse = responseOverride ??
|
||||
json.encode(<Map<String, dynamic>>[response]);
|
||||
when<String>(result.stdout).thenReturn(finalResponse);
|
||||
when<String>(result.stderr).thenReturn('');
|
||||
@@ -116,10 +117,15 @@ void main() {
|
||||
|
||||
// Sets whether or not a vswhere query searching for 'all' and 'prerelease'
|
||||
// versions will return an installation.
|
||||
void setMockAnyVisualStudioInstallation(Map<String, dynamic>response) {
|
||||
void setMockAnyVisualStudioInstallation(Map<String, dynamic> response) {
|
||||
setMockVswhereResponse(null, <String>['-prerelease', '-all'], response);
|
||||
}
|
||||
|
||||
// Set a pre-encoded query result.
|
||||
void setMockEncodedAnyVisualStudioInstallation(String response) {
|
||||
setMockVswhereResponse(null, <String>['-prerelease', '-all'], null, response);
|
||||
}
|
||||
|
||||
group('Visual Studio', () {
|
||||
VisualStudio visualStudio;
|
||||
|
||||
@@ -393,6 +399,19 @@ void main() {
|
||||
Platform: () => windowsPlatform,
|
||||
});
|
||||
|
||||
testUsingContext('vcvarsPath returns null when VS is present but when vswhere returns invalid JSON', () {
|
||||
setMockCompatibleVisualStudioInstallation(null);
|
||||
setMockPrereleaseVisualStudioInstallation(null);
|
||||
setMockEncodedAnyVisualStudioInstallation('{');
|
||||
|
||||
visualStudio = VisualStudio();
|
||||
expect(visualStudio.vcvarsPath, isNull);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => memoryFilesystem,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Platform: () => windowsPlatform,
|
||||
});
|
||||
|
||||
testUsingContext('Everything returns good values when VS is present with all components', () {
|
||||
setMockCompatibleVisualStudioInstallation(_defaultResponse);
|
||||
setMockPrereleaseVisualStudioInstallation(null);
|
||||
|
||||
Reference in New Issue
Block a user