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

Commit 1feaa03

Browse files
author
Peter Huene
committed
Fix incorrect default VSTest verbosity level.
Commit 1028950 changed the default verbosity option used for MSBuild from `-v:quiet` to `-verbosity:quiet`. This triggered a match that was being done against arguments starting with `-verbosity` to forward the value to VSTest via the `VSTestVerbosity` property. The result is that VSTest is using a default verbosity of `quiet`, suppressing error output that users expect to see. The fix is to change the check to only match against user-supplied options. The default level the command uses for MSBuild is not forwarded to VSTest. Fixes #9229.
1 parent d0bcc1e commit 1feaa03

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/dotnet/ArgumentForwardingExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static IEnumerable<string> OptionValuesToBeForwarded(
3535
.OfType<ForwardedArgument>()
3636
.SelectMany(o => o.Values);
3737

38+
public static IEnumerable<string> ForwardedOptionValues(this AppliedOption command, string alias) =>
39+
(command.ValueOrDefault<ForwardedArgument>(alias)?.Values ?? Array.Empty<string>());
40+
3841
private class ForwardedArgument
3942
{
4043
public ForwardedArgument(params string[] values)

src/dotnet/commands/dotnet-test/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ public static TestCommand FromArgs(string[] args, string msbuildPath = null)
6060
msbuildArgs.Add($"-property:VSTestCLIRunSettings=\"{runSettingsArg}\"");
6161
}
6262

63-
var verbosityArg = msbuildArgs.LastOrDefault(arg => arg.StartsWith("-verbosity"));
64-
65-
if (!string.IsNullOrEmpty(verbosityArg))
63+
var verbosityArg = parsedTest.ForwardedOptionValues("verbosity").SingleOrDefault();
64+
if (verbosityArg != null)
6665
{
67-
var verbosity = verbosityArg.Split(':');
66+
var verbosity = verbosityArg.Split(':', 2);
6867
if (verbosity.Length == 2)
6968
{
7069
msbuildArgs.Add($"-property:VSTestVerbosity={verbosity[1]}");

test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ public void XunitSingleTFM()
110110
result.ExitCode.Should().Be(1);
111111
}
112112

113+
[Fact]
114+
public void GivenAFailingTestItDisplaysFailureDetails()
115+
{
116+
var testInstance = TestAssets.Get("XunitCore")
117+
.CreateInstance()
118+
.WithSourceFiles();
119+
120+
var result = new DotnetTestCommand()
121+
.WithWorkingDirectory(testInstance.Root.FullName)
122+
.ExecuteWithCapturedOutput();
123+
124+
result.ExitCode.Should().Be(1);
125+
126+
if (!DotnetUnderTest.IsLocalized())
127+
{
128+
result.StdOut.Should().Contain("Failed TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
129+
result.StdOut.Should().Contain("Assert.Equal() Failure");
130+
result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
131+
}
132+
}
133+
113134
[Fact]
114135
public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
115136
{

0 commit comments

Comments
 (0)