2016-10-29 19:08:52 +00:00
|
|
|
|
// 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.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.MSBuild.IntegrationTests
|
|
|
|
|
{
|
|
|
|
|
public class GivenDotnetInvokesMSBuild : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("build")]
|
|
|
|
|
[InlineData("clean")]
|
|
|
|
|
[InlineData("msbuild")]
|
|
|
|
|
[InlineData("pack")]
|
|
|
|
|
[InlineData("publish")]
|
|
|
|
|
[InlineData("test")]
|
|
|
|
|
public void When_dotnet_command_invokes_msbuild_Then_env_vars_and_m_are_passed(string command)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
|
|
|
|
.CreateInstance(identifier: command)
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.Execute(command)
|
|
|
|
|
.Should().Pass();
|
|
|
|
|
}
|
2016-11-15 19:56:39 +00:00
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("build")]
|
2016-11-24 07:54:44 +00:00
|
|
|
|
[InlineData("msbuild")]
|
2016-11-15 19:56:39 +00:00
|
|
|
|
[InlineData("pack")]
|
|
|
|
|
[InlineData("publish")]
|
|
|
|
|
public void When_dotnet_command_invokes_msbuild_with_no_args_verbosity_is_set_to_minimum(string command)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
|
|
|
|
.CreateInstance(identifier: command)
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput(command);
|
2016-11-24 07:54:44 +00:00
|
|
|
|
|
2016-11-15 19:56:39 +00:00
|
|
|
|
cmd.Should().Pass();
|
2016-11-24 07:54:44 +00:00
|
|
|
|
|
|
|
|
|
cmd.StdOut
|
|
|
|
|
.Should().NotContain("Message with normal importance", "Because verbosity is set to minimum")
|
|
|
|
|
.And.Contain("Message with high importance", "Because high importance messages are shown on minimum verbosity");
|
2016-11-15 19:56:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("build")]
|
|
|
|
|
[InlineData("clean")]
|
|
|
|
|
[InlineData("pack")]
|
|
|
|
|
[InlineData("publish")]
|
|
|
|
|
public void When_dotnet_command_invokes_msbuild_with_diag_verbosity_Then_arg_is_passed(string command)
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
|
|
|
|
.CreateInstance(identifier: command)
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.ExecuteWithCapturedOutput($"{command} -v diag");
|
2016-11-24 07:54:44 +00:00
|
|
|
|
|
2016-11-15 19:56:39 +00:00
|
|
|
|
cmd.Should().Pass();
|
2016-11-24 07:54:44 +00:00
|
|
|
|
|
2016-11-15 19:56:39 +00:00
|
|
|
|
cmd.StdOut.Should().Contain("Message with low importance");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void When_dotnet_test_invokes_msbuild_with_no_args_verbosity_is_set_to_quiet()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
2016-11-24 07:54:44 +00:00
|
|
|
|
.CreateInstance()
|
2016-11-15 19:56:39 +00:00
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2016-11-24 07:54:44 +00:00
|
|
|
|
.ExecuteWithCapturedOutput("test");
|
|
|
|
|
|
2016-11-15 19:56:39 +00:00
|
|
|
|
cmd.Should().Pass();
|
|
|
|
|
cmd.StdOut.Should().NotContain("Message with high importance");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void When_dotnet_msbuild_command_is_invoked_with_non_msbuild_switch_Then_it_fails()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
2016-11-24 07:54:44 +00:00
|
|
|
|
.CreateInstance()
|
2016-11-15 19:56:39 +00:00
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
2016-11-24 07:54:44 +00:00
|
|
|
|
.ExecuteWithCapturedOutput($"msbuild -v diag");
|
|
|
|
|
|
2016-11-15 19:56:39 +00:00
|
|
|
|
cmd.ExitCode.Should().NotBe(0);
|
|
|
|
|
}
|
2016-12-01 22:45:55 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void When_MSBuildSDKsPath_is_set_by_env_var_then_it_is_not_overridden()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssets.Get("MSBuildIntegration")
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new DotnetCommand()
|
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
|
.WithEnvironmentVariable("MSBuildSDKsPath", "AnyString")
|
|
|
|
|
.ExecuteWithCapturedOutput($"msbuild");
|
|
|
|
|
|
|
|
|
|
cmd.ExitCode.Should().NotBe(0);
|
|
|
|
|
|
|
|
|
|
cmd.StdOut.Should().Contain("Expected 'AnyString")
|
|
|
|
|
.And.Contain("to exist, but it does not.");
|
|
|
|
|
}
|
2016-10-29 19:08:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|