Make --no-build imply --no-restore for pack command.

This commit makes the `--no-build` option for the pack command
automatically imply `--no-restore`.

Fixes issue #7472.
This commit is contained in:
Peter Huene 2017-11-27 21:01:26 -08:00
parent de10b22bcd
commit 40b0e0fcec
18 changed files with 57 additions and 29 deletions

View file

@ -69,6 +69,13 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> NotHaveStdOutContaining(string pattern)
{
Execute.Assertion.ForCondition(!_commandResult.StdOut.Contains(pattern))
.FailWith(AppendDiagnosticsTo($"The command output contained a result it should not have contained: {pattern}{Environment.NewLine}"));
return new AndConstraint<CommandResultAssertions>(this);
}
public AndConstraint<CommandResultAssertions> HaveStdOutMatching(string pattern, RegexOptions options = RegexOptions.None)
{
Execute.Assertion.ForCondition(Regex.Match(_commandResult.StdOut, pattern, options).Success)

View file

@ -12,6 +12,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
public class GivenDotnetPackInvocation
{
const string ExpectedPrefix = "exec <msbuildpath> /m /v:m /restore /t:pack";
const string ExpectedNoBuildPrefix = "exec <msbuildpath> /m /v:m /t:pack";
[Theory]
[InlineData(new string[] { }, "")]
@ -34,9 +35,10 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
var msbuildPath = "<msbuildpath>";
var command = PackCommand.FromArgs(args, msbuildPath);
var expectedPrefix = args.FirstOrDefault() == "--no-build" ? ExpectedNoBuildPrefix : ExpectedPrefix;
command.SeparateRestoreCommand.Should().BeNull();
command.GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}");
command.GetProcessStartInfo().Arguments.Should().Be($"{expectedPrefix}{expectedAdditionalArgs}");
}
}
}

View file

@ -186,6 +186,25 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
.Should().Pass();
}
[Fact]
public void ItDoesNotImplicitlyBuildAProjectWhenPackagingWithTheNoBuildOption()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();
var result = new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.ExecuteWithCapturedOutput("--no-build");
result.Should().Fail();
if (!DotnetUnderTest.IsLocalized())
{
result.Should().NotHaveStdOutContaining("Restore")
.And.HaveStdOutContaining("project.assets.json");
}
}
[Fact]
public void ItDoesNotImplicitlyRestoreAProjectWhenPackagingWithTheNoRestoreOption()
{