2017-02-14 18:41:58 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Build;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Xunit;
|
2017-02-15 18:38:41 +00:00
|
|
|
|
using WindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.WindowsOnlyFactAttribute;
|
|
|
|
|
using NonWindowsOnlyFactAttribute = Microsoft.DotNet.Tools.Test.Utilities.NonWindowsOnlyFactAttribute;
|
|
|
|
|
using System.Collections.Generic;
|
2017-02-14 18:41:58 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenDotnetBuildInvocation
|
|
|
|
|
{
|
2017-02-14 19:38:01 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(new string[] { }, @"exec <msbuildpath> /m /v:m /t:Build /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-o", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--output", "foo" }, @"exec <msbuildpath> /m /v:m /t:Build /p:OutputPath=foo /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-o", "foo1 foo2" }, @"exec <msbuildpath> /m /v:m /t:Build ""/p:OutputPath=foo1 foo2"" /clp:Summary")]
|
2017-02-15 00:23:33 +00:00
|
|
|
|
[InlineData(new string[] { "--no-incremental" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-f", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--framework", "framework" }, @"exec <msbuildpath> /m /v:m /t:Build /p:TargetFramework=framework /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-r", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--runtime", "runtime" }, @"exec <msbuildpath> /m /v:m /t:Build /p:RuntimeIdentifier=runtime /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-c", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--configuration", "configuration" }, @"exec <msbuildpath> /m /v:m /t:Build /p:Configuration=configuration /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--version-suffix", "mysuffix" }, @"exec <msbuildpath> /m /v:m /t:Build /p:VersionSuffix=mysuffix /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--no-dependencies" }, @"exec <msbuildpath> /m /v:m /t:Build /p:BuildProjectReferences=false /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "-v", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--verbosity", "verbosity" }, @"exec <msbuildpath> /m /v:m /t:Build /verbosity:verbosity /clp:Summary")]
|
|
|
|
|
[InlineData(new string[] { "--no-incremental", "-o", "myoutput", "-r", "myruntime", "-v", "diag" }, @"exec <msbuildpath> /m /v:m /t:Rebuild /p:OutputPath=myoutput /p:RuntimeIdentifier=myruntime /verbosity:diag /clp:Summary")]
|
|
|
|
|
public void WhenArgsArePassedThenMsbuildInvocationIsCorrect(string[] args, string expectedCommand)
|
2017-02-14 18:41:58 +00:00
|
|
|
|
{
|
2017-02-14 19:38:01 +00:00
|
|
|
|
var msbuildPath = "<msbuildpath>";
|
|
|
|
|
BuildCommand.FromArgs(args, msbuildPath)
|
|
|
|
|
.GetProcessStartInfo().Arguments.Should().Be(expectedCommand);
|
2017-02-14 18:41:58 +00:00
|
|
|
|
}
|
2017-02-15 18:38:41 +00:00
|
|
|
|
|
|
|
|
|
[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");
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-15 20:28:13 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("MSBuildExtensionsPath", "(?i)[\\/\\\\]netcoreapp[0-9]\\.[0-9]([\\/\\\\]|$)")]
|
|
|
|
|
[InlineData("CscToolExe", "(?i)[\\/\\\\](run)?csc(\\.|$)")]
|
|
|
|
|
[InlineData("MSBuildSDKsPath", "(?i)[\\/\\\\]\\d\\.\\d\\.\\d\\-[a-z]+\\-\\d+[\\/\\\\]sdks(\\/|\\\\|$)")]
|
|
|
|
|
[InlineData("DOTNET_CLI_TELEMETRY_SESSIONID", "(^$|\\d+)")]
|
|
|
|
|
public void WhenInvokingBuildCommandItSetsEnvironmentVariables(string envVarName, string envVarPattern)
|
2017-02-15 18:38:41 +00:00
|
|
|
|
{
|
|
|
|
|
var msbuildPath = "<msbuildpath>";
|
|
|
|
|
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath).GetProcessStartInfo();
|
|
|
|
|
|
2017-02-15 20:28:13 +00:00
|
|
|
|
startInfo.Environment.ContainsKey(envVarName).Should().BeTrue();
|
|
|
|
|
(startInfo.Environment[envVarName] ?? "").Should().MatchRegex(envVarPattern);
|
2017-02-15 18:38:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void WhenInvokingBuildCommandItDoesNotSetCurrentWorkingDirectory()
|
|
|
|
|
{
|
|
|
|
|
var msbuildPath = "<msbuildpath>";
|
|
|
|
|
var startInfo = BuildCommand.FromArgs(new string[0], msbuildPath)
|
|
|
|
|
.GetProcessStartInfo().WorkingDirectory.Should().Be("");
|
|
|
|
|
}
|
2017-02-14 18:41:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|