Commit 096a8ac4 authored by Jonah Williams's avatar Jonah Williams Committed by Zachary Anderson

handle format error from vswhere (#43402)

parent 2b272f81
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment