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 { ...@@ -208,6 +208,8 @@ class VisualStudio {
// Thrown if vswhere doesnt' exist; ignore and return null below. // Thrown if vswhere doesnt' exist; ignore and return null below.
} on ProcessException { } on ProcessException {
// Ignored, return null below. // Ignored, return null below.
} on FormatException {
// may be thrown if invalid JSON is returned.
} }
return null; return null;
} }
......
...@@ -71,6 +71,7 @@ void main() { ...@@ -71,6 +71,7 @@ void main() {
List<String> requiredComponents, List<String> requiredComponents,
List<String> additionalArguments, List<String> additionalArguments,
Map<String, dynamic> response, Map<String, dynamic> response,
String responseOverride,
]) { ]) {
fs.file(vswherePath).createSync(recursive: true); fs.file(vswherePath).createSync(recursive: true);
fs.file(vcvarsPath).createSync(recursive: true); fs.file(vcvarsPath).createSync(recursive: true);
...@@ -78,7 +79,7 @@ void main() { ...@@ -78,7 +79,7 @@ void main() {
final MockProcessResult result = MockProcessResult(); final MockProcessResult result = MockProcessResult();
when(result.exitCode).thenReturn(0); when(result.exitCode).thenReturn(0);
final String finalResponse = final String finalResponse = responseOverride ??
json.encode(<Map<String, dynamic>>[response]); json.encode(<Map<String, dynamic>>[response]);
when<String>(result.stdout).thenReturn(finalResponse); when<String>(result.stdout).thenReturn(finalResponse);
when<String>(result.stderr).thenReturn(''); when<String>(result.stderr).thenReturn('');
...@@ -116,10 +117,15 @@ void main() { ...@@ -116,10 +117,15 @@ void main() {
// Sets whether or not a vswhere query searching for 'all' and 'prerelease' // Sets whether or not a vswhere query searching for 'all' and 'prerelease'
// versions will return an installation. // versions will return an installation.
void setMockAnyVisualStudioInstallation(Map<String, dynamic>response) { void setMockAnyVisualStudioInstallation(Map<String, dynamic> response) {
setMockVswhereResponse(null, <String>['-prerelease', '-all'], 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', () { group('Visual Studio', () {
VisualStudio visualStudio; VisualStudio visualStudio;
...@@ -393,6 +399,19 @@ void main() { ...@@ -393,6 +399,19 @@ void main() {
Platform: () => windowsPlatform, 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', () { testUsingContext('Everything returns good values when VS is present with all components', () {
setMockCompatibleVisualStudioInstallation(_defaultResponse); setMockCompatibleVisualStudioInstallation(_defaultResponse);
setMockPrereleaseVisualStudioInstallation(null); 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