diff --git a/src/dotnet/ArgumentForwardingExtensions.cs b/src/dotnet/ArgumentForwardingExtensions.cs index da4a3cdc9..fb2796094 100644 --- a/src/dotnet/ArgumentForwardingExtensions.cs +++ b/src/dotnet/ArgumentForwardingExtensions.cs @@ -35,6 +35,9 @@ namespace Microsoft.DotNet.Cli .OfType() .SelectMany(o => o.Values); + public static IEnumerable ForwardedOptionValues(this AppliedOption command, string alias) => + (command.ValueOrDefault(alias)?.Values ?? Array.Empty()); + private class ForwardedArgument { public ForwardedArgument(params string[] values) diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 95a8f2418..ac7062f03 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -60,11 +60,10 @@ namespace Microsoft.DotNet.Tools.Test msbuildArgs.Add($"-property:VSTestCLIRunSettings=\"{runSettingsArg}\""); } - var verbosityArg = msbuildArgs.LastOrDefault(arg => arg.StartsWith("-verbosity")); - - if (!string.IsNullOrEmpty(verbosityArg)) + var verbosityArg = parsedTest.ForwardedOptionValues("verbosity").SingleOrDefault(); + if (verbosityArg != null) { - var verbosity = verbosityArg.Split(':'); + var verbosity = verbosityArg.Split(':', 2); if (verbosity.Length == 2) { msbuildArgs.Add($"-property:VSTestVerbosity={verbosity[1]}"); diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 3b06797aa..8120df7c9 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -110,6 +110,27 @@ namespace Microsoft.DotNet.Cli.Test.Tests result.ExitCode.Should().Be(1); } + [Fact] + public void GivenAFailingTestItDisplaysFailureDetails() + { + var testInstance = TestAssets.Get("XunitCore") + .CreateInstance() + .WithSourceFiles(); + + var result = new DotnetTestCommand() + .WithWorkingDirectory(testInstance.Root.FullName) + .ExecuteWithCapturedOutput(); + + result.ExitCode.Should().Be(1); + + if (!DotnetUnderTest.IsLocalized()) + { + result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTest"); + result.StdOut.Should().Contain("Assert.Equal() Failure"); + result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0."); + } + } + [Fact] public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven() {