From 6d49b2ac450396ff7916ec7caad0a6b638394023 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 16:46:08 +0200 Subject: [PATCH 1/6] Execute dotnet run behind the hood --- .../commands/dotnet-test/BuiltInOptions.cs | 7 ++ .../commands/dotnet-test/CliConstants.cs | 7 +- .../commands/dotnet-test/IPC/Models/Module.cs | 2 +- .../IPC/Serializers/ModuleSerializer.cs | 4 +- .../dotnet-test/LocalizableStrings.resx | 3 + .../dotnet-test/MSBuildConnectionHandler.cs | 7 +- .../commands/dotnet-test/TestApplication.cs | 94 ++++++++++++++++--- .../dotnet-test/TestApplicationActionQueue.cs | 2 +- .../commands/dotnet-test/TestCommandParser.cs | 1 + .../dotnet-test/TestModulesFilterHandler.cs | 2 +- .../dotnet-test/TestingPlatformCommand.cs | 28 +++--- .../dotnet-test/TestingPlatformOptions.cs | 6 ++ .../dotnet-test/xlf/LocalizableStrings.cs.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.de.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.es.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.fr.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.it.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.ja.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.ko.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.pl.xlf | 5 + .../xlf/LocalizableStrings.pt-BR.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.ru.xlf | 5 + .../dotnet-test/xlf/LocalizableStrings.tr.xlf | 5 + .../xlf/LocalizableStrings.zh-Hans.xlf | 5 + .../xlf/LocalizableStrings.zh-Hant.xlf | 5 + ...Microsoft.TestPlatform.ImportAfter.targets | 2 +- .../GetTestsProject.cs | 5 +- 27 files changed, 191 insertions(+), 44 deletions(-) create mode 100644 src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs diff --git a/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs b/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs new file mode 100644 index 000000000000..c134e5d50f92 --- /dev/null +++ b/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs @@ -0,0 +1,7 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.DotNet.Cli.commands.dotnet_test +{ + internal record BuiltInOptions(bool HasNoRestore, bool HasNoBuild, string Configuration, string Architecture); +} diff --git a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs index 0a7fb838a844..e3b32f856c5f 100644 --- a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs +++ b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs @@ -5,13 +5,12 @@ namespace Microsoft.DotNet.Cli { internal static class CliConstants { + public const string DotnetRunCommand = "dotnet run"; public const string HelpOptionKey = "--help"; - public const string MSBuildOptionKey = "--msbuild-params"; - public const string NoBuildOptionKey = "--no-build"; public const string ServerOptionKey = "--server"; public const string DotNetTestPipeOptionKey = "--dotnet-test-pipe"; - public const string DegreeOfParallelismOptionKey = "--degree-of-parallelism"; - public const string DOPOptionKey = "--dop"; + public const string ProjectOptionKey = "--project"; + public const string FrameworkOptionKey = "--framework"; public const string ServerOptionValue = "dotnettestcli"; diff --git a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs index 568df5c66e58..53d5bcd3fff3 100644 --- a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs +++ b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs @@ -5,4 +5,4 @@ namespace Microsoft.DotNet.Tools.Test; -internal sealed record class Module(string? DLLPath, string? ProjectPath) : IRequest; +internal sealed record class Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest; diff --git a/src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/ModuleSerializer.cs b/src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/ModuleSerializer.cs index cfbf43d54335..3fbc7ae55642 100644 --- a/src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/ModuleSerializer.cs +++ b/src/Cli/dotnet/commands/dotnet-test/IPC/Serializers/ModuleSerializer.cs @@ -11,13 +11,15 @@ public object Deserialize(Stream stream) { string modulePath = ReadString(stream); string projectPath = ReadString(stream); - return new Module(modulePath.Trim(), projectPath.Trim()); + string targetFramework = ReadString(stream); + return new Module(modulePath.Trim(), projectPath.Trim(), targetFramework.Trim()); } public void Serialize(object objectToSerialize, Stream stream) { WriteString(stream, ((Module)objectToSerialize).DLLPath); WriteString(stream, ((Module)objectToSerialize).ProjectPath); + WriteString(stream, ((Module)objectToSerialize).TargetFramework); } } } diff --git a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx index 64459e2ba62b..c0f347c7c5cf 100644 --- a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx @@ -181,6 +181,9 @@ The target architecture '{0}' on which tests will run. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + The directory where the test results will be placed. The specified directory will be created if it does not exist. diff --git a/src/Cli/dotnet/commands/dotnet-test/MSBuildConnectionHandler.cs b/src/Cli/dotnet/commands/dotnet-test/MSBuildConnectionHandler.cs index d57e75c7e83b..d3b02b9795e0 100644 --- a/src/Cli/dotnet/commands/dotnet-test/MSBuildConnectionHandler.cs +++ b/src/Cli/dotnet/commands/dotnet-test/MSBuildConnectionHandler.cs @@ -62,7 +62,7 @@ private Task OnRequest(IRequest request) throw new NotSupportedException($"Request '{request.GetType()}' is unsupported."); } - var testApp = new TestApplication(module.DLLPath, _args); + var testApp = new TestApplication(module, _args); // Write the test application to the channel _actionQueue.Enqueue(testApp); testApp.OnCreated(); @@ -82,12 +82,9 @@ private Task OnRequest(IRequest request) public int RunWithMSBuild(ParseResult parseResult) { - bool containsNoBuild = parseResult.HasOption(TestingPlatformOptions.NoBuildOption); - bool containsNoRestore = parseResult.HasOption(TestingPlatformOptions.NoRestoreOption) || containsNoBuild; - List msbuildCommandLineArgs = [ - $"-t:{(containsNoRestore ? string.Empty : "Restore;")}{(containsNoBuild ? string.Empty : "Build;")}_GetTestsProject", + $"-t:_GetTestsProject", $"-p:GetTestsProjectPipeName={_pipeNameDescription.Name}", "-verbosity:q" ]; diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs index 061cf446b1ec..5a5a48816b13 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs @@ -4,13 +4,15 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.IO.Pipes; +using Microsoft.DotNet.Cli.commands.dotnet_test; using Microsoft.DotNet.Tools.Test; namespace Microsoft.DotNet.Cli { internal sealed class TestApplication : IDisposable { - private readonly string _modulePath; + private readonly Module _module; + private readonly string[] _args; private readonly List _outputData = []; private readonly List _errorData = []; @@ -33,11 +35,11 @@ internal sealed class TestApplication : IDisposable public event EventHandler Created; public event EventHandler ExecutionIdReceived; - public string ModulePath => _modulePath; + public Module Module => _module; - public TestApplication(string modulePath, string[] args) + public TestApplication(Module module, string[] args) { - _modulePath = modulePath; + _module = module; _args = args; } @@ -46,20 +48,20 @@ public void AddExecutionId(string executionId) _ = _executionIds.GetOrAdd(executionId, _ => string.Empty); } - public async Task RunAsync(bool enableHelp) + public async Task RunAsync(bool isFilterMode, bool enableHelp, BuiltInOptions builtInOptions) { if (!ModulePathExists()) { return 1; } - bool isDll = _modulePath.EndsWith(".dll"); + bool isDll = _module.DLLPath.EndsWith(".dll"); ProcessStartInfo processStartInfo = new() { FileName = isDll ? Environment.ProcessPath : - _modulePath, - Arguments = enableHelp ? BuildHelpArgs(isDll) : BuildArgs(isDll), + _module.DLLPath, + Arguments = enableHelp ? BuildHelpArgs(isDll) : isFilterMode ? BuildArgs(isDll) : BuildArgsWithDotnetRun(builtInOptions), RedirectStandardOutput = true, RedirectStandardError = true }; @@ -70,7 +72,6 @@ public async Task RunAsync(bool enableHelp) _namedPipeConnectionLoop.Wait(); return result; } - private async Task WaitConnectionAsync(CancellationToken token) { try @@ -223,21 +224,63 @@ private void StoreOutputAndErrorData(Process process) private bool ModulePathExists() { - if (!File.Exists(_modulePath)) + if (!File.Exists(_module.DLLPath)) { - ErrorReceived.Invoke(this, new ErrorEventArgs { ErrorMessage = $"Test module '{_modulePath}' not found. Build the test application before or run 'dotnet test'." }); + ErrorReceived.Invoke(this, new ErrorEventArgs { ErrorMessage = $"Test module '{_module.DLLPath}' not found. Build the test application before or run 'dotnet test'." }); return false; } return true; } + private string BuildArgsWithDotnetRun(BuiltInOptions builtInOptions) + { + StringBuilder builder = new(); + + builder.Append($"{CliConstants.DotnetRunCommand} {CliConstants.ProjectOptionKey} \"{_module.ProjectPath}\""); + + if (builtInOptions.HasNoRestore || builtInOptions.HasNoBuild) + { + builder.Append($" {TestingPlatformOptions.NoRestoreOption.Name}"); + } + + if (builtInOptions.HasNoBuild) + { + builder.Append($" {TestingPlatformOptions.NoBuildOption.Name}"); + } + + if (!string.IsNullOrEmpty(builtInOptions.Architecture)) + { + builder.Append($" {TestingPlatformOptions.ArchitectureOption.Name} {builtInOptions.Architecture}"); + } + + if (!string.IsNullOrEmpty(builtInOptions.Configuration)) + { + builder.Append($" {TestingPlatformOptions.ConfigurationOption.Name} {builtInOptions.Configuration}"); + } + + if (!string.IsNullOrEmpty(_module.TargetFramework)) + { + builder.Append($" {CliConstants.FrameworkOptionKey} {_module.TargetFramework}"); + } + + builder.Append(" -- "); + + builder.Append(_args.Length != 0 + ? _args.Aggregate((a, b) => $"{a} {b}") + : string.Empty); + + builder.Append($" {CliConstants.ServerOptionKey} {CliConstants.ServerOptionValue} {CliConstants.DotNetTestPipeOptionKey} {_pipeNameDescription.Name}"); + + return builder.ToString(); + } + private string BuildArgs(bool isDll) { StringBuilder builder = new(); if (isDll) { - builder.Append($"exec {_modulePath} "); + builder.Append($"exec {_module.DLLPath} "); } builder.Append(_args.Length != 0 @@ -255,7 +298,7 @@ private string BuildHelpArgs(bool isDll) if (isDll) { - builder.Append($"exec {_modulePath} "); + builder.Append($"exec {_module.DLLPath} "); } builder.Append($" {CliConstants.HelpOptionKey} {CliConstants.ServerOptionKey} {CliConstants.ServerOptionValue} {CliConstants.DotNetTestPipeOptionKey} {_pipeNameDescription.Name}"); @@ -267,7 +310,8 @@ public void OnHandshakeInfo(HandshakeInfo handshakeInfo) { if (handshakeInfo.Properties.TryGetValue(HandshakeInfoPropertyNames.ExecutionId, out string executionId)) { - ExecutionIdReceived?.Invoke(this, new ExecutionEventArgs { ModulePath = _modulePath, ExecutionId = executionId }); + AddExecutionId(executionId); + ExecutionIdReceived?.Invoke(this, new ExecutionEventArgs { ModulePath = _module.DLLPath, ExecutionId = executionId }); } HandshakeInfoReceived?.Invoke(this, new HandshakeInfoArgs { handshakeInfo = handshakeInfo }); } @@ -307,6 +351,28 @@ internal void OnCreated() Created?.Invoke(this, EventArgs.Empty); } + public override string ToString() + { + StringBuilder builder = new(); + + if (!string.IsNullOrEmpty(_module.DLLPath)) + { + builder.Append($"DLL: {_module.DLLPath}"); + } + + if (!string.IsNullOrEmpty(_module.ProjectPath)) + { + builder.Append($"Project: {_module.ProjectPath}"); + }; + + if (!string.IsNullOrEmpty(_module.TargetFramework)) + { + builder.Append($"Target Framework: {_module.TargetFramework}"); + }; + + return builder.ToString(); + } + public void Dispose() { _pipeConnection?.Dispose(); diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplicationActionQueue.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplicationActionQueue.cs index 6dbbe76e37aa..be10de8fbacc 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplicationActionQueue.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplicationActionQueue.cs @@ -23,7 +23,7 @@ public TestApplicationActionQueue(int dop, Func> acti public void Enqueue(TestApplication testApplication) { if (!_channel.Writer.TryWrite(testApplication)) - throw new InvalidOperationException($"Failed to write to channel for test application: {testApplication.ModulePath}"); + throw new InvalidOperationException($"Failed to write to channel for test application: {testApplication}"); } public bool WaitAllActions() diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 5e9a57686542..4792793a2cb1 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -198,6 +198,7 @@ private static CliCommand GetTestingPlatformCliCommand() command.Options.Add(TestingPlatformOptions.NoBuildOption); command.Options.Add(TestingPlatformOptions.NoRestoreOption); command.Options.Add(TestingPlatformOptions.ArchitectureOption); + command.Options.Add(TestingPlatformOptions.ConfigurationOption); return command; } diff --git a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs index e47ff1246676..897bb8c26691 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs @@ -50,7 +50,7 @@ public bool RunWithTestModulesFilter(ParseResult parseResult) foreach (string testModule in testModulePaths) { - var testApp = new TestApplication(testModule, _args); + var testApp = new TestApplication(new Module(testModule, null, null), _args); // Write the test application to the channel _actionQueue.Enqueue(testApp); testApp.OnCreated(); diff --git a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs index 8096d6f69c44..adc82223659d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.CommandLine; +using Microsoft.DotNet.Cli.commands.dotnet_test; using Microsoft.DotNet.Tools.Test; using Microsoft.TemplateEngine.Cli.Commands; @@ -10,7 +11,7 @@ namespace Microsoft.DotNet.Cli { internal partial class TestingPlatformCommand : CliCommand, ICustomHelp { - private readonly ConcurrentDictionary _testApplications = []; + private readonly ConcurrentBag _testApplications = []; private readonly CancellationTokenSource _cancellationToken = new(); private MSBuildConnectionHandler _msBuildConnectionHandler; @@ -26,17 +27,18 @@ public TestingPlatformCommand(string name, string description = null) : base(nam public int Run(ParseResult parseResult) { - if (parseResult.HasOption(TestingPlatformOptions.ArchitectureOption)) - { - VSTestTrace.SafeWriteTrace(() => $"The --arch option is not yet supported."); - return ExitCodes.GenericFailure; - } - // User can decide what the degree of parallelism should be // If not specified, we will default to the number of processors if (!int.TryParse(parseResult.GetValue(TestingPlatformOptions.MaxParallelTestModulesOption), out int degreeOfParallelism)) degreeOfParallelism = Environment.ProcessorCount; + bool filterModeEnabled = parseResult.HasOption(TestingPlatformOptions.TestModulesFilterOption); + BuiltInOptions builtInOptions = new( + parseResult.HasOption(TestingPlatformOptions.NoRestoreOption), + parseResult.HasOption(TestingPlatformOptions.NoBuildOption), + parseResult.GetValue(TestingPlatformOptions.ConfigurationOption), + parseResult.GetValue(TestingPlatformOptions.ArchitectureOption)); + if (ContainsHelpOption(parseResult.GetArguments())) { _actionQueue = new(degreeOfParallelism, async (TestApplication testApp) => @@ -47,7 +49,7 @@ public int Run(ParseResult parseResult) testApp.Created += OnTestApplicationCreated; testApp.ExecutionIdReceived += OnExecutionIdReceived; - return await testApp.RunAsync(enableHelp: true); + return await testApp.RunAsync(filterModeEnabled, enableHelp: true, builtInOptions); }); } else @@ -65,7 +67,7 @@ public int Run(ParseResult parseResult) testApp.Created += OnTestApplicationCreated; testApp.ExecutionIdReceived += OnExecutionIdReceived; - return await testApp.RunAsync(enableHelp: false); + return await testApp.RunAsync(filterModeEnabled, enableHelp: false, builtInOptions); }); } @@ -108,7 +110,7 @@ public int Run(ParseResult parseResult) private void CleanUp() { _msBuildConnectionHandler.Dispose(); - foreach (var testApplication in _testApplications.Values) + foreach (var testApplication in _testApplications) { testApplication.Dispose(); } @@ -222,15 +224,11 @@ private void OnTestProcessExited(object sender, TestProcessExitEventArgs args) private void OnTestApplicationCreated(object sender, EventArgs args) { TestApplication testApp = sender as TestApplication; - _testApplications[testApp.ModulePath] = testApp; + _testApplications.Add(testApp); } private void OnExecutionIdReceived(object sender, ExecutionEventArgs args) { - if (_testApplications.TryGetValue(args.ModulePath, out var testApp)) - { - testApp.AddExecutionId(args.ExecutionId); - } } private static bool ContainsHelpOption(IEnumerable args) => args.Contains(CliConstants.HelpOptionKey) || args.Contains(CliConstants.HelpOptionKey.Substring(0, 2)); diff --git a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformOptions.cs b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformOptions.cs index 80d8f04cca75..02e03c43d330 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformOptions.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformOptions.cs @@ -45,5 +45,11 @@ internal static class TestingPlatformOptions Description = LocalizableStrings.CmdArchitectureDescription, Arity = ArgumentArity.ExactlyOne }; + + public static readonly CliOption ConfigurationOption = new("--configuration") + { + Description = LocalizableStrings.CmdConfigurationDescription, + Arity = ArgumentArity.ExactlyOne + }; } } diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf index e36c12ad9df1..8ffc5a327e29 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf @@ -78,6 +78,11 @@ Při použití společně s testy řízenými daty závisí chování časového Pro MSTest před 2.2.4 se časový limit použije pro všechny testovací případy. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf index 9192f49bc1d4..4230845dc7d5 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf @@ -78,6 +78,11 @@ Wenn dies zusammen mit datengesteuerten Tests verwendet wird, hängt das Timeout für MSTest vor 2.2.4 wird das Timeout für alle Testfälle verwendet. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf index f0cb31480c84..5b862da217b9 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf @@ -80,6 +80,11 @@ Cuando se usa junto con pruebas controladas por datos, el comportamiento del tie Para MSTest antes de 2.2.4, el tiempo de espera se usa para todos los casos de prueba. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf index 95a502f88149..bf99a014362f 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf @@ -78,6 +78,11 @@ Lorsqu’elle est utilisée avec des tests pilotés par les données, le comport Pour MSTest avant la version 2.2.4, le délai d’expiration est utilisé pour tous les cas de test. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf index ff61e5b830d3..1cd9b68552f4 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf @@ -78,6 +78,11 @@ Se viene usato insieme a test basati sui dati, il comportamento di timeout dipen Per MSTest prima di 2.2.4, il timeout viene usato per tutti i test case. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf index 7c69cc3ba64a..2b3cb8acb6be 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf @@ -78,6 +78,11 @@ For MSTest before 2.2.4, the timeout is used for all testcases. MSTest 2.2.4 以前の場合、タイムアウトはすべてのテスト ケースに使用されます。 + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf index 57daab273960..e94d525573d1 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf @@ -78,6 +78,11 @@ For MSTest before 2.2.4, the timeout is used for all testcases. 2.2.4 이전 MSTest의 경우 모든 테스트 사례에 시간 제한이 사용됩니다. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf index 0d23d34fb3d5..2c2152b26341 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf @@ -78,6 +78,11 @@ W przypadku użycia razem z testami opartymi na danych zachowanie limitu czasu z W przypadku platformy MSTest przed wersją 2.2.4 limit czasu jest używany dla wszystkich przypadków testowych. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf index 297d44e3fc75..dcca53209d77 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pt-BR.xlf @@ -78,6 +78,11 @@ Quando usado junto com testes controlados por dados, o comportamento do tempo li Para MSTest antes de 2.2.4, o tempo limite é usado para todos os casos de teste. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf index ad7c0cd8a88c..541c29323863 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf @@ -78,6 +78,11 @@ For MSTest before 2.2.4, the timeout is used for all testcases. Для MSTest версии ниже 2.2.4 время ожидания подсчитывается суммарно для всех тестовых случаев. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf index 0e78cc42a504..d06fb5f1c673 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf @@ -78,6 +78,11 @@ Zaman aşımı davranışı veri tabanlı testlerle birlikte kullanıldığında 2.2.4’ten önceki MSTest sürümleri için zaman aşımı süresi tüm test çalışmalarına yönelik olarak kullanılır. + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf index 57096c8a03d5..5242033c88ba 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf @@ -78,6 +78,11 @@ For MSTest before 2.2.4, the timeout is used for all testcases. 对于 2.2.4 之前的 MSTest,超时用于所有测试用例。 + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf index fa9ad65d4f49..6db3242e82bb 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf @@ -78,6 +78,11 @@ For MSTest before 2.2.4, the timeout is used for all testcases. 對於 MSTest 2.2.4 之前的版本,該逾時會用於所有測試案例。 + + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project. + + Sets the value of an environment variable. Creates the variable if it does not exist, overrides if it does. diff --git a/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets b/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets index 389cf9397eb9..61d5cabf1296 100644 --- a/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets +++ b/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets @@ -20,6 +20,6 @@ Copyright (c) .NET Foundation. All rights reserved. - + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GetTestsProject.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GetTestsProject.cs index f461346586dd..d7b7838d0c97 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GetTestsProject.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GetTestsProject.cs @@ -18,6 +18,9 @@ public class GetTestsProject : Microsoft.Build.Utilities.Task [Required] public ITaskItem ProjectFullPath { get; set; } + [Required] + public ITaskItem TargetFramework { get; set; } + public override bool Execute() { try @@ -30,7 +33,7 @@ public override bool Execute() dotnetTestPipeClient.RegisterSerializer(new VoidResponseSerializer(), typeof(VoidResponse)); dotnetTestPipeClient.ConnectAsync(CancellationToken.None).GetAwaiter().GetResult(); - dotnetTestPipeClient.RequestReplyAsync(new Module(TargetPath.ItemSpec, ProjectFullPath.ItemSpec), CancellationToken.None).GetAwaiter().GetResult(); + dotnetTestPipeClient.RequestReplyAsync(new Module(TargetPath.ItemSpec, ProjectFullPath.ItemSpec, TargetFramework.ItemSpec), CancellationToken.None).GetAwaiter().GetResult(); } catch (Exception ex) { From f92dbf5564e7a9939fc2f38260f992074e42a37b Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 16:58:31 +0200 Subject: [PATCH 2/6] remove wrong namespace --- src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs | 2 +- src/Cli/dotnet/commands/dotnet-test/CliConstants.cs | 1 + src/Cli/dotnet/commands/dotnet-test/TestApplication.cs | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs b/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs index c134e5d50f92..f3bc4c1419c5 100644 --- a/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs +++ b/src/Cli/dotnet/commands/dotnet-test/BuiltInOptions.cs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -namespace Microsoft.DotNet.Cli.commands.dotnet_test +namespace Microsoft.DotNet.Cli { internal record BuiltInOptions(bool HasNoRestore, bool HasNoBuild, string Configuration, string Architecture); } diff --git a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs index e3b32f856c5f..3604c74df456 100644 --- a/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs +++ b/src/Cli/dotnet/commands/dotnet-test/CliConstants.cs @@ -15,6 +15,7 @@ internal static class CliConstants public const string ServerOptionValue = "dotnettestcli"; public const string MSBuildExeName = "MSBuild.dll"; + public const string ParametersSeparator = "--"; } internal static class TestStates diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs index 5a5a48816b13..aa1e792c3143 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs @@ -4,7 +4,6 @@ using System.Collections.Concurrent; using System.Diagnostics; using System.IO.Pipes; -using Microsoft.DotNet.Cli.commands.dotnet_test; using Microsoft.DotNet.Tools.Test; namespace Microsoft.DotNet.Cli @@ -263,7 +262,7 @@ private string BuildArgsWithDotnetRun(BuiltInOptions builtInOptions) builder.Append($" {CliConstants.FrameworkOptionKey} {_module.TargetFramework}"); } - builder.Append(" -- "); + builder.Append($" {CliConstants.ParametersSeparator} "); builder.Append(_args.Length != 0 ? _args.Aggregate((a, b) => $"{a} {b}") From 550fd415018d9a86e45f32772be8f33e25b92bfa Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 17:10:08 +0200 Subject: [PATCH 3/6] refactor --- src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs | 5 ++++- .../dotnet/commands/dotnet-test/TestModulesFilterHandler.cs | 2 +- .../dotnet/commands/dotnet-test/TestingPlatformCommand.cs | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs index 53d5bcd3fff3..fb65027da495 100644 --- a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs +++ b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs @@ -5,4 +5,7 @@ namespace Microsoft.DotNet.Tools.Test; -internal sealed record class Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest; +internal sealed record Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest +{ + public Module(string? DLLPath) : this(DLLPath, string.Empty, string.Empty) { } +} diff --git a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs index 897bb8c26691..3e8aa28e1212 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs @@ -50,7 +50,7 @@ public bool RunWithTestModulesFilter(ParseResult parseResult) foreach (string testModule in testModulePaths) { - var testApp = new TestApplication(new Module(testModule, null, null), _args); + var testApp = new TestApplication(new Module(testModule), _args); // Write the test application to the channel _actionQueue.Enqueue(testApp); testApp.OnCreated(); diff --git a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs index adc82223659d..04a96792c72a 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestingPlatformCommand.cs @@ -3,7 +3,6 @@ using System.Collections.Concurrent; using System.CommandLine; -using Microsoft.DotNet.Cli.commands.dotnet_test; using Microsoft.DotNet.Tools.Test; using Microsoft.TemplateEngine.Cli.Commands; From 51ad72ed9b7725e1fd42056bd8cc04f11806c1b0 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 17:15:13 +0200 Subject: [PATCH 4/6] Undo change to add extra constructor for Module --- src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs | 3 --- .../dotnet/commands/dotnet-test/TestModulesFilterHandler.cs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs index fb65027da495..243b3d86a7e2 100644 --- a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs +++ b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs @@ -6,6 +6,3 @@ namespace Microsoft.DotNet.Tools.Test; internal sealed record Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest -{ - public Module(string? DLLPath) : this(DLLPath, string.Empty, string.Empty) { } -} diff --git a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs index 3e8aa28e1212..897bb8c26691 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestModulesFilterHandler.cs @@ -50,7 +50,7 @@ public bool RunWithTestModulesFilter(ParseResult parseResult) foreach (string testModule in testModulePaths) { - var testApp = new TestApplication(new Module(testModule), _args); + var testApp = new TestApplication(new Module(testModule, null, null), _args); // Write the test application to the channel _actionQueue.Enqueue(testApp); testApp.OnCreated(); From 768b39e65a90e536bde03f170af5d02e3f10a27b Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 17:15:23 +0200 Subject: [PATCH 5/6] add ; --- src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs index 243b3d86a7e2..b884bdf94a6e 100644 --- a/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs +++ b/src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs @@ -5,4 +5,4 @@ namespace Microsoft.DotNet.Tools.Test; -internal sealed record Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest +internal sealed record Module(string? DLLPath, string? ProjectPath, string? TargetFramework) : IRequest; From 3b7ea1905fa6535d0dc194ed3e0c94b2b2c6fc39 Mon Sep 17 00:00:00 2001 From: mariam-abdulla Date: Mon, 2 Sep 2024 17:20:31 +0200 Subject: [PATCH 6/6] Fix condition for no-restore in test app --- src/Cli/dotnet/commands/dotnet-test/TestApplication.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs index aa1e792c3143..1c36d08d38b8 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestApplication.cs @@ -237,7 +237,7 @@ private string BuildArgsWithDotnetRun(BuiltInOptions builtInOptions) builder.Append($"{CliConstants.DotnetRunCommand} {CliConstants.ProjectOptionKey} \"{_module.ProjectPath}\""); - if (builtInOptions.HasNoRestore || builtInOptions.HasNoBuild) + if (builtInOptions.HasNoRestore) { builder.Append($" {TestingPlatformOptions.NoRestoreOption.Name}"); }