Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fixing a bug in the restore option where specifying verbosity through…
Browse files Browse the repository at this point in the history
… /v was not entirely honored.

Adding tests for implicit restore for all the affected commands.

Fixing an issue where the command target was being passed to the restore command during implicit restore.
  • Loading branch information
livarcocc committed Jun 5, 2017
1 parent bcc202b commit ee032de
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 11 deletions.
16 changes: 13 additions & 3 deletions src/dotnet/commands/RestoringCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public class RestoringCommand : MSBuildForwardingApp

private IEnumerable<string> ArgsToForward { get; }

private IEnumerable<string> ArgsToForwardToRestore
{
get
{
var restoreArguments = ArgsToForward.Where(a => !a.Contains("/t:"));

return restoreArguments;
}
}

private bool ShouldRunImplicitRestore => !NoRestore;

public RestoringCommand(IEnumerable<string> msbuildArgs, bool noRestore, string msbuildPath = null)
: base(msbuildArgs, msbuildPath)
{
Expand All @@ -25,7 +37,7 @@ public override int Execute()
{
if (ShouldRunImplicitRestore)
{
int exitCode = RestoreCommand.Run(ArgsToForward.ToArray());
int exitCode = RestoreCommand.Run(ArgsToForwardToRestore.ToArray());
if (exitCode != 0)
{
return exitCode;
Expand All @@ -34,7 +46,5 @@ public override int Execute()

return base.Execute();
}

private bool ShouldRunImplicitRestore => !NoRestore;
}
}
9 changes: 8 additions & 1 deletion src/dotnet/commands/dotnet-restore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static RestoreCommand FromArgs(string[] args, string msbuildPath = null)
"/t:Restore"
};

if (!parsedRestore.HasOption("verbosity"))
if (!HasVerbosityOption(parsedRestore))
{
msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal");
}
Expand All @@ -46,6 +46,8 @@ public static RestoreCommand FromArgs(string[] args, string msbuildPath = null)

msbuildArgs.AddRange(parsedRestore.Arguments);

string m = string.Join(",", msbuildArgs);

return new RestoreCommand(msbuildArgs, msbuildPath);
}

Expand All @@ -65,5 +67,10 @@ public static int Run(string[] args)

return cmd.Execute();
}

private static bool HasVerbosityOption(AppliedOption parsedRestore)
{
return parsedRestore.HasOption("verbosity") || parsedRestore.Arguments.Any(a => a.Contains("/v:"));
}
}
}
16 changes: 15 additions & 1 deletion test/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public void ItBuildsARunnableOutput()
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void ItImplicitlyRestoresAProjectWhenBuilding()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance(testAppName)
.WithSourceFiles();

new BuildCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}

[Fact]
public void ItRunsWhenRestoringToSpecificPackageDir()
{
Expand All @@ -62,7 +76,7 @@ public void ItRunsWhenRestoringToSpecificPackageDir()

new BuildCommand()
.WithWorkingDirectory(rootPath)
.Execute()
.Execute("--no-restore")
.Should().Pass();

var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
Expand Down
17 changes: 15 additions & 2 deletions test/dotnet-pack.Tests/PackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void PackAddsCorrectFilesForProjectsWithOutputNameSpecified()
}

[Fact]
public void PackWorksWithLocalProjectJson()
public void PackWorksWithLocalProject()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
Expand All @@ -171,6 +171,19 @@ public void PackWorksWithLocalProjectJson()
.Should().Pass();
}

[Fact]
public void ItImplicitlyRestoresAProjectWhenPacking()
{
var testInstance = TestAssets.Get("TestAppSimple")
.CreateInstance()
.WithSourceFiles();

new PackCommand()
.WithWorkingDirectory(testInstance.Root)
.Execute()
.Should().Pass();
}

[Fact]
public void HasServiceableFlagWhenArgumentPassed()
{
Expand Down Expand Up @@ -231,7 +244,7 @@ public void ItPacksAppWhenRestoringToSpecificPackageDirectory()

new PackCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass();

Expand Down
18 changes: 17 additions & 1 deletion test/dotnet-publish.Tests/GivenDotnetPublishPublishesProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ public void ItPublishesARunnablePortableApp()
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void ItImplicitlyRestoresAProjectWhenPublishing()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();

var testProjectDirectory = testInstance.Root.FullName;

new PublishCommand()
.WithWorkingDirectory(testProjectDirectory)
.Execute("--framework netcoreapp2.0")
.Should().Pass();
}

[Fact]
public void ItPublishesARunnableSelfContainedApp()
{
Expand Down Expand Up @@ -170,7 +186,7 @@ public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()

new PublishCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass();

var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
Expand Down
19 changes: 18 additions & 1 deletion test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public void ItCanRunAMSBuildProject()
.And.HaveStdOutContaining("Hello World!");
}

[Fact]
public void ItImplicitlyRestoresAProjectWhenRunning()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();

var testProjectDirectory = testInstance.Root.FullName;

new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput()
.Should().Pass()
.And.HaveStdOutContaining("Hello World!");
}

[Fact]
public void ItBuildsTheProjectBeforeRunning()
{
Expand Down Expand Up @@ -160,7 +177,7 @@ public void ItRunsAppWhenRestoringToSpecificPackageDirectory()

new RunCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should().Pass()
.And.HaveStdOutContaining("Hello World");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ public void MSTestSingleTFM()
result.ExitCode.Should().Be(1);
}

[Fact]
public void ItImplicitlyRestoresAProjectWhenTesting()
{
string testAppName = "VSTestCore";
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();

var testProjectDirectory = testInstance.Root.FullName;

CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
result.StdOut.Should().Contain("Failed TestNamespace.VSTestTests.VSTestFailTest");
result.ExitCode.Should().Be(1);
}

[Fact]
public void XunitSingleTFM()
{
Expand Down Expand Up @@ -161,14 +181,14 @@ public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()

new BuildCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput()
.ExecuteWithCapturedOutput("--no-restore")
.Should()
.Pass()
.And.NotHaveStdErr();

CommandResult result = new DotnetTestCommand()
.WithWorkingDirectory(rootPath)
.ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);
.ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-restore");

result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
result.StdOut.Should().Contain("Passed TestNamespace.VSTestTests.VSTestPassTest");
Expand Down Expand Up @@ -209,6 +229,7 @@ private string CopyAndRestoreVSTestDotNetCoreTestApp([CallerMemberName] string c
.Execute()
.Should()
.Pass();

return testProjectDirectory;
}
}
Expand Down

0 comments on commit ee032de

Please sign in to comment.