|
| 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