Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ private static bool IsValidShowOutputArgument(string argument)
|| ShowOutputNoneArgument.Equals(argument, StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Resolves <c>--show-test-results</c>, returning <see langword="null"/> when the option is absent so the
/// caller (<c>TerminalOutputDevice.InitializeAsync</c>) can fall back to its <c>--output</c>-based default.
/// Resolves <c>--show-test-results</c> or its passive configuration default, returning <see langword="null"/>
/// when neither is present so the caller (<c>TerminalOutputDevice.InitializeAsync</c>) can fall back to its
/// <c>--output</c>-based default.
/// Arguments are already guaranteed valid by <see cref="ValidateOptionArgumentsAsync"/> by the time a real run
/// reaches this method; an unexpected parse failure therefore indicates that command-line validation was
/// bypassed and is reported as an invalid application state.
/// </summary>
internal static TestResultVisibility? GetShowTestResultsVisibility(ICommandLineOptions commandLineOptions)
=> !commandLineOptions.TryGetOptionArgumentList(ShowTestResultsOption, out string[]? arguments)
=> !commandLineOptions.TryGetOptionArgumentListOrDefault(ShowTestResultsOption, out string[]? arguments)
? null
: TryParseShowTestResultsArguments(arguments ?? [], out TestResultVisibility visibility, out _)
? visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,17 @@ string s when TerminalTestReporterCommandLineOptionsProvider.ShowOutputNoneArgum
}
: isLLMEnvironment ? OutputShowMode.Failed : OutputShowMode.All;

// Resolves which per-test terminal blocks are rendered. An explicit --show-test-results always wins over
// --output, regardless of the order the two options appear on the command line (only --show-test-results is
// consulted for the override, via TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility).
// Absent --show-test-results, 'minimal' shows only failed results, 'detailed' shows every outcome, and
// everything else (including no --output at all) shows failed and skipped results (passed tests stay hidden).
// Resolves which per-test terminal blocks are rendered. An explicit --show-test-results value or its passive
// configuration default wins over --output; an explicit value wins over the passive default. When neither is
// present, 'minimal' shows only failed results, 'detailed' shows every outcome, and everything else (including
// no --output at all) shows failed and skipped results (passed tests stay hidden).
// Internal for unit testing the parse seam that feeds
// TerminalTestReporterOptions.ShowTestResults.
internal static TestResultVisibility GetShowTestResultsVisibility(ICommandLineOptions commandLineOptions)
{
if (TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility(commandLineOptions) is { } explicitVisibility)
if (TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility(commandLineOptions) is { } configuredVisibility)
{
return explicitVisibility;
return configuredVisibility;
}

string? outputArgument = commandLineOptions.TryGetOptionArgumentList(TerminalTestReporterCommandLineOptionsProvider.OutputOption, out string[]? outputArguments)
Expand Down
9 changes: 6 additions & 3 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<TestingPlatformCommandLineArguments Condition=" '$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' == '.NETCoreApp' ">$(TestingPlatformCommandLineArguments) --crashdump</TestingPlatformCommandLineArguments>
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --hangdump --hangdump-timeout 15m</TestingPlatformCommandLineArguments>
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --report-azdo</TestingPlatformCommandLineArguments>
<!-- Keep test output focused on actionable per-test results. Skipped tests remain included in summaries
and report files; only their terminal result blocks are suppressed. -->
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --show-test-results failed</TestingPlatformCommandLineArguments>
<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --report-ctrf --report-ctrf-filename $(MSBuildProjectName)_$(TargetFramework).ctrf.json</TestingPlatformCommandLineArguments>
<!-- The report-azdo-summary option implements ITestSessionLifetimeHandler and emits a warning on the
output device when TF_BUILD is not 'true', unlike the silent report-azdo. Gate it on $(TF_BUILD)
Expand Down Expand Up @@ -51,6 +48,12 @@

</PropertyGroup>

<ItemGroup>
<!-- Persist this preference into each test host so direct solution and test-module runs also honor it.
Explicit command-line values can still override the default. Skipped tests remain in summaries and reports. -->
<TestingPlatformCommandLineOptionDefault Include="show-test-results" Value="failed" />
</ItemGroup>

<PropertyGroup Condition="'$(UsingDotNetTest)'=='true'">
<!-- By default, Arcade already adds report-trx, report-trx-filename, and results-directory -->
<!-- However, when we run with dotnet test, we need to add these options, but still don't duplicate them on Arcade -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@

namespace Microsoft.Testing.Platform.UnitTests.Helpers;

internal class TestCommandLineOptions : ICommandLineOptions
internal class TestCommandLineOptions : ICommandLineOptions, ICommandLineOptionsWithDefaults
{
private readonly Dictionary<string, string[]> _options;
private readonly Dictionary<string, string[]> _defaults;

public TestCommandLineOptions(Dictionary<string, string[]> options) => _options = options;
public TestCommandLineOptions(Dictionary<string, string[]> options)
: this(options, [])
{
}

public TestCommandLineOptions(Dictionary<string, string[]> options, Dictionary<string, string[]> defaults)
{
_options = options;
_defaults = defaults;
}

public bool IsOptionSet(string optionName) => _options.ContainsKey(optionName);

public bool TryGetOptionArgumentList(string optionName, [NotNullWhen(true)] out string[]? arguments) => _options.TryGetValue(optionName, out arguments);

bool ICommandLineOptionsWithDefaults.TryGetOptionArgumentListOrDefault(string optionName, [NotNullWhen(true)] out string[]? arguments)
=> _options.TryGetValue(optionName, out arguments) || _defaults.TryGetValue(optionName, out arguments);
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,35 @@ public void GetShowTestResultsVisibility_WhenOptionPresent_ReturnsParsedFlags()
Assert.AreEqual(TestResultVisibility.Passed | TestResultVisibility.Skipped, TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility(options));
}

[TestMethod]
public void GetShowTestResultsVisibility_WhenPassiveDefaultPresent_ReturnsParsedFlags()
{
var options = new Helpers.TestCommandLineOptions(
[],
new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.ShowTestResultsOption] = ["failed"],
});

