add tests for checking filename, working dir and validation of presence of environmental variables

This commit is contained in:
Krzysztof Wicher 2017-02-15 10:38:41 -08:00
parent 8ad8fe7e8e
commit 531b0136eb
6 changed files with 79 additions and 8 deletions

View file

@ -113,7 +113,7 @@ namespace Microsoft.DotNet.Tools.Build
int exitCode = app.Execute(args); int exitCode = app.Execute(args);
if (ret._forwardingApp == null) if (ret._forwardingApp == null)
{ {
throw new CodeNotExecutedException(exitCode); throw new CommandCreationException(exitCode);
} }
return ret; return ret;
@ -128,7 +128,7 @@ namespace Microsoft.DotNet.Tools.Build
{ {
cmd = FromArgs(args); cmd = FromArgs(args);
} }
catch (CodeNotExecutedException e) catch (CommandCreationException e)
{ {
return e.ExitCode; return e.ExitCode;
} }
@ -146,11 +146,11 @@ namespace Microsoft.DotNet.Tools.Build
return GetProcessStartInfo().Execute(); return GetProcessStartInfo().Execute();
} }
private class CodeNotExecutedException : Exception private class CommandCreationException : Exception
{ {
public int ExitCode { get; private set; } public int ExitCode { get; private set; }
public CodeNotExecutedException(int exitCode) public CommandCreationException(int exitCode)
{ {
ExitCode = exitCode; ExitCode = exitCode;
} }

View file

@ -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 Microsoft.DotNet.PlatformAbstractions;
using Xunit; using Xunit;
@ -9,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform == Platform.Windows)
{ {
this.Skip = "This test requires windows to run"; this.Skip = "This test requires non-Windows to run";
} }
} }
} }

View file

@ -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";
}
}
}
}

View file

@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
this.Skip = "This test requires windows to run"; this.Skip = "This test requires Windows to run";
} }
} }
} }

View file

@ -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; using Xunit;
namespace Microsoft.DotNet.Tools.Test.Utilities namespace Microsoft.DotNet.Tools.Test.Utilities
@ -9,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{ {
if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows)
{ {
this.Skip = "This test requires windows to run"; this.Skip = "This test requires Windows to run";
} }
} }
} }

View file

@ -1,6 +1,9 @@
using Microsoft.DotNet.Tools.Build; using Microsoft.DotNet.Tools.Build;
using FluentAssertions; using FluentAssertions;
using Xunit; 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 namespace Microsoft.DotNet.Cli.MSBuild.Tests
{ {
@ -29,5 +32,48 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
BuildCommand.FromArgs(args, msbuildPath) BuildCommand.FromArgs(args, msbuildPath)
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand); .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("");
}
} }
} }