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 @@ -454,6 +454,24 @@ This is equivalent to deleting project.assets.json.</value>
<data name="CmdListTestsDescription" xml:space="preserve">
<value>List the discovered tests instead of running the tests. Optionally accepts a format: 'text' (default) for human-readable output or 'json' for machine-readable output.</value>
</data>
<data name="CmdAffectedTestsFeatureDisabled" xml:space="preserve">
<value>Affected-test selection is experimental. Set the '{0}' environment variable to '1' to enable it.</value>
</data>
<data name="CmdAffectedTestsOptionsMutuallyExclusive" xml:space="preserve">
<value>The options '--collect-test-map' and '--affected-tests' cannot be used together.</value>
</data>
<data name="CmdCollectTestMapDescription" xml:space="preserve">
<value>Run tests and write the source-to-test map used by affected-test selection.</value>
</data>
<data name="CmdCollectTestMapCannotRunModulesInParallel" xml:space="preserve">
<value>The option '--collect-test-map' cannot be combined with '--max-parallel-test-modules'. Test maps are collected one module at a time.</value>
</data>
<data name="CmdCollectTestMapCannotRequireMinimumTests" xml:space="preserve">
<value>The option '--collect-test-map' cannot be combined with '--minimum-expected-tests'. Collection batches do not report test totals to the parent process.</value>
</data>
<data name="CmdAffectedTestsDescription" xml:space="preserve">
<value>Run only tests linked in the test map to sources changed in Git.</value>
</data>
<data name="CmdLockedModeOptionDescription" xml:space="preserve">
<value>Don't allow updating project lock file.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text.RegularExpressions;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Help;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Cli.Commands.Test;

Expand Down Expand Up @@ -181,6 +182,18 @@ public sealed partial class MicrosoftTestingPlatform : TestCommandDefinition, IC
Arity = ArgumentArity.Zero
};

public const string EnableAffectedTestsEnvironmentVariable = "DOTNET_CLI_ENABLE_AFFECTED_TESTS";

public const string CollectTestMapOptionName = "--collect-test-map";

public readonly Option<bool> CollectTestMapOption;

public const string AffectedTestsOptionName = "--affected-tests";

public readonly Option<bool> AffectedTestsOption;

public bool AffectedTestsEnabled { get; }

public readonly Option<string> ArtifactsPathOption = CommonOptions.CreateArtifactsPathOption();

public const string BuildTargetName = "_MTPBuild";
Expand All @@ -195,6 +208,24 @@ public MicrosoftTestingPlatform()
MinimumExpectedTestsOption.Validators.Add(ValidatePositiveInteger);
MaximumFailedTestsOption.Validators.Add(ValidatePositiveInteger);

AffectedTestsEnabled = EnvironmentVariableParser.ParseBool(
Environment.GetEnvironmentVariable(EnableAffectedTestsEnvironmentVariable),
defaultValue: false);

CollectTestMapOption = new(CollectTestMapOptionName)
{
Description = CommandDefinitionStrings.CmdCollectTestMapDescription,
Arity = ArgumentArity.Zero,
Hidden = !AffectedTestsEnabled,
};

AffectedTestsOption = new(AffectedTestsOptionName)
{
Description = CommandDefinitionStrings.CmdAffectedTestsDescription,
Arity = ArgumentArity.Zero,
Hidden = !AffectedTestsEnabled,
};

Options.Add(ProjectOrSolutionOption);
Options.Add(SolutionOption);
Options.Add(TestModulesFilterOption);
Expand Down Expand Up @@ -228,7 +259,33 @@ public MicrosoftTestingPlatform()
Options.Add(NoLaunchProfileArgumentsOption);
Options.Add(DeviceOption);
Options.Add(ListDevicesOption);
Options.Add(CollectTestMapOption);
Options.Add(AffectedTestsOption);
Options.Add(MTPTargetOption);

Validators.Add(commandResult =>
{
bool collectTestMap = commandResult.HasOption(CollectTestMapOption);
bool affectedTests = commandResult.HasOption(AffectedTestsOption);
if (!AffectedTestsEnabled && (collectTestMap || affectedTests))
{
commandResult.AddError(string.Format(
CommandDefinitionStrings.CmdAffectedTestsFeatureDisabled,
EnableAffectedTestsEnvironmentVariable));
}
else if (collectTestMap && affectedTests)
{
commandResult.AddError(CommandDefinitionStrings.CmdAffectedTestsOptionsMutuallyExclusive);
}
else if (collectTestMap && commandResult.HasOption(MaxParallelTestModulesOption))
{
commandResult.AddError(CommandDefinitionStrings.CmdCollectTestMapCannotRunModulesInParallel);
}
else if (collectTestMap && commandResult.HasOption(MinimumExpectedTestsOption))
{
commandResult.AddError(CommandDefinitionStrings.CmdCollectTestMapCannotRequireMinimumTests);
}
});
}

public IEnumerable<Action<HelpContext>> CustomHelpLayout()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading