From ae25bec97456414cb33c1b398f32576a77a5eba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 12 Dec 2025 10:25:56 +0100 Subject: [PATCH 1/2] WIP --- .../CommandLine/CommandLineHandler.cs | 15 +++++++++-- .../CommandLine/CommandLineOption.cs | 18 ++++++++++--- .../CommandLineOptionsValidator.cs | 26 +++++++++++++++++++ .../Hosts/TestHostBuilder.cs | 11 +++++++- .../Resources/PlatformResources.resx | 3 +++ .../Resources/xlf/PlatformResources.cs.xlf | 5 ++++ .../Resources/xlf/PlatformResources.de.xlf | 5 ++++ .../Resources/xlf/PlatformResources.es.xlf | 5 ++++ .../Resources/xlf/PlatformResources.fr.xlf | 5 ++++ .../Resources/xlf/PlatformResources.it.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ja.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ko.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pl.xlf | 5 ++++ .../Resources/xlf/PlatformResources.pt-BR.xlf | 5 ++++ .../Resources/xlf/PlatformResources.ru.xlf | 5 ++++ .../Resources/xlf/PlatformResources.tr.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hans.xlf | 5 ++++ .../xlf/PlatformResources.zh-Hant.xlf | 5 ++++ .../DotnetTest/DotnetTestConnection.cs | 3 ++- .../IPC/Models/CommandLineOptionMessages.cs | 2 +- .../DotnetTest/IPC/ObjectFieldIds.cs | 1 + .../CommandLineOptionMessagesSerializer.cs | 16 +++++++++--- 22 files changed, 148 insertions(+), 12 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineHandler.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineHandler.cs index c2e5cdb6f8..cfed372f38 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineHandler.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineHandler.cs @@ -112,7 +112,8 @@ async Task DisplayOptionsAsync(IOutputDevice outputDevice, IEnumerable x.Name)) { - await outputDevice.DisplayAsync(this, new TextOutputDeviceData($"{optionNameIndent}--{option.Name}"), cancellationToken).ConfigureAwait(false); + string optionName = option.ObsolescenceMessage is not null ? $"{optionNameIndent}--{option.Name} [obsolete]" : $"{optionNameIndent}--{option.Name}"; + await outputDevice.DisplayAsync(this, new TextOutputDeviceData(optionName), cancellationToken).ConfigureAwait(false); if (option.Arity.Min == option.Arity.Max) { await outputDevice.DisplayAsync(this, new TextOutputDeviceData($"{optionInfoIndent}Arity: {option.Arity.Min}"), cancellationToken).ConfigureAwait(false); @@ -125,6 +126,10 @@ async Task DisplayOptionsAsync(IOutputDevice outputDevice, IEnumerable /// The arity of the command line option. /// Indicates whether the command line option is hidden. /// Indicates whether the command line option is built-in. - internal CommandLineOption(string name, string description, ArgumentArity arity, bool isHidden, bool isBuiltIn) + /// The obsolescence message for the command line option. + internal CommandLineOption(string name, string description, ArgumentArity arity, bool isHidden, bool isBuiltIn, string? obsolescenceMessage = null) { Guard.NotNullOrWhiteSpace(name); Guard.NotNullOrWhiteSpace(description); @@ -37,6 +38,7 @@ internal CommandLineOption(string name, string description, ArgumentArity arity, Arity = arity; IsHidden = isHidden; IsBuiltIn = isBuiltIn; + ObsolescenceMessage = obsolescenceMessage; } /// @@ -46,12 +48,13 @@ internal CommandLineOption(string name, string description, ArgumentArity arity, /// The description of the command line option. /// The arity of the command line option. /// Indicates whether the command line option is hidden. + /// The obsolescence message for the command line option. /// /// This ctor is public and used by non built-in extension, we need to know if the extension is built-in or not /// to correctly handle the --internal- prefix. /// - public CommandLineOption(string name, string description, ArgumentArity arity, bool isHidden) - : this(name, description, arity, isHidden, isBuiltIn: false) + public CommandLineOption(string name, string description, ArgumentArity arity, bool isHidden, string? obsolescenceMessage = null) + : this(name, description, arity, isHidden, isBuiltIn: false, obsolescenceMessage) { } @@ -77,6 +80,11 @@ public CommandLineOption(string name, string description, ArgumentArity arity, b internal bool IsBuiltIn { get; } + /// + /// Gets the obsolescence message for the command line option. + /// + public string? ObsolescenceMessage { get; } + /// public override bool Equals(object? obj) => Equals(obj as CommandLineOption); @@ -86,7 +94,8 @@ public bool Equals(CommandLineOption? other) Name == other.Name && Description == other.Description && Arity == other.Arity && - IsHidden == other.IsHidden; + IsHidden == other.IsHidden && + ObsolescenceMessage == other.ObsolescenceMessage; /// public override int GetHashCode() @@ -96,6 +105,7 @@ public override int GetHashCode() hc.Add(Description); hc.Add(Arity.GetHashCode()); hc.Add(IsHidden); + hc.Add(ObsolescenceMessage); return hc.ToHashCode(); } } diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs index 9ea02b9a03..13f4f5d0be 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOptionsValidator.cs @@ -3,7 +3,9 @@ using Microsoft.Testing.Platform.Extensions; using Microsoft.Testing.Platform.Extensions.CommandLine; +using Microsoft.Testing.Platform.Extensions.OutputDevice; using Microsoft.Testing.Platform.Helpers; +using Microsoft.Testing.Platform.OutputDevice; using Microsoft.Testing.Platform.Resources; namespace Microsoft.Testing.Platform.CommandLine; @@ -68,6 +70,30 @@ public static async Task ValidateAsync( return await ValidateConfigurationAsync(extensionOptionsByProvider.Keys, systemOptionsByProvider.Keys, commandLineOptions).ConfigureAwait(false); } + public static async Task CheckForObsoleteOptionsAsync( + CommandLineParseResult commandLineParseResult, + IEnumerable systemCommandLineOptionsProviders, + IEnumerable extensionCommandLineOptionsProviders, + IOutputDevice outputDevice, + IOutputDeviceDataProducer outputDeviceDataProducer, + CancellationToken cancellationToken) + { + var allOptions = systemCommandLineOptionsProviders + .Union(extensionCommandLineOptionsProviders) + .SelectMany(provider => provider.GetCommandLineOptions()) + .Where(option => option.ObsolescenceMessage is not null) + .ToDictionary(option => option.Name); + + foreach (CommandLineParseOption optionRecord in commandLineParseResult.Options) + { + if (allOptions.TryGetValue(optionRecord.Name, out CommandLineOption? option)) + { + string warningMessage = string.Format(CultureInfo.InvariantCulture, PlatformResources.CommandLineOptionObsoleteWarning, optionRecord.Name, option.ObsolescenceMessage); + await outputDevice.DisplayAsync(outputDeviceDataProducer, new WarningMessageOutputDeviceData(warningMessage), cancellationToken).ConfigureAwait(false); + } + } + } + private static ValidationResult ValidateExtensionOptionsDoNotContainReservedPrefix( Dictionary> extensionOptionsByProvider) { diff --git a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs index 1add332506..2d171f6330 100644 --- a/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs +++ b/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs @@ -139,7 +139,7 @@ public async Task BuildAsync( // relies on unhandled exception. // Check the config file, by default is not specified the policy is false. - _ = bool.TryParse(configuration[PlatformConfigurationConstants.PlatformExitProcessOnUnhandledException]!, out bool isFileConfiguredToFailFast); + _ = bool.TryParse(configuration[PlatformConfigurationConstants.PlatformExitProcessOnUnhandledException], out bool isFileConfiguredToFailFast); // Check the environment variable, it wins on all the other configuration. string? environmentSetting = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_EXIT_PROCESS_ON_UNHANDLED_EXCEPTION); @@ -249,6 +249,15 @@ public async Task BuildAsync( return new InformativeCommandLineHost(ExitCodes.InvalidCommandLine, serviceProvider); } + // Check for obsolete options and display warnings + await CommandLineOptionsValidator.CheckForObsoleteOptionsAsync( + loggingState.CommandLineParseResult, + commandLineHandler.SystemCommandLineOptionsProviders, + commandLineHandler.ExtensionsCommandLineOptionsProviders, + proxyOutputDevice, + commandLineHandler, + testApplicationCancellationTokenSource.CancellationToken).ConfigureAwait(false); + // Register as ICommandLineOptions. serviceProvider.TryAddService(commandLineHandler); diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index 036efd79e9..91d7026151 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -316,6 +316,9 @@ Option '--{0}' is reserved and cannot be used by providers: '{0}' + + Warning: Option '--{0}' is obsolete. {1} + Unexpected argument {0} 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 41efbbe3b5..6a2ee3f42d 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -117,6 +117,11 @@ Možnost --{0} je vyhrazená a nelze ji použít zprostředkovateli: {0} + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' Možnost --{0} od zprostředkovatele {1} (UID: {2}) používá vyhrazenou předponu --internal. 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 6dafbd92ae..c52620b107 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -117,6 +117,11 @@ Die Option "--{0}" ist reserviert und kann nicht von Anbietern verwendet werden: "{0}" + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' Die Option "--{0}" vom Anbieter "{1}" (UID: {2}) verwendet das reservierte Präfix "--internal". 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 ca22203490..94fbb9e448 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -117,6 +117,11 @@ La opción “--{0}” está reservada y los proveedores no la pueden usar: “{0}” + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' La opción “--{0}” del proveedor “{1}” (UID: {2}) usa el prefijo reservado “--internal” 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 e341f04865..2031260867 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -117,6 +117,11 @@ L’option « --{0} » est réservée et ne peut pas être utilisée par les fournisseurs : « {0} » + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' L’option « --{0} » du fournisseur « {1} » (UID : {2}) utilise le préfixe réservé « --internal » 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 5a0fe9b87c..184dce3af1 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -117,6 +117,11 @@ L'opzione '--{0}' è riservata e non può essere usata dai provider: '{0}' + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' L'opzione '--{0}' del provider '{1}' (UID: {2}) usa il prefisso riservato '--internal' 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 6f402ad9c9..a9575cfcfa 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -117,6 +117,11 @@ オプション '--{0}' は予約されており、プロバイダーでは使用できません: '{0}' + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' プロバイダー '{1}' のオプション '--{0}' (UID:{2}) は予約済みプレフィックス '--internal' を 使用しています 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 519426f952..c1aaddec55 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -117,6 +117,11 @@ '--{0}' 옵션은 예약되어 있으므로 공급자 '{0}'이(가) 사용할 수 없습니다. + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' 공급자 '{1}'(UID: {2})의 옵션 '-- {0}'이 예약된 접두사 '--internal'을 사용하고 있습니다. 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 ec53ed7191..1927442177 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -117,6 +117,11 @@ Opcja „--{0}” jest zastrzeżona i nie może być używana przez dostawców: „{0}” + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' Opcja „--{0}” od dostawcy „{1}” (UID: {2}) używa zastrzeżonego prefiksu „--internal” 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 5a2bc95a8f..0a93d55917 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 @@ -117,6 +117,11 @@ A opção '--{0}' está reservada e não pode ser usada pelos provedores: '{0}' + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' A opção '--{0}' do provedor '{1}' (UID: {2}) está usando o prefixo reservado '--internal' 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 30201fcdff..a9b0e12f72 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -117,6 +117,11 @@ Параметр "--{0}" зарезервирован и не может использоваться поставщиками: "{0}" + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' Параметр "--{0}" от поставщика "{1}" (UID: {2}) использует зарезервированный префикс "--internal" 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 36dc259dc6..5080be01ce 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -117,6 +117,11 @@ '--{0}' seçeneği ayrılmıştır ve şu sağlayıcılar tarafından kullanılamaz: '{0}' + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' '{1}' sağlayıcısındaki (UID: {2}) `--{0}` seçeneği ayrılmış '--internal' önekini kullanıyor 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 08a9beb56e..82e6280bf2 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 @@ -117,6 +117,11 @@ 选项“--{0}”是保留的,提供程序不能使用:“{0}” + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' 来自提供程序“{1}” (UID: {2}) 的选项“--{0}”正在使用保留前缀“--internal” 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 a35747c7cb..13e0525d85 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 @@ -117,6 +117,11 @@ 選項 '--{0}' 已保留,無法供提供者 '{0}' 使用 + + Warning: Option '--{0}' is obsolete. {1} + Warning: Option '--{0}' is obsolete. {1} + + Option `--{0}` from provider '{1}' (UID: {2}) is using the reserved prefix '--internal' 提供者 '{1}' (UID: {2}) 中的選項 '--{0}' 使用保留的前置詞 '--internal' diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/DotnetTestConnection.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/DotnetTestConnection.cs index d71ee14538..21f187393f 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/DotnetTestConnection.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/DotnetTestConnection.cs @@ -77,7 +77,8 @@ public async Task HelpInvokedAsync() commandLineOption.Name, commandLineOption.Description, commandLineOption.IsHidden, - commandLineOption.IsBuiltIn)); + commandLineOption.IsBuiltIn, + commandLineOption.ObsolescenceMessage)); } } diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Models/CommandLineOptionMessages.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Models/CommandLineOptionMessages.cs index 5691de32c3..a9ffbc99c5 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Models/CommandLineOptionMessages.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Models/CommandLineOptionMessages.cs @@ -3,6 +3,6 @@ namespace Microsoft.Testing.Platform.IPC.Models; -internal sealed record CommandLineOptionMessage(string? Name, string? Description, bool? IsHidden, bool? IsBuiltIn); +internal sealed record CommandLineOptionMessage(string? Name, string? Description, bool? IsHidden, bool? IsBuiltIn, string? ObsolescenceMessage); internal sealed record CommandLineOptionMessages(string? ModulePath, CommandLineOptionMessage[]? CommandLineOptionMessageList) : IRequest; diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs index dc61f0c85f..451a7e250a 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/ObjectFieldIds.cs @@ -36,6 +36,7 @@ internal static class CommandLineOptionMessageFieldsId public const ushort Description = 2; public const ushort IsHidden = 3; public const ushort IsBuiltIn = 4; + public const ushort ObsolescenceMessage = 5; } internal static class DiscoveredTestMessagesFieldsId diff --git a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/CommandLineOptionMessagesSerializer.cs b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/CommandLineOptionMessagesSerializer.cs index 0e75677bd1..af59a4a894 100644 --- a/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/CommandLineOptionMessagesSerializer.cs +++ b/src/Platform/Microsoft.Testing.Platform/ServerMode/DotnetTest/IPC/Serializers/CommandLineOptionMessagesSerializer.cs @@ -34,6 +34,10 @@ namespace Microsoft.Testing.Platform.IPC.Serializers; |---CommandLineOptionMessageList[0].IsBuiltIn Id---| (2 bytes) |---CommandLineOptionMessageList[0].IsBuiltIn Size---| (4 bytes) |---CommandLineOptionMessageList[0].IsBuiltIn Value---| (1 byte) + + |---CommandLineOptionMessageList[0].ObsolescenceMessage Id---| (2 bytes) + |---CommandLineOptionMessageList[0].ObsolescenceMessage Size---| (4 bytes) + |---CommandLineOptionMessageList[0].ObsolescenceMessage Value---| (n bytes) */ internal sealed class CommandLineOptionMessagesSerializer : BaseSerializer, INamedPipeSerializer @@ -79,7 +83,7 @@ private static List ReadCommandLineOptionMessagesPaylo int length = ReadInt(stream); for (int i = 0; i < length; i++) { - string? name = null, description = null; + string? name = null, description = null, obsolescenceMessage = null; bool? isHidden = null, isBuiltIn = null; int fieldCount = ReadUShort(stream); @@ -107,13 +111,17 @@ private static List ReadCommandLineOptionMessagesPaylo isBuiltIn = ReadBool(stream); break; + case CommandLineOptionMessageFieldsId.ObsolescenceMessage: + obsolescenceMessage = ReadStringValue(stream, fieldSize); + break; + default: SetPosition(stream, stream.Position + fieldSize); break; } } - commandLineOptionMessages.Add(new CommandLineOptionMessage(name, description, isHidden, isBuiltIn)); + commandLineOptionMessages.Add(new CommandLineOptionMessage(name, description, isHidden, isBuiltIn, obsolescenceMessage)); } return commandLineOptionMessages; @@ -154,6 +162,7 @@ private static void WriteCommandLineOptionMessagesPayload(Stream stream, Command WriteField(stream, CommandLineOptionMessageFieldsId.Description, commandLineOptionMessage.Description); WriteField(stream, CommandLineOptionMessageFieldsId.IsHidden, commandLineOptionMessage.IsHidden); WriteField(stream, CommandLineOptionMessageFieldsId.IsBuiltIn, commandLineOptionMessage.IsBuiltIn); + WriteField(stream, CommandLineOptionMessageFieldsId.ObsolescenceMessage, commandLineOptionMessage.ObsolescenceMessage); } // NOTE: We are able to seek only if we are using a MemoryStream @@ -169,5 +178,6 @@ private static ushort GetFieldCount(CommandLineOptionMessage commandLineOptionMe (ushort)((commandLineOptionMessage.Name is null ? 0 : 1) + (commandLineOptionMessage.Description is null ? 0 : 1) + (commandLineOptionMessage.IsHidden is null ? 0 : 1) + - (commandLineOptionMessage.IsBuiltIn is null ? 0 : 1)); + (commandLineOptionMessage.IsBuiltIn is null ? 0 : 1) + + (commandLineOptionMessage.ObsolescenceMessage is null ? 0 : 1)); } From fe2ab96d400bf24b88efbfec3cf2a47595ff1de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 12 Dec 2025 11:12:24 +0100 Subject: [PATCH 2/2] Fix --- .../CommandLine/CommandLineOption.cs | 16 ++++++++++++++++ .../Helpers/HashCode.cs | 2 +- .../PublicAPI/PublicAPI.Unshipped.txt | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs index 1c4a85a0e4..32dfc8070c 100644 --- a/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs +++ b/src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs @@ -58,6 +58,22 @@ public CommandLineOption(string name, string description, ArgumentArity arity, b { } + /// + /// Initializes a new instance of the class. + /// + /// The name of the command line option. + /// The description of the command line option. + /// The arity of the command line option. + /// Indicates whether the command line option is hidden. + /// + /// This ctor is public and used by non built-in extension, we need to know if the extension is built-in or not + /// to correctly handle the --internal- prefix. + /// + public CommandLineOption(string name, string description, ArgumentArity arity, bool isHidden) + : this(name, description, arity, isHidden, isBuiltIn: false, null) + { + } + /// /// Gets the name of the command line option. /// diff --git a/src/Platform/Microsoft.Testing.Platform/Helpers/HashCode.cs b/src/Platform/Microsoft.Testing.Platform/Helpers/HashCode.cs index 147c8930fd..cb0b11a3aa 100644 --- a/src/Platform/Microsoft.Testing.Platform/Helpers/HashCode.cs +++ b/src/Platform/Microsoft.Testing.Platform/Helpers/HashCode.cs @@ -11,7 +11,7 @@ internal struct HashCode public HashCode() => _hash = 17; - public void Add(string value) + public void Add(string? value) { // Overflow is fine, just wrap unchecked diff --git a/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt b/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt index 7dc5c58110..efcc8e2a62 100644 --- a/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt +++ b/src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt @@ -1 +1,3 @@ #nullable enable +Microsoft.Testing.Platform.Extensions.CommandLine.CommandLineOption.CommandLineOption(string! name, string! description, Microsoft.Testing.Platform.Extensions.CommandLine.ArgumentArity arity, bool isHidden, string? obsolescenceMessage = null) -> void +Microsoft.Testing.Platform.Extensions.CommandLine.CommandLineOption.ObsolescenceMessage.get -> string?