dotnet test and publish failing badly when the project isn't restored.
Fixing this by checking for diagnostic errors before continuing. Fix #2692 Fix #2942
This commit is contained in:
parent
0336f6bb34
commit
652d0541ef
18 changed files with 168 additions and 42 deletions
|
@ -16,5 +16,11 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
args = $"test {args}";
|
||||
return base.Execute(args);
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"test {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -372,5 +372,21 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
.Should()
|
||||
.Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishFailsCorrectlyWithUnrestoredProject()
|
||||
{
|
||||
// NOTE: we don't say "WithLockFiles", so the project is "unrestored"
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppSimple");
|
||||
|
||||
new PublishCommand(instance.TestRoot)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Fail()
|
||||
.And
|
||||
.HaveStdErrContaining("NU1009")
|
||||
.And
|
||||
.HaveStdErrContaining("dotnet restore");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,35 @@ namespace Microsoft.DotNet.Tools.Run.Tests
|
|||
"arg: [two]"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItHandlesUnrestoredProjectFileCorrectly()
|
||||
{
|
||||
// NOTE: we don't say "WithLockFiles", so the project is "unrestored"
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppSimple");
|
||||
|
||||
new RunCommand(instance.TestRoot)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Fail()
|
||||
.And
|
||||
.HaveStdErrContaining("NU1009")
|
||||
.And
|
||||
.HaveStdErrContaining("dotnet restore");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItHandlesUnknownProjectFileCorrectly()
|
||||
{
|
||||
new RunCommand("bad path")
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Fail()
|
||||
.And
|
||||
.HaveStdErrContaining("DOTNET1017")
|
||||
.And
|
||||
.HaveStdErrContaining("bad path");
|
||||
}
|
||||
|
||||
private static string JoinWithNewlines(params string[] values)
|
||||
{
|
||||
return string.Join(Environment.NewLine, values);
|
||||
|
|
29
test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs
Normal file
29
test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
// 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 System.IO;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenThatWeWantToRunTests : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void It_fails_correctly_with_an_unrestored_project()
|
||||
{
|
||||
// NOTE: we don't say "WithLockFiles", so the project is "unrestored"
|
||||
var instance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "NetCoreAppOnlyProject"));
|
||||
|
||||
new DotnetTestCommand()
|
||||
.ExecuteWithCapturedOutput(instance.TestRoot)
|
||||
.Should()
|
||||
.Fail()
|
||||
.And
|
||||
.HaveStdErrContaining("NU1009")
|
||||
.And
|
||||
.HaveStdErrContaining("dotnet restore");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
{
|
||||
var testCommand = new DotnetTestCommand();
|
||||
var result = testCommand
|
||||
.ExecuteWithCapturedOutput($"test {_projectFilePath}");
|
||||
.ExecuteWithCapturedOutput($"{_projectFilePath}");
|
||||
result.Should().Pass();
|
||||
result.StdOut.Should().Contain("Skipped for NET451");
|
||||
result.StdOut.Should().Contain("Skipped for NETCOREAPP1.0");
|
||||
|
@ -55,7 +55,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
{
|
||||
var testCommand = new DotnetTestCommand();
|
||||
var result = testCommand
|
||||
.ExecuteWithCapturedOutput($"test {_projectFilePath} -f net451");
|
||||
.ExecuteWithCapturedOutput($"{_projectFilePath} -f net451");
|
||||
result.Should().Pass();
|
||||
result.StdOut.Should().Contain($"Skipped for NET451");
|
||||
result.StdOut.Should().NotContain($"Skipped for NETCOREAPP1.0");
|
||||
|
@ -66,7 +66,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
{
|
||||
var testCommand = new DotnetTestCommand();
|
||||
var result = testCommand
|
||||
.ExecuteWithCapturedOutput($"test {_projectFilePath} -f netcoreapp1.0");
|
||||
.ExecuteWithCapturedOutput($"{_projectFilePath} -f netcoreapp1.0");
|
||||
result.Should().Pass();
|
||||
result.StdOut.Should().Contain($"Skipped for NETCOREAPP1.0");
|
||||
result.StdOut.Should().NotContain($"Skipped for NET451");
|
||||
|
@ -121,7 +121,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
var nonExistentFramework = "doesnotexisttfm99.99";
|
||||
var testCommand = new DotnetTestCommand();
|
||||
var result = testCommand
|
||||
.ExecuteWithCapturedOutput($"test {_projectFilePath} -f {nonExistentFramework}");
|
||||
.ExecuteWithCapturedOutput($"{_projectFilePath} -f {nonExistentFramework}");
|
||||
|
||||
result.Should().Fail();
|
||||
result.StdErr.Should().Contain($"does not support framework");
|
||||
|
@ -139,7 +139,7 @@ namespace Microsoft.Dotnet.Tools.Test.Tests
|
|||
};
|
||||
|
||||
var result = testCommand
|
||||
.ExecuteWithCapturedOutput($"test {_projectFilePath}");
|
||||
.ExecuteWithCapturedOutput($"{_projectFilePath}");
|
||||
|
||||
result.Should().Fail();
|
||||
result.StdOut.Should().Contain("Failing in NET451");
|
||||
|
|
|
@ -188,7 +188,7 @@ namespace Microsoft.DotNet.Tests
|
|||
{
|
||||
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
|
||||
|
||||
result.StdOut.Should().Contain("No executable found matching command");
|
||||
result.StdErr.Should().Contain("No executable found matching command");
|
||||
result.Should().Fail();
|
||||
}
|
||||
finally
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue