From 1610dca5d1e864ceb0d2187255d7854e7553625f Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Fri, 16 Sep 2022 10:59:48 -0500 Subject: [PATCH 01/13] Add explicit catch-all argument for forwarded arguments for dotnet test --- .../commands/dotnet-test/LocalizableStrings.resx | 6 ++++++ .../dotnet/commands/dotnet-test/TestCommandParser.cs | 7 +++++++ .../commands/dotnet-test/xlf/LocalizableStrings.cs.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.de.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.es.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.fr.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.it.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.ja.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.ko.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.pl.xlf | 10 ++++++++++ .../dotnet-test/xlf/LocalizableStrings.pt-BR.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.ru.xlf | 10 ++++++++++ .../commands/dotnet-test/xlf/LocalizableStrings.tr.xlf | 10 ++++++++++ .../dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf | 10 ++++++++++ .../dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf | 10 ++++++++++ 15 files changed, 143 insertions(+) diff --git a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx index 85b9deb95a5c..d54f6b239a21 100644 --- a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx @@ -277,4 +277,10 @@ Examples: NAME="VALUE" + + FORWARDED_ARGS + + + Arguments to forward to MSBuild. + diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 43088b1b36d1..b80e9827afbb 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -23,6 +23,12 @@ internal static class TestCommandParser Arity = ArgumentArity.ZeroOrOne }; + public static readonly Argument ForwardedArguments = new Argument(LocalizableStrings.ForwardedArguments) + { + Description = LocalizableStrings.ForwardedArgumentsDescription, + Arity = ArgumentArity.ZeroOrMore + }; + public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) { ArgumentHelpName = LocalizableStrings.CmdSettingsFile @@ -159,6 +165,7 @@ private static Command ConstructCommand() command.AddOption(CommonOptions.VerbosityOption); command.AddOption(CommonOptions.ArchitectureOption); command.AddOption(CommonOptions.OperatingSystemOption); + command.AddArgument(ForwardedArguments); command.SetHandler(TestCommand.Run); 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 ecaf095ba690..c5475d60f81f 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf @@ -200,6 +200,16 @@ Pokud zadaný adresář neexistuje, bude vytvořen. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 edadf570a1d4..ca913b64d476 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf @@ -200,6 +200,16 @@ Das angegebene Verzeichnis wird erstellt, wenn es nicht vorhanden ist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 716710671c42..1e04459761f9 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf @@ -200,6 +200,16 @@ Si no existe, se creará el directorio especificado. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 0b8efdae271e..6524f214ea24 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf @@ -200,6 +200,16 @@ Le répertoire spécifié est créé, s'il n'existe pas déjà. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 1c5ec654b0a6..1705b45cad34 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf @@ -200,6 +200,16 @@ Se non esiste, la directory specificata verrà creata. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 3e3ba42e0b7d..a5cee4a48181 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf @@ -200,6 +200,16 @@ The specified directory will be created if it does not exist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 e685ee09ed76..36e83174e924 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf @@ -200,6 +200,16 @@ The specified directory will be created if it does not exist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 af32230d649d..868a77242153 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf @@ -200,6 +200,16 @@ Jeśli określony katalog nie istnieje, zostanie utworzony. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 a1d5259e781b..c8bf220b897d 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 @@ -200,6 +200,16 @@ O diretório especificado será criado se ele ainda não existir. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 72fff3da0429..0e071bf58b53 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf @@ -200,6 +200,16 @@ The specified directory will be created if it does not exist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 9bd1871b1915..7a57228c6226 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf @@ -200,6 +200,16 @@ Belirtilen dizin yoksa oluşturulur. DÖKÜM_TÜRÜ + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DÖKÜM_TÜRÜ 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 bb778a744ed5..8928b2e0beca 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 @@ -200,6 +200,16 @@ The specified directory will be created if it does not exist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE 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 ba011c75476d..f7388fa54475 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 @@ -200,6 +200,16 @@ The specified directory will be created if it does not exist. DUMP_TYPE + + FORWARDED_ARGS + FORWARDED_ARGS + + + + Arguments to forward to MSBuild. + Arguments to forward to MSBuild. + + DUMP_TYPE DUMP_TYPE From b3b5ed7af0672f2a342cff93b356efa74c710f53 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Fri, 16 Sep 2022 12:02:33 -0500 Subject: [PATCH 02/13] use unmatched tokens instead --- src/Cli/dotnet/commands/dotnet-test/Program.cs | 2 +- src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 701e619b035b..3e7ae169f648 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -32,7 +32,7 @@ public static int Run(ParseResult parseResult) // from the VSTest side. string testSessionCorrelationId = $"{Environment.ProcessId}_{Guid.NewGuid()}"; - string[] args = parseResult.GetArguments(); + string[] args = parseResult.GetArguments().Concat(parseResult.UnmatchedTokens).ToArray(); if (VSTestTrace.TraceEnabled) { diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index b80e9827afbb..43088b1b36d1 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -23,12 +23,6 @@ internal static class TestCommandParser Arity = ArgumentArity.ZeroOrOne }; - public static readonly Argument ForwardedArguments = new Argument(LocalizableStrings.ForwardedArguments) - { - Description = LocalizableStrings.ForwardedArgumentsDescription, - Arity = ArgumentArity.ZeroOrMore - }; - public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) { ArgumentHelpName = LocalizableStrings.CmdSettingsFile @@ -165,7 +159,6 @@ private static Command ConstructCommand() command.AddOption(CommonOptions.VerbosityOption); command.AddOption(CommonOptions.ArchitectureOption); command.AddOption(CommonOptions.OperatingSystemOption); - command.AddArgument(ForwardedArguments); command.SetHandler(TestCommand.Run); From 226cff026c1c498d97382dd55024fdc80d2ad31e Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Fri, 16 Sep 2022 14:13:39 -0500 Subject: [PATCH 03/13] Add test case for msbuild argument forwarding --- .../VSTestMSBuildParameters/Tests.cs | 21 ++++++++ .../VSTestMSBuildParameters.csproj | 20 ++++++++ ...ivenDotnetTestContainsMSBuildParameters.cs | 50 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs create mode 100644 src/Assets/TestProjects/VSTestMSBuildParameters/VSTestMSBuildParameters.csproj create mode 100644 src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs diff --git a/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs b/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs new file mode 100644 index 000000000000..0cfa0b11f8a0 --- /dev/null +++ b/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs @@ -0,0 +1,21 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections; +using System.Reflection; + +namespace TestNamespace +{ + [TestClass] + public class Tests + { + [TestMethod] + public void TestMSBuildParameters() + { + var assemblyInfoVersion = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; + Assert.AreEqual(assemblyInfoVersion, "1.2.3"); + } + } +} diff --git a/src/Assets/TestProjects/VSTestMSBuildParameters/VSTestMSBuildParameters.csproj b/src/Assets/TestProjects/VSTestMSBuildParameters/VSTestMSBuildParameters.csproj new file mode 100644 index 000000000000..b407ba549aa2 --- /dev/null +++ b/src/Assets/TestProjects/VSTestMSBuildParameters/VSTestMSBuildParameters.csproj @@ -0,0 +1,20 @@ + + + + + Exe + $(CurrentTargetFramework) + + + + + + + + + + + + + + diff --git a/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs b/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs new file mode 100644 index 000000000000..63ca3b396956 --- /dev/null +++ b/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; +using FluentAssertions; +using Microsoft.DotNet.Cli.Utils; +using System.IO; +using System; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Commands; +using Xunit.Abstractions; + +namespace Microsoft.DotNet.Cli.Test.Tests +{ + public class GivenDotnetTestContainsMSBuildParameters : SdkTest + { + private const string TestAppName = "VSTestMSBuildParameters"; + private const string MSBuildParameter = "/p:Version=1.2.3"; + + public GivenDotnetTestContainsMSBuildParameters(ITestOutputHelper log) : base(log) + { + } + + [Fact] + public void ItPassesEnvironmentVariablesFromCommandLineParametersWhenRunningViaCsproj() + { + var testAsset = _testAssetsManager.CopyTestAsset(TestAppName) + .WithSource() + .WithVersionVariables(); + + var testRoot = testAsset.Path; + + CommandResult result = new DotnetTestCommand(Log) + .WithWorkingDirectory(testRoot) + .Execute("--logger", "console;verbosity=detailed", MSBuildParameter); + + if (!TestContext.IsLocalized()) + { + result.StdOut + .Should().Contain("Total tests: 1") + .And.Contain("Passed: 1") + .And.Contain("Passed TestMSBuildParameters"); + } + + result.ExitCode.Should().Be(0); + } + } +} From 79a7e317d6fe3c430434b284121e3d675d58d4a7 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Fri, 16 Sep 2022 14:16:53 -0500 Subject: [PATCH 04/13] revert xlf changes because we went with a different strategy --- .../commands/dotnet-test/LocalizableStrings.resx | 6 ------ .../commands/dotnet-test/xlf/LocalizableStrings.cs.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.de.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.es.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.fr.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.it.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.ja.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.ko.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.pl.xlf | 10 ---------- .../dotnet-test/xlf/LocalizableStrings.pt-BR.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.ru.xlf | 10 ---------- .../commands/dotnet-test/xlf/LocalizableStrings.tr.xlf | 10 ---------- .../dotnet-test/xlf/LocalizableStrings.zh-Hans.xlf | 10 ---------- .../dotnet-test/xlf/LocalizableStrings.zh-Hant.xlf | 10 ---------- 14 files changed, 136 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx index d54f6b239a21..85b9deb95a5c 100644 --- a/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx @@ -277,10 +277,4 @@ Examples: NAME="VALUE" - - FORWARDED_ARGS - - - Arguments to forward to MSBuild. - 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 c5475d60f81f..ecaf095ba690 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf @@ -200,16 +200,6 @@ Pokud zadaný adresář neexistuje, bude vytvořen. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 ca913b64d476..edadf570a1d4 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf @@ -200,16 +200,6 @@ Das angegebene Verzeichnis wird erstellt, wenn es nicht vorhanden ist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 1e04459761f9..716710671c42 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf @@ -200,16 +200,6 @@ Si no existe, se creará el directorio especificado. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 6524f214ea24..0b8efdae271e 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf @@ -200,16 +200,6 @@ Le répertoire spécifié est créé, s'il n'existe pas déjà. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 1705b45cad34..1c5ec654b0a6 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf @@ -200,16 +200,6 @@ Se non esiste, la directory specificata verrà creata. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 a5cee4a48181..3e3ba42e0b7d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf @@ -200,16 +200,6 @@ The specified directory will be created if it does not exist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 36e83174e924..e685ee09ed76 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf @@ -200,16 +200,6 @@ The specified directory will be created if it does not exist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 868a77242153..af32230d649d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf @@ -200,16 +200,6 @@ Jeśli określony katalog nie istnieje, zostanie utworzony. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 c8bf220b897d..a1d5259e781b 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 @@ -200,16 +200,6 @@ O diretório especificado será criado se ele ainda não existir. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 0e071bf58b53..72fff3da0429 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ru.xlf @@ -200,16 +200,6 @@ The specified directory will be created if it does not exist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 7a57228c6226..9bd1871b1915 100644 --- a/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.tr.xlf @@ -200,16 +200,6 @@ Belirtilen dizin yoksa oluşturulur. DÖKÜM_TÜRÜ - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DÖKÜM_TÜRÜ 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 8928b2e0beca..bb778a744ed5 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 @@ -200,16 +200,6 @@ The specified directory will be created if it does not exist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE 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 f7388fa54475..ba011c75476d 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 @@ -200,16 +200,6 @@ The specified directory will be created if it does not exist. DUMP_TYPE - - FORWARDED_ARGS - FORWARDED_ARGS - - - - Arguments to forward to MSBuild. - Arguments to forward to MSBuild. - - DUMP_TYPE DUMP_TYPE From e85325040c5bc51b670c5b4c659303f7a10c571c Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Tue, 20 Sep 2022 12:49:35 -0500 Subject: [PATCH 05/13] Add tests to cover both ways the project-invocation can be tested --- src/Cli/dotnet/commands/dotnet-test/Program.cs | 16 ++++++++++++---- .../Commands/TestCommand.cs | 6 ++++++ .../GivenDotnetTestContainsMSBuildParameters.cs | 12 +++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 3e7ae169f648..413c2f1eca11 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -32,7 +32,7 @@ public static int Run(ParseResult parseResult) // from the VSTest side. string testSessionCorrelationId = $"{Environment.ProcessId}_{Guid.NewGuid()}"; - string[] args = parseResult.GetArguments().Concat(parseResult.UnmatchedTokens).ToArray(); + string[] args = parseResult.GetArguments(); if (VSTestTrace.TraceEnabled) { @@ -118,7 +118,13 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings "-nologo" }; - msbuildArgs.AddRange(result.OptionValuesToBeForwarded(TestCommandParser.GetCommand())); + + var parsedArgs = + result.OptionValuesToBeForwarded(TestCommandParser.GetCommand()) // all msbuild-recognized tokens + .Concat(result.UnmatchedTokens); // all tokens that the test-parser doesn't explicitly track + + VSTestTrace.SafeWriteTrace(() => $"MSBuild args from forwarded options: {String.Join(", ", parsedArgs)}" ); + msbuildArgs.AddRange(parsedArgs); if (settings.Any()) { @@ -126,7 +132,7 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); if(!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) { - msbuildArgs.Add(result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument)); + msbuildArgs.Add(commandArgument); } // skip '--' and escape every \ to be \\ and every " to be \" to survive the next hop @@ -138,8 +144,10 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings else { var argument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - if(!string.IsNullOrWhiteSpace(argument)) + if (!string.IsNullOrWhiteSpace(argument)) + { msbuildArgs.Add(argument); + } } string verbosityArg = result.ForwardedOptionValues>(TestCommandParser.GetCommand(), "verbosity")?.SingleOrDefault() ?? null; diff --git a/src/Tests/Microsoft.NET.TestFramework/Commands/TestCommand.cs b/src/Tests/Microsoft.NET.TestFramework/Commands/TestCommand.cs index eea0b9a39191..60276ced1e1a 100644 --- a/src/Tests/Microsoft.NET.TestFramework/Commands/TestCommand.cs +++ b/src/Tests/Microsoft.NET.TestFramework/Commands/TestCommand.cs @@ -46,6 +46,12 @@ public TestCommand WithWorkingDirectory(string workingDirectory) return this; } + public TestCommand WithTraceOutput() + { + WithEnvironmentVariable("DOTNET_CLI_VSTEST_TRACE", "1"); + return this; + } + private SdkCommandSpec CreateCommandSpec(IEnumerable args) { var commandSpec = CreateCommand(args); diff --git a/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs b/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs index 63ca3b396956..8cfdcc66fb41 100644 --- a/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs +++ b/src/Tests/dotnet-test.Tests/GivenDotnetTestContainsMSBuildParameters.cs @@ -23,8 +23,10 @@ public GivenDotnetTestContainsMSBuildParameters(ITestOutputHelper log) : base(lo { } - [Fact] - public void ItPassesEnvironmentVariablesFromCommandLineParametersWhenRunningViaCsproj() + [InlineData($"{TestAppName}.csproj")] + [InlineData(null)] + [Theory] + public void ItPassesEnvironmentVariablesFromCommandLineParametersWhenRunningViaCsproj(string projectName) { var testAsset = _testAssetsManager.CopyTestAsset(TestAppName) .WithSource() @@ -32,9 +34,9 @@ public void ItPassesEnvironmentVariablesFromCommandLineParametersWhenRunningViaC var testRoot = testAsset.Path; - CommandResult result = new DotnetTestCommand(Log) - .WithWorkingDirectory(testRoot) - .Execute("--logger", "console;verbosity=detailed", MSBuildParameter); + CommandResult result = (projectName is null ? new DotnetTestCommand(Log) : new DotnetTestCommand(Log, projectName)) + .WithWorkingDirectory(testRoot) + .Execute("--logger", "console;verbosity=detailed", MSBuildParameter); if (!TestContext.IsLocalized()) { From bdbb0f37385a20c8d5eff53374e17ba462b971e1 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Wed, 21 Sep 2022 13:12:18 -0500 Subject: [PATCH 06/13] fix test args --- ...TestfromCsprojWithCorrectTestRunParameters.cs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsprojWithCorrectTestRunParameters.cs b/src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsprojWithCorrectTestRunParameters.cs index bad9ecd1e1b2..aec125674ea2 100644 --- a/src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsprojWithCorrectTestRunParameters.cs +++ b/src/Tests/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsprojWithCorrectTestRunParameters.cs @@ -34,12 +34,8 @@ public void GivenAProjectAndMultipleTestRunParametersItPassesThemToVStestConsole .WithWorkingDirectory(testProjectDirectory) .Execute(ConsoleLoggerOutputNormal.Concat(new[] { "--", - "TestRunParameters.Parameter(name=\"myParam\",", - "value=\"value\")", - "TestRunParameters.Parameter(name=\"myParam2\",", - "value=\"value", - "with", - "space\")" + "TestRunParameters.Parameter(name=\"myParam\",value=\"value\")", + "TestRunParameters.Parameter(name=\"myParam2\",value=\"value with space\")" })); // Verify @@ -72,12 +68,8 @@ public void GivenADllAndMultipleTestRunParametersItPassesThemToVStestConsoleInTh .Execute(ConsoleLoggerOutputNormal.Concat(new[] { outputDll, "--", - "TestRunParameters.Parameter(name=\"myParam\",", - "value=\"value\")", - "TestRunParameters.Parameter(name=\"myParam2\",", - "value=\"value", - "with", - "space\")" + "TestRunParameters.Parameter(name=\"myParam\",value=\"value\")", + "TestRunParameters.Parameter(name=\"myParam2\",value=\"value with space\")" })); // Verify From 1f0b26a8032fbfc82362db98dc3f30f74e7b74d7 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Wed, 2 Nov 2022 08:55:46 -0500 Subject: [PATCH 07/13] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Jareš Co-authored-by: Amaury Levé --- src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs | 2 +- src/Cli/dotnet/commands/dotnet-test/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs b/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs index 0cfa0b11f8a0..d44bdcef33f3 100644 --- a/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs +++ b/src/Assets/TestProjects/VSTestMSBuildParameters/Tests.cs @@ -15,7 +15,7 @@ public class Tests public void TestMSBuildParameters() { var assemblyInfoVersion = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; - Assert.AreEqual(assemblyInfoVersion, "1.2.3"); + Assert.AreEqual("1.2.3", assemblyInfoVersion); } } } diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 413c2f1eca11..c6f2cae9cd82 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -120,7 +120,7 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings var parsedArgs = - result.OptionValuesToBeForwarded(TestCommandParser.GetCommand()) // all msbuild-recognized tokens + result.OptionValuesToBeForwarded(TestCommandParser.GetCommand()) // all msbuild-recognized tokens .Concat(result.UnmatchedTokens); // all tokens that the test-parser doesn't explicitly track VSTestTrace.SafeWriteTrace(() => $"MSBuild args from forwarded options: {String.Join(", ", parsedArgs)}" ); From cf8c7a561eef9b8d9d318f421b3a7d97c8b05be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 8 Nov 2022 19:00:40 +0100 Subject: [PATCH 08/13] Fix parsing of unhandled arguments --- .../dotnet/commands/dotnet-test/Program.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index c6f2cae9cd82..b6df569b7cea 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Parsing; +using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.DotNet.Cli; @@ -32,6 +33,15 @@ public static int Run(ParseResult parseResult) // from the VSTest side. string testSessionCorrelationId = $"{Environment.ProcessId}_{Guid.NewGuid()}"; + if (!Debugger.IsAttached) + { + Debugger.Launch(); + } + else + { + Debugger.Break(); + } + string[] args = parseResult.GetArguments(); if (VSTestTrace.TraceEnabled) @@ -56,10 +66,10 @@ public static int Run(ParseResult parseResult) return ForwardToVSTestConsole(parseResult, args, settings, testSessionCorrelationId); } - return ForwardToMsbuild(parseResult, settings, testSessionCorrelationId); + return ForwardToMsbuild(parseResult, args, settings, testSessionCorrelationId); } - private static int ForwardToMsbuild(ParseResult parseResult, string[] settings, string testSessionCorrelationId) + private static int ForwardToMsbuild(ParseResult parseResult, string[] args, string[] settings, string testSessionCorrelationId) { // Workaround for https://github.com/Microsoft/vstest/issues/1503 const string NodeWindowEnvironmentName = "MSBUILDENSURESTDOUTFORTASKPROCESSES"; @@ -67,7 +77,7 @@ private static int ForwardToMsbuild(ParseResult parseResult, string[] settings, try { Environment.SetEnvironmentVariable(NodeWindowEnvironmentName, "1"); - int exitCode = FromParseResult(parseResult, settings, testSessionCorrelationId).Execute(); + int exitCode = FromParseResult(parseResult, args, settings, testSessionCorrelationId).Execute(); // We run post processing also if execution is failed for possible partial successful result to post process. exitCode |= RunArtifactPostProcessingIfNeeded(testSessionCorrelationId, parseResult, FeatureFlag.Instance); @@ -107,7 +117,7 @@ private static int ForwardToVSTestConsole(ParseResult parseResult, string[] args return exitCode; } - private static TestCommand FromParseResult(ParseResult result, string[] settings, string testSessionCorrelationId, string msbuildPath = null) + private static TestCommand FromParseResult(ParseResult result, string[] args, string[] settings, string testSessionCorrelationId, string msbuildPath = null) { result.ShowHelpOrErrorIfAppropriate(); @@ -118,10 +128,9 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings "-nologo" }; - var parsedArgs = result.OptionValuesToBeForwarded(TestCommandParser.GetCommand()) // all msbuild-recognized tokens - .Concat(result.UnmatchedTokens); // all tokens that the test-parser doesn't explicitly track + .Concat(args); // all tokens that the test-parser doesn't explicitly track (minus the settings tokens) VSTestTrace.SafeWriteTrace(() => $"MSBuild args from forwarded options: {String.Join(", ", parsedArgs)}" ); msbuildArgs.AddRange(parsedArgs); @@ -130,7 +139,10 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings { //workaround for correct -- logic var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - if(!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) + // TODO: @baronfel, @Evangelink + // If the project or solution is not specified we would expect null here but we actually + // get some of the parameter (last one before --) instead. + if (!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) { msbuildArgs.Add(commandArgument); } From 6e1ce52ffae402f66ecb3086e2e320da25575bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 8 Nov 2022 19:02:21 +0100 Subject: [PATCH 09/13] Remove debugger.launch --- src/Cli/dotnet/commands/dotnet-test/Program.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index b6df569b7cea..897e860cfc26 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -33,15 +33,6 @@ public static int Run(ParseResult parseResult) // from the VSTest side. string testSessionCorrelationId = $"{Environment.ProcessId}_{Guid.NewGuid()}"; - if (!Debugger.IsAttached) - { - Debugger.Launch(); - } - else - { - Debugger.Break(); - } - string[] args = parseResult.GetArguments(); if (VSTestTrace.TraceEnabled) From 0368dfff605ff77cfbb6e75a5b931aefec4469ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 9 Nov 2022 16:05:23 +0100 Subject: [PATCH 10/13] wip --- .../dotnet/commands/dotnet-test/Program.cs | 32 +++++++++++-------- .../commands/dotnet-test/TestCommandParser.cs | 12 +++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 897e860cfc26..ca8a68eeb0fd 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -119,9 +119,13 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st "-nologo" }; + var unMatchedNonSettingsArgs = settings.Length > 1 + ? result.UnmatchedTokens.TakeWhile(x => x != settings[1]) + : result.UnmatchedTokens; + var parsedArgs = result.OptionValuesToBeForwarded(TestCommandParser.GetCommand()) // all msbuild-recognized tokens - .Concat(args); // all tokens that the test-parser doesn't explicitly track (minus the settings tokens) + .Concat(unMatchedNonSettingsArgs); // all tokens that the test-parser doesn't explicitly track (minus the settings tokens) VSTestTrace.SafeWriteTrace(() => $"MSBuild args from forwarded options: {String.Join(", ", parsedArgs)}" ); msbuildArgs.AddRange(parsedArgs); @@ -129,14 +133,14 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st if (settings.Any()) { //workaround for correct -- logic - var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - // TODO: @baronfel, @Evangelink - // If the project or solution is not specified we would expect null here but we actually - // get some of the parameter (last one before --) instead. - if (!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) - { - msbuildArgs.Add(commandArgument); - } + //var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); + //// TODO: @baronfel, @Evangelink + //// If the project or solution is not specified we would expect null here but we actually + //// get some of the parameter (last one before --) instead. + //if (!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) + //{ + // msbuildArgs.Add(commandArgument); + //} // skip '--' and escape every \ to be \\ and every " to be \" to survive the next hop string[] escaped = settings.Skip(1).Select(s => s.Replace("\\", "\\\\").Replace("\"", "\\\"")).ToArray(); @@ -146,11 +150,11 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st } else { - var argument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - if (!string.IsNullOrWhiteSpace(argument)) - { - msbuildArgs.Add(argument); - } + //var argument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); + //if (!string.IsNullOrWhiteSpace(argument)) + //{ + // msbuildArgs.Add(argument); + //} } string verbosityArg = result.ForwardedOptionValues>(TestCommandParser.GetCommand(), "verbosity")?.SingleOrDefault() ?? null; diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 43088b1b36d1..ca15d1b406f6 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -17,11 +17,11 @@ internal static class TestCommandParser { public static readonly string DocsLink = "https://aka.ms/dotnet-test"; - public static readonly Argument SlnOrProjectArgument = new Argument(CommonLocalizableStrings.SolutionOrProjectArgumentName) - { - Description = CommonLocalizableStrings.SolutionOrProjectArgumentDescription, - Arity = ArgumentArity.ZeroOrOne - }; + //public static readonly Argument SlnOrProjectArgument = new Argument(CommonLocalizableStrings.SolutionOrProjectArgumentName) + //{ + // Description = CommonLocalizableStrings.SolutionOrProjectArgumentDescription, + // Arity = ArgumentArity.ZeroOrOne + //}; public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) { @@ -130,7 +130,7 @@ private static Command ConstructCommand() { var command = new DocumentedCommand("test", DocsLink, LocalizableStrings.AppFullName); command.TreatUnmatchedTokensAsErrors = false; - command.AddArgument(SlnOrProjectArgument); + //command.AddArgument(SlnOrProjectArgument); command.AddOption(SettingsOption); command.AddOption(ListTestsOption); From cdd5f3b9465e07babb6c1ba54e4d8887c7b9c28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 9 Nov 2022 16:37:16 +0100 Subject: [PATCH 11/13] Cleanup change --- .../dotnet/commands/dotnet-test/Program.cs | 25 ++++--------------- .../commands/dotnet-test/TestCommandParser.cs | 12 +++------ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index ca8a68eeb0fd..4cce5cee57cf 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -68,7 +68,7 @@ private static int ForwardToMsbuild(ParseResult parseResult, string[] args, stri try { Environment.SetEnvironmentVariable(NodeWindowEnvironmentName, "1"); - int exitCode = FromParseResult(parseResult, args, settings, testSessionCorrelationId).Execute(); + int exitCode = FromParseResult(parseResult, settings, testSessionCorrelationId).Execute(); // We run post processing also if execution is failed for possible partial successful result to post process. exitCode |= RunArtifactPostProcessingIfNeeded(testSessionCorrelationId, parseResult, FeatureFlag.Instance); @@ -108,7 +108,7 @@ private static int ForwardToVSTestConsole(ParseResult parseResult, string[] args return exitCode; } - private static TestCommand FromParseResult(ParseResult result, string[] args, string[] settings, string testSessionCorrelationId, string msbuildPath = null) + private static TestCommand FromParseResult(ParseResult result, string[] settings, string testSessionCorrelationId, string msbuildPath = null) { result.ShowHelpOrErrorIfAppropriate(); @@ -119,6 +119,9 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st "-nologo" }; + // Extra msbuild properties won't be parsed and so end up in the UnmatchedTokens list. In addition to those + // properties, all the test settings properties are also considered as unmatched but we don't want to forward + // these as-is to msbuild. So we filter out the test settings properties from the unmatched tokens. var unMatchedNonSettingsArgs = settings.Length > 1 ? result.UnmatchedTokens.TakeWhile(x => x != settings[1]) : result.UnmatchedTokens; @@ -132,30 +135,12 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st if (settings.Any()) { - //workaround for correct -- logic - //var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - //// TODO: @baronfel, @Evangelink - //// If the project or solution is not specified we would expect null here but we actually - //// get some of the parameter (last one before --) instead. - //if (!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) - //{ - // msbuildArgs.Add(commandArgument); - //} - // skip '--' and escape every \ to be \\ and every " to be \" to survive the next hop string[] escaped = settings.Skip(1).Select(s => s.Replace("\\", "\\\\").Replace("\"", "\\\"")).ToArray(); string runSettingsArg = string.Join(";", escaped); msbuildArgs.Add($"-property:VSTestCLIRunSettings=\"{runSettingsArg}\""); } - else - { - //var argument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - //if (!string.IsNullOrWhiteSpace(argument)) - //{ - // msbuildArgs.Add(argument); - //} - } string verbosityArg = result.ForwardedOptionValues>(TestCommandParser.GetCommand(), "verbosity")?.SingleOrDefault() ?? null; if (verbosityArg != null) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index ca15d1b406f6..30bb60e16c9d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -15,13 +15,7 @@ namespace Microsoft.DotNet.Cli { internal static class TestCommandParser { - public static readonly string DocsLink = "https://aka.ms/dotnet-test"; - - //public static readonly Argument SlnOrProjectArgument = new Argument(CommonLocalizableStrings.SolutionOrProjectArgumentName) - //{ - // Description = CommonLocalizableStrings.SolutionOrProjectArgumentDescription, - // Arity = ArgumentArity.ZeroOrOne - //}; + public static readonly string DocsLink = "https://aka.ms/dotnet-test"; public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) { @@ -130,7 +124,9 @@ private static Command ConstructCommand() { var command = new DocumentedCommand("test", DocsLink, LocalizableStrings.AppFullName); command.TreatUnmatchedTokensAsErrors = false; - //command.AddArgument(SlnOrProjectArgument); + + // We are on purpose not capturing the solution, project or directory here. We want to pass it to the + // MSBuild command so we are letting it flow. command.AddOption(SettingsOption); command.AddOption(ListTestsOption); From 29c336ae882f0bb075548a779e1f0fa1430b406c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Wed, 9 Nov 2022 18:44:26 +0100 Subject: [PATCH 12/13] Update src/Cli/dotnet/commands/dotnet-test/Program.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Jareš --- src/Cli/dotnet/commands/dotnet-test/Program.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 4cce5cee57cf..993b52d2f54d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -121,7 +121,8 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings // Extra msbuild properties won't be parsed and so end up in the UnmatchedTokens list. In addition to those // properties, all the test settings properties are also considered as unmatched but we don't want to forward - // these as-is to msbuild. So we filter out the test settings properties from the unmatched tokens. + // these as-is to msbuild. So we filter out the test settings properties from the unmatched tokens, + // by only taking values until the first item after `--`. (`--` is not present in the UnmatchedTokens ). var unMatchedNonSettingsArgs = settings.Length > 1 ? result.UnmatchedTokens.TakeWhile(x => x != settings[1]) : result.UnmatchedTokens; From 91c5e639e630c5d830c19b2a9d65671350481245 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Thu, 10 Nov 2022 09:49:05 -0600 Subject: [PATCH 13/13] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Amaury Levé --- src/Cli/dotnet/commands/dotnet-test/Program.cs | 7 +++---- src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index 993b52d2f54d..257db53be33e 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.CommandLine; using System.CommandLine.Parsing; -using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.DotNet.Cli; @@ -57,10 +56,10 @@ public static int Run(ParseResult parseResult) return ForwardToVSTestConsole(parseResult, args, settings, testSessionCorrelationId); } - return ForwardToMsbuild(parseResult, args, settings, testSessionCorrelationId); + return ForwardToMsbuild(parseResult, settings, testSessionCorrelationId); } - private static int ForwardToMsbuild(ParseResult parseResult, string[] args, string[] settings, string testSessionCorrelationId) + private static int ForwardToMsbuild(ParseResult parseResult, string[] settings, string testSessionCorrelationId) { // Workaround for https://github.com/Microsoft/vstest/issues/1503 const string NodeWindowEnvironmentName = "MSBUILDENSURESTDOUTFORTASKPROCESSES"; @@ -122,7 +121,7 @@ private static TestCommand FromParseResult(ParseResult result, string[] settings // Extra msbuild properties won't be parsed and so end up in the UnmatchedTokens list. In addition to those // properties, all the test settings properties are also considered as unmatched but we don't want to forward // these as-is to msbuild. So we filter out the test settings properties from the unmatched tokens, - // by only taking values until the first item after `--`. (`--` is not present in the UnmatchedTokens ). + // by only taking values until the first item after `--`. (`--` is not present in the UnmatchedTokens). var unMatchedNonSettingsArgs = settings.Length > 1 ? result.UnmatchedTokens.TakeWhile(x => x != settings[1]) : result.UnmatchedTokens; diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index 30bb60e16c9d..69512049fdcc 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli { internal static class TestCommandParser { - public static readonly string DocsLink = "https://aka.ms/dotnet-test"; + public static readonly string DocsLink = "https://aka.ms/dotnet-test"; public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) {