Assert.AreEqual(TestResultVisibility.Failed, TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility(options));
}

[TestMethod]
public void GetShowTestResultsVisibility_WhenOptionAndPassiveDefaultPresent_OptionWins()
{
var options = new Helpers.TestCommandLineOptions(
new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.ShowTestResultsOption] = ["skipped"],
},
new Dictionary<string, string[]>
{
[TerminalTestReporterCommandLineOptionsProvider.ShowTestResultsOption] = ["failed"],
});

Assert.AreEqual(TestResultVisibility.Skipped, TerminalTestReporterCommandLineOptionsProvider.GetShowTestResultsVisibility(options));
}

[TestMethod]
public void GetShowTestResultsVisibility_WhenPresentValueWasNotValidated_Throws()
{
Expand All @@ -438,10 +467,10 @@ public void GetShowTestResultsVisibility_WhenPresentValueWasNotValidated_Throws(
Assert.AreEqual("The --show-test-results option was not validated.", exception.Message);
}

// TerminalOutputDevice.GetShowTestResultsVisibility resolution/precedence: an explicit --show-test-results
// always wins over --output; absent it, --output's 'Minimal' maps to 'failed', 'Detailed' maps to 'all', and
// everything else (including no --output at all) maps to 'failed'+'skipped'. Since both options are read independently by name from the
// same options bag, the resolution cannot depend on which one a user typed first on the command line.
// TerminalOutputDevice.GetShowTestResultsVisibility resolution/precedence: an explicit or passive-default
// --show-test-results value wins over --output; absent both, --output's 'Minimal' maps to 'failed', 'Detailed'
// maps to 'all', and everything else (including no --output at all) maps to 'failed'+'skipped'. Since both
// options are read independently by name from the same options bag, resolution cannot depend on CLI order.
//
// Comparisons cast to int: TerminalOutputDevice itself is not compiled into this test project (only the
// OutputDevice\Terminal folder is, via the Compile Include in the .csproj), so its return value is the
Expand Down
Loading