-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Split 'dotnet test' classes in two directories (VSTest/MTP) #50639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
9a73b27
5ebba95
579fee7
3069d64
201e6a8
72667af
cb6969a
dc5bbdd
0e0f802
fa7ce81
e2c81e6
7beb98c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,27 +10,24 @@ | |
|
|
||
| namespace Microsoft.DotNet.Cli.Commands.Test; | ||
|
|
||
| internal partial class TestingPlatformCommand : Command, ICustomHelp | ||
| internal partial class MicrosoftTestingPlatformTestCommand : Command, ICustomHelp, ICommandDocument | ||
| { | ||
| private MSBuildHandler _msBuildHandler; | ||
| private TerminalTestReporter _output; | ||
| private TestApplicationActionQueue _actionQueue; | ||
|
|
||
| private byte _cancelled; | ||
| private bool _isDiscovery; | ||
| private bool _isRetry; | ||
|
|
||
| public TestingPlatformCommand(string name, string description = null) : base(name, description) | ||
| public MicrosoftTestingPlatformTestCommand(string name, string description = null) : base(name, description) | ||
| { | ||
| TreatUnmatchedTokensAsErrors = false; | ||
| } | ||
|
|
||
| public int Run(ParseResult parseResult) | ||
| public string DocsLink => "https://aka.ms/dotnet-test"; | ||
|
|
||
| public int Run(ParseResult parseResult, bool isHelp = false) | ||
| { | ||
| int? exitCode = null; | ||
| try | ||
| { | ||
| exitCode = RunInternal(parseResult); | ||
| exitCode = RunInternal(parseResult, isHelp); | ||
| return exitCode.Value; | ||
| } | ||
| finally | ||
|
|
@@ -39,49 +36,53 @@ public int Run(ParseResult parseResult) | |
| } | ||
| } | ||
|
|
||
| private int RunInternal(ParseResult parseResult) | ||
| private int RunInternal(ParseResult parseResult, bool isHelp) | ||
| { | ||
| ValidationUtility.ValidateMutuallyExclusiveOptions(parseResult); | ||
| ValidationUtility.ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrectly(parseResult); | ||
|
|
||
| PrepareEnvironment(parseResult, out TestOptions testOptions, out int degreeOfParallelism); | ||
| int degreeOfParallelism = GetDegreeOfParallelism(parseResult); | ||
| bool filterModeEnabled = parseResult.HasOption(MicrosoftTestingPlatformOptions.TestModulesFilterOption); | ||
| var testOptions = new TestOptions(filterModeEnabled, IsHelp: isHelp); | ||
|
||
|
|
||
| InitializeOutput(degreeOfParallelism, parseResult, testOptions.IsHelp); | ||
|
|
||
| SetupCancelKeyPressHandler(); | ||
|
|
||
| BuildOptions buildOptions = MSBuildUtility.GetBuildOptions(parseResult, degreeOfParallelism); | ||
|
|
||
| InitializeActionQueue(degreeOfParallelism, testOptions, buildOptions); | ||
| var actionQueue = InitializeActionQueue(degreeOfParallelism, testOptions, buildOptions); | ||
|
|
||
| _msBuildHandler = new(buildOptions, _actionQueue, _output); | ||
| TestModulesFilterHandler testModulesFilterHandler = new(_actionQueue, _output); | ||
| var msBuildHandler = new MSBuildHandler(buildOptions, actionQueue, _output); | ||
|
|
||
| if (testOptions.HasFilterMode) | ||
| { | ||
| var testModulesFilterHandler = new TestModulesFilterHandler(actionQueue, _output); | ||
| if (!testModulesFilterHandler.RunWithTestModulesFilter(parseResult)) | ||
| { | ||
| return ExitCode.GenericFailure; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (!_msBuildHandler.RunMSBuild()) | ||
| if (!msBuildHandler.RunMSBuild()) | ||
| { | ||
| return ExitCode.GenericFailure; | ||
| } | ||
|
|
||
| if (!_msBuildHandler.EnqueueTestApplications()) | ||
| if (!msBuildHandler.EnqueueTestApplications()) | ||
| { | ||
| return ExitCode.GenericFailure; | ||
| } | ||
| } | ||
|
|
||
| _actionQueue.EnqueueCompleted(); | ||
| actionQueue.EnqueueCompleted(); | ||
| // Don't inline exitCode variable. We want to always call WaitAllActions first. | ||
| var exitCode = _actionQueue.WaitAllActions(); | ||
| var exitCode = actionQueue.WaitAllActions(); | ||
| exitCode = _output.HasHandshakeFailure ? ExitCode.GenericFailure : exitCode; | ||
| if (exitCode == ExitCode.Success && | ||
| parseResult.HasOption(TestingPlatformOptions.MinimumExpectedTestsOption) && | ||
| parseResult.GetValue(TestingPlatformOptions.MinimumExpectedTestsOption) is { } minimumExpectedTests && | ||
| parseResult.HasOption(MicrosoftTestingPlatformOptions.MinimumExpectedTestsOption) && | ||
| parseResult.GetValue(MicrosoftTestingPlatformOptions.MinimumExpectedTestsOption) is { } minimumExpectedTests && | ||
| _output.TotalTests < minimumExpectedTests) | ||
| { | ||
| exitCode = ExitCode.MinimumExpectedTestsPolicyViolation; | ||
|
|
@@ -90,26 +91,9 @@ private int RunInternal(ParseResult parseResult) | |
| return exitCode; | ||
| } | ||
|
|
||
| private void PrepareEnvironment(ParseResult parseResult, out TestOptions testOptions, out int degreeOfParallelism) | ||
| private TestApplicationActionQueue InitializeActionQueue(int degreeOfParallelism, TestOptions testOptions, BuildOptions buildOptions) | ||
| { | ||
| SetupCancelKeyPressHandler(); | ||
|
|
||
| degreeOfParallelism = GetDegreeOfParallelism(parseResult); | ||
|
|
||
| bool filterModeEnabled = parseResult.HasOption(TestingPlatformOptions.TestModulesFilterOption); | ||
|
|
||
| var arguments = parseResult.GetArguments(); | ||
| testOptions = GetTestOptions(filterModeEnabled, isHelp: ContainsHelpOption(arguments)); | ||
|
|
||
| _isDiscovery = ContainsListTestsOption(arguments); | ||
|
|
||
| // This is ugly, and we need to replace it by passing out some info from testing platform to inform us that some process level retry plugin is active. | ||
| _isRetry = arguments.Contains("--retry-failed-tests"); | ||
| } | ||
|
|
||
| private void InitializeActionQueue(int degreeOfParallelism, TestOptions testOptions, BuildOptions buildOptions) | ||
| { | ||
| _actionQueue = new TestApplicationActionQueue(degreeOfParallelism, buildOptions, testOptions, _output, async (TestApplication testApp) => | ||
| return new TestApplicationActionQueue(degreeOfParallelism, buildOptions, testOptions, _output, async (TestApplication testApp) => | ||
| { | ||
| testApp.HelpRequested += OnHelpRequested; | ||
| return await testApp.RunAsync(); | ||
|
|
@@ -129,9 +113,9 @@ private void SetupCancelKeyPressHandler() | |
| private void InitializeOutput(int degreeOfParallelism, ParseResult parseResult, bool isHelp) | ||
| { | ||
| var console = new SystemConsole(); | ||
| var showPassedTests = parseResult.GetValue(TestingPlatformOptions.OutputOption) == OutputOptions.Detailed; | ||
| var noProgress = parseResult.HasOption(TestingPlatformOptions.NoProgressOption); | ||
| var noAnsi = parseResult.HasOption(TestingPlatformOptions.NoAnsiOption); | ||
| var showPassedTests = parseResult.GetValue(MicrosoftTestingPlatformOptions.OutputOption) == OutputOptions.Detailed; | ||
| var noProgress = parseResult.HasOption(MicrosoftTestingPlatformOptions.NoProgressOption); | ||
| var noAnsi = parseResult.HasOption(MicrosoftTestingPlatformOptions.NoAnsiOption); | ||
|
|
||
| // TODO: Replace this with proper CI detection that we already have in telemetry. https://github.com/microsoft/testfx/issues/5533#issuecomment-2838893327 | ||
| bool inCI = string.Equals(Environment.GetEnvironmentVariable("TF_BUILD"), "true", StringComparison.OrdinalIgnoreCase) || string.Equals(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"), "true", StringComparison.OrdinalIgnoreCase); | ||
|
|
@@ -144,33 +128,24 @@ private void InitializeOutput(int degreeOfParallelism, ParseResult parseResult, | |
| UseCIAnsi = inCI, | ||
| ShowAssembly = true, | ||
| ShowAssemblyStartAndComplete = true, | ||
| MinimumExpectedTests = parseResult.GetValue(TestingPlatformOptions.MinimumExpectedTestsOption), | ||
| MinimumExpectedTests = parseResult.GetValue(MicrosoftTestingPlatformOptions.MinimumExpectedTestsOption), | ||
| }); | ||
|
|
||
| _output.TestExecutionStarted(DateTimeOffset.Now, degreeOfParallelism, _isDiscovery, isHelp, _isRetry); | ||
| var isDiscovery = parseResult.HasOption(MicrosoftTestingPlatformOptions.ListTestsOption); | ||
| // This is ugly, and we need to replace it by passing out some info from testing platform to inform us that some process level retry plugin is active. | ||
| var isRetry = parseResult.GetArguments().Contains("--retry-failed-tests"); | ||
|
|
||
| _output.TestExecutionStarted(DateTimeOffset.Now, degreeOfParallelism, isDiscovery, isHelp, isRetry); | ||
| } | ||
|
|
||
| private static int GetDegreeOfParallelism(ParseResult parseResult) | ||
| { | ||
| var degreeOfParallelism = parseResult.GetValue(TestingPlatformOptions.MaxParallelTestModulesOption); | ||
| var degreeOfParallelism = parseResult.GetValue(MicrosoftTestingPlatformOptions.MaxParallelTestModulesOption); | ||
| if (degreeOfParallelism <= 0) | ||
| degreeOfParallelism = Environment.ProcessorCount; | ||
| return degreeOfParallelism; | ||
| } | ||
|
|
||
| private static TestOptions GetTestOptions(bool hasFilterMode, bool isHelp) => | ||
| new(hasFilterMode, isHelp); | ||
|
|
||
| private static bool ContainsHelpOption(IEnumerable<string> args) | ||
| { | ||
| return args.Contains(TestingPlatformOptions.HelpOption.Name) || TestingPlatformOptions.HelpOption.Aliases.Any(alias => args.Contains(alias)); | ||
| } | ||
|
|
||
| private static bool ContainsListTestsOption(IEnumerable<string> args) | ||
| { | ||
| return args.Contains(TestingPlatformOptions.ListTestsOption.Name); | ||
| } | ||
|
|
||
| private void CompleteRun(int? exitCode) | ||
| { | ||
| if (Interlocked.CompareExchange(ref _cancelled, 1, 0) == 0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The additional interface is for #50638