From 7318cbdc13679032b2dd44c4afb0e351f204c5e3 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 14 Jul 2025 09:00:55 +0200 Subject: [PATCH 1/3] Support `--filter-uid` on console --- .../PlatformCommandLineProvider.cs | 2 + .../ConsoleTestExecutionFilterFactory.cs | 19 ++++- .../Requests/ITestExecutionFilterFactory.cs | 2 +- .../Resources/PlatformResources.resx | 6 ++ .../Resources/xlf/PlatformResources.cs.xlf | 10 +++ .../Resources/xlf/PlatformResources.de.xlf | 10 +++ .../Resources/xlf/PlatformResources.es.xlf | 10 +++ .../Resources/xlf/PlatformResources.fr.xlf | 10 +++ .../Resources/xlf/PlatformResources.it.xlf | 10 +++ .../Resources/xlf/PlatformResources.ja.xlf | 10 +++ .../Resources/xlf/PlatformResources.ko.xlf | 10 +++ .../Resources/xlf/PlatformResources.pl.xlf | 10 +++ .../Resources/xlf/PlatformResources.pt-BR.xlf | 10 +++ .../Resources/xlf/PlatformResources.ru.xlf | 10 +++ .../Resources/xlf/PlatformResources.tr.xlf | 10 +++ .../xlf/PlatformResources.zh-Hans.xlf | 10 +++ .../xlf/PlatformResources.zh-Hant.xlf | 10 +++ .../HelpInfoTests.cs | 2 + .../ExecutionTests.cs | 74 +++++++++++++++++-- .../HelpInfoTests.cs | 12 +++ 20 files changed, 237 insertions(+), 10 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs index ad94138e77..5f1b3f192b 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.cs @@ -28,6 +28,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider public const string TestHostControllerPIDOptionKey = "internal-testhostcontroller-pid"; public const string ExitOnProcessExitOptionKey = "exit-on-process-exit"; public const string ConfigFileOptionKey = "config-file"; + public const string FilterUidOptionKey = "filter-uid"; public const string ServerOptionKey = "server"; public const string ClientPortOptionKey = "client-port"; @@ -57,6 +58,7 @@ internal sealed class PlatformCommandLineProvider : ICommandLineOptionsProvider new(IgnoreExitCodeOptionKey, PlatformResources.PlatformCommandLineIgnoreExitCodeOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true), new(ExitOnProcessExitOptionKey, PlatformResources.PlatformCommandLineExitOnProcessExitOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true), new(ConfigFileOptionKey, PlatformResources.PlatformCommandLineConfigFileOptionDescription, ArgumentArity.ExactlyOne, false, isBuiltIn: true), + new(FilterUidOptionKey, PlatformResources.PlatformCommandLineFilterUidOptionDescription, ArgumentArity.OneOrMore, false, isBuiltIn: true), // Hidden options new(HelpOptionQuestionMark, PlatformResources.PlatformCommandLineHelpOptionDescription, ArgumentArity.Zero, true, isBuiltIn: true), diff --git a/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionFilterFactory.cs b/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionFilterFactory.cs index 14f7305ec4..5e7ef78150 100644 --- a/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionFilterFactory.cs +++ b/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionFilterFactory.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Microsoft.Testing.Platform.CommandLine; +using Microsoft.Testing.Platform.Extensions.Messages; using Microsoft.Testing.Platform.Helpers; using Microsoft.Testing.Platform.Resources; @@ -21,8 +22,18 @@ internal sealed class ConsoleTestExecutionFilterFactory(ICommandLineOptions comm public Task IsEnabledAsync() => Task.FromResult(true); - public Task<(bool Success, ITestExecutionFilter? TestExecutionFilter)> TryCreateAsync() => - _commandLineService.TryGetOptionArgumentList(TreeNodeFilterCommandLineOptionsProvider.TreenodeFilter, out string[]? filter) - ? Task.FromResult((true, (ITestExecutionFilter?)new TreeNodeFilter(filter[0]))) - : Task.FromResult((true, (ITestExecutionFilter?)new NopFilter())); + public Task<(bool Success, ITestExecutionFilter? TestExecutionFilter)> TryCreateAsync() + { + bool hasTreenodeFilter = _commandLineService.TryGetOptionArgumentList(TreeNodeFilterCommandLineOptionsProvider.TreenodeFilter, out string[]? treenodeFilter); + bool hasTestNodeUidFilter = _commandLineService.TryGetOptionArgumentList(PlatformCommandLineProvider.FilterUidOptionKey, out string[]? uidFilter); + ITestExecutionFilter filter = (hasTreenodeFilter, hasTestNodeUidFilter) switch + { + (true, true) => throw new NotSupportedException(PlatformResources.OnlyOneFilterSupported), + (true, false) => new TreeNodeFilter(treenodeFilter![0]), + (false, true) => new TestNodeUidListFilter([.. uidFilter!.Select(x => new TestNodeUid(x))]), + (false, false) => new NopFilter(), + }; + + return Task.FromResult<(bool, ITestExecutionFilter?)>((true, filter)); + } } diff --git a/src/Platform/Microsoft.Testing.Platform/Requests/ITestExecutionFilterFactory.cs b/src/Platform/Microsoft.Testing.Platform/Requests/ITestExecutionFilterFactory.cs index cc80518805..37b51a3d82 100644 --- a/src/Platform/Microsoft.Testing.Platform/Requests/ITestExecutionFilterFactory.cs +++ b/src/Platform/Microsoft.Testing.Platform/Requests/ITestExecutionFilterFactory.cs @@ -7,5 +7,5 @@ namespace Microsoft.Testing.Platform.Requests; internal interface ITestExecutionFilterFactory : IExtension { - public Task<(bool Success, ITestExecutionFilter? TestExecutionFilter)> TryCreateAsync(); + Task<(bool Success, ITestExecutionFilter? TestExecutionFilter)> TryCreateAsync(); } diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 51ec6ea19f..755cc220b1 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -707,4 +707,10 @@ Takes one argument as string in the format <value>[h|m|s] where 'value' is The current test framework does not implement 'IGracefulStopTestExecutionCapability' which is required for '--maximum-failed-tests' feature. + + Specifies a list of test node uids to filter. + + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index bf97e9b009..cfbf517278 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -431,6 +431,11 @@ Nenalezeno + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Vytvořené artefakty souboru mimo proces: @@ -533,6 +538,11 @@ Dostupné hodnoty jsou Trace, Debug, Information, Warning, Error a Critical.„ --{0}“ očekává jeden argument int PID. + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Umožňuje zobrazit nápovědu příkazového řádku. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index d657755538..c43270625f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -431,6 +431,11 @@ Nicht gefunden + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Nicht verarbeitete Dateiartefakte erstellt: @@ -533,6 +538,11 @@ Die verfügbaren Werte sind "Trace", "Debug", "Information", "Warning", "Error" "--{0}" erwartet ein einzelnes int-PID-Argument. + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Zeigen Sie die Hilfe zur Befehlszeile an. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index 493fe65d2a..b22ade1e23 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -431,6 +431,11 @@ No se encontró + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Artefactos de archivo fuera de proceso producidos: @@ -533,6 +538,11 @@ Los valores disponibles son 'Seguimiento', 'Depurar', 'Información', 'Advertenc '--{0}' espera un único argumento PID entero + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Muestre la ayuda de la línea de comandos. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index f82ac26b64..a64d3bc10f 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -431,6 +431,11 @@ Introuvable + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Artefacts de fichier hors processus produits : @@ -533,6 +538,11 @@ Les valeurs disponibles sont « Trace », « Debug », « Information », « --{0} » attend un seul argument PID int + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Afficher l’aide de la ligne de commande. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index 0f9e8cf771..03b898e1a9 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -431,6 +431,11 @@ Non trovato + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Artefatti file non in elaborazione prodotti: @@ -533,6 +538,11 @@ I valori disponibili sono 'Trace', 'Debug', 'Information', 'Warning', 'Error' e '--{0}' prevede un singolo argomento PID int + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Mostra la Guida della riga di comando. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 52d494a080..7a849bc4f7 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -431,6 +431,11 @@ 見つかりません + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: アウトプロセスのファイル成果物が生成されました: @@ -534,6 +539,11 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an '--{0}' には 1 つの int PID 引数が必要です + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. コマンド ラインヘルプを表示します。 diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index 2bddcfd54c..c95d167154 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -431,6 +431,11 @@ 찾을 수 없음 + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: 생성된 Out of process 파일 아티팩트: @@ -533,6 +538,11 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an '--{0}'에는 단일 int PID 인수가 필요합니다. + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. 명령줄 도움말을 표시합니다. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 9fa4232e0d..30ce09a762 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -431,6 +431,11 @@ Nie znaleziono + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Wygenerowane artefakty pliku poza procesem: @@ -533,6 +538,11 @@ Dostępne wartości to „Trace”, „Debug”, „Information”, „Warning „--{0}” oczekuje pojedynczego argumentu int identyfikatora PID + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Pokaż pomoc wiersza polecenia. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index c24d1413ab..ff301c8c90 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -431,6 +431,11 @@ Não encontrado + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Artefatos de arquivo fora do processo produzidos: @@ -533,6 +538,11 @@ Os valores disponíveis são 'Rastreamento', 'Depuração', 'Informação', 'Avi "--{0}" espera um único argumento int PID + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Mostrar a ajuda da linha de comando. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index 089434cc81..4396c286f6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -431,6 +431,11 @@ Не найдено + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Созданные вне процесса артефакты файлов: @@ -533,6 +538,11 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an "--{0}" ожидает один аргумент int PID + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Показать справку по командной строке. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 67ff90a823..527b31dfe5 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -431,6 +431,11 @@ Bulunamadı + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: Üretilen işlem dışı dosya yapıtları: @@ -533,6 +538,11 @@ Kullanılabilir değerler: 'Trace', 'Debug', 'Information', 'Warning', 'Error' v '--{0}', tek bir int PID bağımsız değişkeni bekliyor + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. Komut satırı yardımını gösterir. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index 5e2dfad71d..b026432596 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -431,6 +431,11 @@ 未找到 + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: 生成的进程外文件项目: @@ -533,6 +538,11 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an “--{0}”需要单个 int PID 参数 + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. 显示命令行帮助。 diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index 8bf8789838..01a72b262d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -431,6 +431,11 @@ 找不到 + + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + Passing both '--treenode-filter' and '--filter-uid' is unsupported. + + Out of process file artifacts produced: 產生的流程外檔案成品: @@ -533,6 +538,11 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an '--{0}' 需要單一 int PID 引數 + + Specifies a list of test node uids to filter. + Specifies a list of test node uids to filter. + + Show the command line help. 顯示命令列說明。 diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs index d43193af01..ac8eb81e69 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -45,6 +45,8 @@ Output directory of the diagnostic logging. The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. + --filter-uid + Specifies a list of test node uids to filter. --help Show the command line help. --ignore-exit-code diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs index 0f4857f6e8..0f60919345 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs @@ -40,6 +40,60 @@ public async Task Exec_WhenOnlyAssetNameIsSpecified_AllTestsAreRun(string tfm) testHostResult.AssertOutputMatchesRegex($"Passed! - .*\\.(dll|exe) \\(net.+\\|.+\\)"); } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Exec_WhenUsingUidFilterForRun(string tfm) + { + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + + TestHostResult testHostResult = await testHost.ExecuteAsync("--filter-uid NonExistingUid"); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); + + testHostResult = await testHost.ExecuteAsync("--filter-uid 0"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); + + testHostResult = await testHost.ExecuteAsync("--filter-uid 1"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); + + testHostResult = await testHost.ExecuteAsync("--filter-uid 0 --filter-uid 1"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputContainsSummary(failed: 0, passed: 2, skipped: 0); + } + + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Exec_WhenUsingUidFilterForDiscovery(string tfm) + { + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + + TestHostResult testHostResult = await testHost.ExecuteAsync("--list-tests --filter-uid NonExistingUid"); + testHostResult.AssertExitCodeIs(ExitCodes.ZeroTests); + + testHostResult = await testHost.ExecuteAsync("--list-tests --filter-uid 0"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputMatchesRegex(""" + Test1 + Test discovery summary: found 1 test\(s\) + """); + + testHostResult = await testHost.ExecuteAsync("--list-tests --filter-uid 1"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputMatchesRegex(""" + Test2 + Test discovery summary: found 1 test\(s\) + """); + + testHostResult = await testHost.ExecuteAsync("--list-tests --filter-uid 0 --filter-uid 1"); + testHostResult.AssertExitCodeIs(ExitCodes.Success); + testHostResult.AssertOutputMatchesRegex(""" + Test1 + Test2 + Test discovery summary: found 2 test\(s\) + """); + } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] [TestMethod] public async Task Exec_WhenListTestsAndFilterAreSpecified_OnlyFilteredTestsAreFound(string tfm) @@ -138,12 +192,14 @@ public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture. #file Program.cs +using System.Linq; using Microsoft.Testing.Platform.Builder; using Microsoft.Testing.Platform.Capabilities.TestFramework; using Microsoft.Testing.Platform.Extensions; using Microsoft.Testing.Platform.Extensions.Messages; using Microsoft.Testing.Platform.Extensions.TestFramework; using Microsoft.Testing.Platform.Helpers; +using Microsoft.Testing.Platform.Requests; using Microsoft.Testing.Platform.Services; public class Program @@ -205,17 +261,25 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context) // Simulate that here. bool isDiscovery = _sp.GetCommandLineOptions().TryGetOptionArgumentList("--list-tests", out _); - - await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, - new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + var uidListFilter = ((TestExecutionRequest)context.Request).Filter as TestNodeUidListFilter; + + // If --filter-uid is used, but it doesn't contain a given Uid, then don't publish TestNodeUpdateMessage for that Uid. + var excludeUid0 = uidListFilter is not null && !uidListFilter.TestNodeUids.Any(n => n.Value == "0"); + var excludeUid1 = uidListFilter is not null && !uidListFilter.TestNodeUids.Any(n => n.Value == "1"); + + if (!excludeUid0) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, + new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); + } - if (!isDiscovery) + if (!isDiscovery && !excludeUid0) { await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(PassedTestNodeStateProperty.CachedInstance) })); } - if (!_sp.GetCommandLineOptions().TryGetOptionArgumentList("--treenode-filter", out _)) + if (!_sp.GetCommandLineOptions().TryGetOptionArgumentList("--treenode-filter", out _) && !excludeUid1) { await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode() { Uid = "1", DisplayName = "Test2", Properties = new(DiscoveredTestNodeStateProperty.CachedInstance) })); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index f4b19b2e50..fb3bf3d6c0 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -39,6 +39,8 @@ Output directory of the diagnostic logging. The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. + --filter-uid + Specifies a list of test node uids to filter. --help Show the command line help. --ignore-exit-code @@ -183,6 +185,10 @@ Note that this is slowing down the test execution\. Arity: 1 Hidden: False Description: Exit the test process if dependent process exits\. PID must be provided\. + --filter-uid + Arity: 1\.\.N + Hidden: False + Description: Specifies a list of test node uids to filter\. --help Arity: 0 Hidden: False @@ -290,6 +296,8 @@ Output directory of the diagnostic logging. The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', and 'Critical'. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. + --filter-uid + Specifies a list of test node uids to filter. --help Show the command line help. --ignore-exit-code @@ -445,6 +453,10 @@ Note that this is slowing down the test execution. Arity: 1 Hidden: False Description: Exit the test process if dependent process exits. PID must be provided. + --filter-uid + Arity: 1\.\.N + Hidden: False + Description: Specifies a list of test node uids to filter\. --help Arity: 0 Hidden: False From 9de514b76c7ef328d91a10b70716ca7d3f99c2c8 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Mon, 14 Jul 2025 09:49:47 +0200 Subject: [PATCH 2/3] Update message --- .../Resources/PlatformResources.resx | 2 +- .../Resources/xlf/PlatformResources.cs.xlf | 4 ++-- .../Resources/xlf/PlatformResources.de.xlf | 4 ++-- .../Resources/xlf/PlatformResources.es.xlf | 4 ++-- .../Resources/xlf/PlatformResources.fr.xlf | 4 ++-- .../Resources/xlf/PlatformResources.it.xlf | 4 ++-- .../Resources/xlf/PlatformResources.ja.xlf | 4 ++-- .../Resources/xlf/PlatformResources.ko.xlf | 4 ++-- .../Resources/xlf/PlatformResources.pl.xlf | 4 ++-- .../Resources/xlf/PlatformResources.pt-BR.xlf | 4 ++-- .../Resources/xlf/PlatformResources.ru.xlf | 4 ++-- .../Resources/xlf/PlatformResources.tr.xlf | 4 ++-- .../Resources/xlf/PlatformResources.zh-Hans.xlf | 4 ++-- .../Resources/xlf/PlatformResources.zh-Hant.xlf | 4 ++-- .../MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs | 2 +- .../HelpInfoTests.cs | 8 ++++---- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 755cc220b1..12d70f5348 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -708,7 +708,7 @@ Takes one argument as string in the format <value>[h|m|s] where 'value' is The current test framework does not implement 'IGracefulStopTestExecutionCapability' which is required for '--maximum-failed-tests' feature. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. Passing both '--treenode-filter' and '--filter-uid' is unsupported. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf index cfbf517278..7574cd18b9 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -539,8 +539,8 @@ Dostupné hodnoty jsou Trace, Debug, Information, Warning, Error a Critical. - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf index c43270625f..4517511eff 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -539,8 +539,8 @@ Die verfügbaren Werte sind "Trace", "Debug", "Information", "Warning", "Error" - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf index b22ade1e23..d0d63bebd0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -539,8 +539,8 @@ Los valores disponibles son 'Seguimiento', 'Depurar', 'Información', 'Advertenc - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf index a64d3bc10f..5a705374cd 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -539,8 +539,8 @@ Les valeurs disponibles sont « Trace », « Debug », « Information », - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf index 03b898e1a9..b08a309ae3 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -539,8 +539,8 @@ I valori disponibili sono 'Trace', 'Debug', 'Information', 'Warning', 'Error' e - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf index 7a849bc4f7..5a06691f95 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -540,8 +540,8 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf index c95d167154..6ed7dc2c13 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -539,8 +539,8 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf index 30ce09a762..eaafb3599b 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -539,8 +539,8 @@ Dostępne wartości to „Trace”, „Debug”, „Information”, „Warning - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf index ff301c8c90..8683d75595 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pt-BR.xlf @@ -539,8 +539,8 @@ Os valores disponíveis são 'Rastreamento', 'Depuração', 'Informação', 'Avi - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf index 4396c286f6..5567e817a8 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -539,8 +539,8 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf index 527b31dfe5..39c2e84d16 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -539,8 +539,8 @@ Kullanılabilir değerler: 'Trace', 'Debug', 'Information', 'Warning', 'Error' v - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf index b026432596..b3a323045d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hans.xlf @@ -539,8 +539,8 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf index 01a72b262d..17f154bcbd 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.zh-Hant.xlf @@ -539,8 +539,8 @@ The available values are 'Trace', 'Debug', 'Information', 'Warning', 'Error', an - Specifies a list of test node uids to filter. - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. + Provides a list of test node UIDs to filter by. diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs index ac8eb81e69..f65ad6d7c4 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -46,7 +46,7 @@ Output directory of the diagnostic logging. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. --filter-uid - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. --help Show the command line help. --ignore-exit-code diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index fb3bf3d6c0..aafda088c6 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -40,7 +40,7 @@ Output directory of the diagnostic logging. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. --filter-uid - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. --help Show the command line help. --ignore-exit-code @@ -188,7 +188,7 @@ Note that this is slowing down the test execution\. --filter-uid Arity: 1\.\.N Hidden: False - Description: Specifies a list of test node uids to filter\. + Description: Provides a list of test node UIDs to filter by\. --help Arity: 0 Hidden: False @@ -297,7 +297,7 @@ Output directory of the diagnostic logging. --exit-on-process-exit Exit the test process if dependent process exits. PID must be provided. --filter-uid - Specifies a list of test node uids to filter. + Provides a list of test node UIDs to filter by. --help Show the command line help. --ignore-exit-code @@ -456,7 +456,7 @@ Note that this is slowing down the test execution. --filter-uid Arity: 1\.\.N Hidden: False - Description: Specifies a list of test node uids to filter\. + Description: Provides a list of test node UIDs to filter by\. --help Arity: 0 Hidden: False From 0fdd76271f06f07078c536caeeeaf2c94bc9227d Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 14 Jul 2025 10:05:14 +0200 Subject: [PATCH 3/3] Fix test --- .../HelpInfoTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs index aafda088c6..49ec524d6f 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/HelpInfoTests.cs @@ -454,9 +454,9 @@ Note that this is slowing down the test execution. Hidden: False Description: Exit the test process if dependent process exits. PID must be provided. --filter-uid - Arity: 1\.\.N + Arity: 1..N Hidden: False - Description: Provides a list of test node UIDs to filter by\. + Description: Provides a list of test node UIDs to filter by. --help Arity: 0 Hidden: False