add tests for checking filename, working dir and validation of presence of environmental variables
This commit is contained in:
parent
8ad8fe7e8e
commit
531b0136eb
6 changed files with 79 additions and 8 deletions
|
@ -113,7 +113,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
int exitCode = app.Execute(args);
|
||||
if (ret._forwardingApp == null)
|
||||
{
|
||||
throw new CodeNotExecutedException(exitCode);
|
||||
throw new CommandCreationException(exitCode);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
{
|
||||
cmd = FromArgs(args);
|
||||
}
|
||||
catch (CodeNotExecutedException e)
|
||||
catch (CommandCreationException e)
|
||||
{
|
||||
return e.ExitCode;
|
||||
}
|
||||
|
@ -146,11 +146,11 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
return GetProcessStartInfo().Execute();
|
||||
}
|
||||
|
||||
private class CodeNotExecutedException : Exception
|
||||
private class CommandCreationException : Exception
|
||||
{
|
||||
public int ExitCode { get; private set; }
|
||||
|
||||
public CodeNotExecutedException(int exitCode)
|
||||
public CommandCreationException(int exitCode)
|
||||
{
|
||||
ExitCode = exitCode;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
||||
|
@ -9,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
|
||||
{
|
||||
this.Skip = "This test requires windows to run";
|
||||
this.Skip = "This test requires non-Windows to run";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public class NonWindowsOnlyTheoryAttribute : TheoryAttribute
|
||||
{
|
||||
public NonWindowsOnlyTheoryAttribute()
|
||||
{
|
||||
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
|
||||
{
|
||||
this.Skip = "This test requires non-Windows to run";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
|
||||
{
|
||||
this.Skip = "This test requires windows to run";
|
||||
this.Skip = "This test requires Windows to run";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
|
@ -9,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
|
||||
{
|
||||
this.Skip = "This test requires windows to run";
|
||||
this.Skip = "This test requires Windows to run";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using Microsoft.DotNet.Tools.Build;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using WindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.WindowsOnlyFactAttribute;
|
||||
using NonWindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.NonWindowsOnlyFactAttribute;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
||||
{
|
||||
|
@ -29,5 +32,48 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|||
BuildCommand.FromArgs(args, msbuildPath)
|
||||
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
||||
}
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void WhenInvokingBuildCommandOnWindowsTheDotnetIsExecuted()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet.exe");
|
||||
}
|
||||
|
||||
[NonWindowsOnlyFact]
|
||||
public void WhenInvokingBuildCommandOnNonWindowsTheDotnetIsExecuted()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().FileName.Should().Be("dotnet");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItSetsEnvironmentVariables()
|
||||
{
|
||||
var expectedEnvironmentalVariables = new HashSet<string> {
|
||||
"MSBuildExtensionsPath",
|
||||
"CscToolExe",
|
||||
"MSBuildSDKsPath",
|
||||
"DOTNET_CLI_TELEMETRY_SESSIONID"
|
||||
};
|
||||
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath).GetProcessStartInfo();
|
||||
|
||||
foreach (var envVarName in expectedEnvironmentalVariables)
|
||||
{
|
||||
startInfo.Environment.ContainsKey(envVarName).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WhenInvokingBuildCommandItDoesNotSetCurrentWorkingDirectory()
|
||||
{
|
||||
var msbuildPath = "<msbuildpath>";
|
||||
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath)
|
||||
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue