Skip to content

Commit 97b60e2

Browse files
author
Nate McMaster
committed
Fix bug in the Visual Studio requirement check on non-Windows
1 parent d49255f commit 97b60e2

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

modules/KoreBuild.Tasks/GetToolsets.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private void GetVisualStudio(KoreBuildSettings.VisualStudioToolset vsToolset)
8181
{
8282
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
8383
{
84-
if ((vsToolset.Required & KoreBuildSettings.RequiredPlatforms.Windows) != 0)
84+
if ((vsToolset.Required & ~KoreBuildSettings.RequiredPlatforms.Windows) != 0)
8585
{
8686
Log.LogError("Visual Studio is not available on non-Windows. Change korebuild.json to 'required: [\"windows\"]'.");
8787
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Runtime.InteropServices;
7+
using BuildTools.Tasks.Tests;
8+
using Xunit;
9+
10+
namespace KoreBuild.Tasks.Tests
11+
{
12+
public class GetToolsetsTests : IDisposable
13+
{
14+
private readonly string _configFile;
15+
16+
public GetToolsetsTests()
17+
{
18+
_configFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
19+
}
20+
21+
public void Dispose()
22+
{
23+
if (File.Exists(_configFile))
24+
{
25+
File.Delete(_configFile);
26+
}
27+
}
28+
29+
[Fact]
30+
public void GetsToolsetsEvenNotRequired()
31+
{
32+
File.WriteAllText(_configFile, @"
33+
{
34+
""toolsets"": {
35+
""visualstudio"": {
36+
""required"": false
37+
},
38+
""nodejs"": {
39+
""required"": false
40+
}
41+
}
42+
}");
43+
var task = new GetToolsets
44+
{
45+
BuildEngine = new MockEngine(),
46+
ConfigFile = _configFile,
47+
};
48+
49+
Assert.True(task.Execute(), "Task is expected to pass");
50+
}
51+
52+
[Fact]
53+
public void FailsIfVsIsRequiredOnNonWindows()
54+
{
55+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
56+
{
57+
return;
58+
}
59+
60+
File.WriteAllText(_configFile, @"
61+
{
62+
""toolsets"": {
63+
""visualstudio"": {
64+
""required"": [""macos"", ""linux""]
65+
}
66+
}
67+
}");
68+
var task = new GetToolsets
69+
{
70+
BuildEngine = new MockEngine { ContinueOnError = true },
71+
ConfigFile = _configFile,
72+
};
73+
74+
Assert.False(task.Execute(), "Task is expected to fail");
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)