From c53a3fc5e2d5a446608a1e3d302d4c48c3583c5b Mon Sep 17 00:00:00 2001 From: Evangelink <11340282+Evangelink@users.noreply.github.com> Date: Wed, 20 May 2026 15:33:50 +0200 Subject: [PATCH 1/3] Add new diagnostic env var names matching renamed CLI options The CLI options `--diagnostic-output-fileprefix` and `--diagnostic-filelogger-synchronouswrite` were renamed to `--diagnostic-file-prefix` and `--diagnostic-synchronous-write`, but the corresponding env vars kept their old names. This adds new env var names that align with the new CLI option names, while keeping the legacy names working for backward compatibility. The new names take precedence; legacy names are documented as deprecated and can be removed in the next breaking-change version. Fixes #7159 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Builder/TestApplication.cs | 24 ++++++-- .../Helpers/EnvironmentVariableConstants.cs | 8 +++ .../DiagnosticTests.cs | 61 +++++++++++++++++++ 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index ece463b364..00daf8340a 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -341,8 +341,16 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( prefixName = prefixNameArg[0]; } - // Override the prefix name - string? environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); + // Override the prefix name. + // Prefer the new TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX env var (matching the --diagnostic-file-prefix CLI option), + // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX for backward compatibility. + // See https://github.com/microsoft/testfx/issues/7159. + string? environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX); + if (RoslynString.IsNullOrEmpty(environmentFilePrefix)) + { + environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); + } + if (!RoslynString.IsNullOrEmpty(environmentFilePrefix)) { prefixName = environmentFilePrefix; @@ -350,8 +358,16 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( bool synchronousWrite = result.IsOptionSet(PlatformCommandLineProvider.DiagnosticFileLoggerSynchronousWriteOptionKey); - // Override the synchronous write - string? environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); + // Override the synchronous write. + // Prefer the new TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE env var (matching the --diagnostic-synchronous-write CLI option), + // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE for backward compatibility. + // See https://github.com/microsoft/testfx/issues/7159. + string? environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE); + if (RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) + { + environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); + } + if (!RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) { synchronousWrite = environmentSynchronousWrite == "1"; diff --git a/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs b/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs index 21fcb57a77..0065a98b37 100644 --- a/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs +++ b/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs @@ -23,8 +23,16 @@ internal static class EnvironmentVariableConstants public const string TESTINGPLATFORM_DIAGNOSTIC = nameof(TESTINGPLATFORM_DIAGNOSTIC); public const string TESTINGPLATFORM_DIAGNOSTIC_VERBOSITY = nameof(TESTINGPLATFORM_DIAGNOSTIC_VERBOSITY); public const string TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_DIRECTORY = nameof(TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_DIRECTORY); + + // Deprecated: kept for backward compatibility. Prefer TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX + // which matches the --diagnostic-file-prefix CLI option (see https://github.com/microsoft/testfx/issues/7159). public const string TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX = nameof(TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); + public const string TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX = nameof(TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX); + + // Deprecated: kept for backward compatibility. Prefer TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE + // which matches the --diagnostic-synchronous-write CLI option (see https://github.com/microsoft/testfx/issues/7159). public const string TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE = nameof(TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); + public const string TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE = nameof(TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE); public const string TESTINGPLATFORM_NOBANNER = nameof(TESTINGPLATFORM_NOBANNER); public const string TESTINGPLATFORM_EXITCODE_IGNORE = nameof(TESTINGPLATFORM_EXITCODE_IGNORE); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs index bf4b936ea8..7b79dc56f1 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs @@ -157,6 +157,47 @@ public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_Succeeded(str await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_NewName_Succeeded(string tfm) + { + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPathPattern = Path.Combine(diagPath, @"MyPrefix_.*.diag").Replace(@"\", @"\\"); + + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync( + null, + new Dictionary + { + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC, "1" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX, "MyPrefix" }, + }, + cancellationToken: TestContext.CancellationToken); + + await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); + } + + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_NewNameTakesPrecedence(string tfm) + { + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPathPattern = Path.Combine(diagPath, @"NewPrefix_.*.diag").Replace(@"\", @"\\"); + + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync( + null, + new Dictionary + { + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC, "1" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX, "OldPrefix" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX, "NewPrefix" }, + }, + cancellationToken: TestContext.CancellationToken); + + await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); + } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_Succeeded(string tfm) @@ -177,6 +218,26 @@ public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_Succeeded await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_NewName_Succeeded(string tfm) + { + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); + + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + TestHostResult testHostResult = await testHost.ExecuteAsync( + null, + new Dictionary + { + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC, "1" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE, "1" }, + }, + cancellationToken: TestContext.CancellationToken); + + await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); + } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_Disable_Succeeded(string tfm) From 367e4cba8ed046e7f661bbc806f000cca209f20f Mon Sep 17 00:00:00 2001 From: Evangelink <11340282+Evangelink@users.noreply.github.com> Date: Wed, 20 May 2026 16:26:47 +0200 Subject: [PATCH 2/3] Emit deprecation warning when legacy diagnostic env vars are used When the legacy `TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX` or `TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE` environment variables are detected, write a localized warning to the console pointing users at the new `TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX` / `TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE` names. The legacy names still work; the warning fires whenever they are set (including when overridden by the new name) so callers always know to migrate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Builder/TestApplication.cs | 24 +++++++++++++++++-- .../Resources/PlatformResources.resx | 4 ++++ .../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 ++++ .../DiagnosticTests.cs | 7 ++++++ 16 files changed, 98 insertions(+), 2 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index 00daf8340a..0100cb0dc9 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -346,9 +346,19 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX for backward compatibility. // See https://github.com/microsoft/testfx/issues/7159. string? environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX); + string? legacyEnvironmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); + if (!RoslynString.IsNullOrEmpty(legacyEnvironmentFilePrefix)) + { + console.WriteLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.DeprecatedEnvironmentVariableWarning, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX)); + } + if (RoslynString.IsNullOrEmpty(environmentFilePrefix)) { - environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); + environmentFilePrefix = legacyEnvironmentFilePrefix; } if (!RoslynString.IsNullOrEmpty(environmentFilePrefix)) @@ -363,9 +373,19 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE for backward compatibility. // See https://github.com/microsoft/testfx/issues/7159. string? environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE); + string? legacyEnvironmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); + if (!RoslynString.IsNullOrEmpty(legacyEnvironmentSynchronousWrite)) + { + console.WriteLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.DeprecatedEnvironmentVariableWarning, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE)); + } + if (RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) { - environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); + environmentSynchronousWrite = legacyEnvironmentSynchronousWrite; } if (!RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) diff --git a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx index a8c61bb779..475c56ea18 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx +++ b/src/Platform/Microsoft.Testing.Platform/Resources/PlatformResources.resx @@ -710,6 +710,10 @@ Takes one argument as string in the format <value>[h|m|s] where 'value' is Exception during the cancellation of request id '{0}' {0} is the request id + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Specifies a maximum number of test failures that, when exceeded, will abort the test run. 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 9cc7e90625..4d3a35d961 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.cs.xlf @@ -207,6 +207,11 @@ Nepodařilo se najít adresář {0}. + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Diagnostický soubor (úroveň {0} s asynchronním vyprázdněním): {1} 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 db640a34ff..0b755d72f0 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.de.xlf @@ -207,6 +207,11 @@ Das Verzeichnis "{0}" konnte nicht gefunden werden + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Diagnosedatei (Ebene „{0}“ mit asynchroner Leerung): {1} 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 d0981b8051..b825b7ff80 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.es.xlf @@ -207,6 +207,11 @@ No se pudo encontrar el directorio '{0}' + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Archivo de diagnóstico (nivel '{0}' con vaciado asincrónico): {1} 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 5987fbabc4..10ba8d0ec6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.fr.xlf @@ -207,6 +207,11 @@ Répertoire « {0} » introuvable. + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Fichier de diagnostic (niveau « {0} » avec vidage asynchrone) : {1} 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 2d3f0a5669..8a67c2cf18 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.it.xlf @@ -207,6 +207,11 @@ Non è stato possibile trovare la directory '{0}' + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} File di diagnostica (livello '{0}' con scaricamento asincrono): {1} 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 345e8e77e8..650e4e1e43 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ja.xlf @@ -207,6 +207,11 @@ ディレクトリ '{0}' が見つかりませんでした。 + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} 診断ファイル (レベル '{0}' で非同期フラッシュ): {1} 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 7e47462a34..3d791db029 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ko.xlf @@ -207,6 +207,11 @@ {0} 디렉터리를 찾을 수 없음 + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} 진단 파일(비동기 플러시를 사용한 수준 '{0}'): {1} 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 995df74b48..8f05de6c63 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.pl.xlf @@ -207,6 +207,11 @@ Nie można odnaleźć katalogu „{0}”. + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Plik diagnostyczny (poziom „{0}” z asynchronicznym opróżnianiem): {1} 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 f49166d4f5..4a20a7a933 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 @@ -207,6 +207,11 @@ Não foi possível localizar o diretório “{0}” + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Arquivo de diagnóstico (nível "{0}" com liberação assíncrona): {1} 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 2f2dac8d12..a76371e0e6 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.ru.xlf @@ -207,6 +207,11 @@ Не удалось найти каталог "{0}". + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Файл диагностики (уровень '{0}' асинхронной очисткой): {1} 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 c1d6bfbdc4..61b91cd5ba 100644 --- a/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf +++ b/src/Platform/Microsoft.Testing.Platform/Resources/xlf/PlatformResources.tr.xlf @@ -207,6 +207,11 @@ '{0}' dizini bulunamadı + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} Tanılama dosyası (zaman uyumsuz boşaltma ile düzey '{0}'): {1} 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 67d231b4d4..0a280216e2 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 @@ -207,6 +207,11 @@ 找不到目录“{0}” + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} 诊断文件(具有异步刷新的级别“{0}”): {1} 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 2493975abc..b179a83eab 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 @@ -207,6 +207,11 @@ 找不到目錄 '{0}' + + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + Warning: The environment variable '{0}' is deprecated and will be removed in a future major version. Use '{1}' instead. + {0} is the deprecated environment variable name, {1} is the replacement environment variable name. + Diagnostic file (level '{0}' with async flush): {1} 診斷檔案 (具有非同步排清的層級 '{0}'): {1} diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs index 7b79dc56f1..5f69aea44a 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs @@ -155,6 +155,7 @@ public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_Succeeded(str cancellationToken: TestContext.CancellationToken); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); + testHostResult.AssertOutputContains($"Warning: The environment variable '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX}' is deprecated and will be removed in a future major version. Use '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX}' instead."); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -175,6 +176,7 @@ public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_NewName_Succe cancellationToken: TestContext.CancellationToken); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); + testHostResult.AssertOutputDoesNotContain("is deprecated and will be removed in a future major version"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -196,6 +198,9 @@ public async Task Diag_EnableWithEnvironmentVariables_CustomPrefix_NewNameTakesP cancellationToken: TestContext.CancellationToken); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern); + + // Setting the legacy env var should still warn even when the new one is also set and wins. + testHostResult.AssertOutputContains($"Warning: The environment variable '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX}' is deprecated and will be removed in a future major version. Use '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX}' instead."); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -216,6 +221,7 @@ public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_Succeeded cancellationToken: TestContext.CancellationToken); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); + testHostResult.AssertOutputContains($"Warning: The environment variable '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE}' is deprecated and will be removed in a future major version. Use '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE}' instead."); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] @@ -236,6 +242,7 @@ public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_NewName_S cancellationToken: TestContext.CancellationToken); await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); + testHostResult.AssertOutputDoesNotContain("is deprecated and will be removed in a future major version"); } [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] From 2041ea1fc34d22dc29dc37849b43e9518e1d534c Mon Sep 17 00:00:00 2001 From: Evangelink <11340282+Evangelink@users.noreply.github.com> Date: Wed, 20 May 2026 17:26:25 +0200 Subject: [PATCH 3/3] Address review feedback: [Obsolete] legacy constants and add symmetric precedence test - Mark legacy diagnostic env var constants TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX and TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE with [Obsolete(error: false)] so any new internal call site fails the build, and suppress the warnings only at the intentional back-compat fallback sites in TestApplication.cs and at the file-wide level in DiagnosticTests.cs which exercises the legacy names on purpose. - Add Diag_EnableWithEnvironmentVariables_SynchronousWrite_NewNameTakesPrecedence test, symmetric to the existing CustomPrefix_NewNameTakesPrecedence test, to lock in the precedence rule for the synchronous-write env var pair as well. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Builder/TestApplication.cs | 4 +++ .../Helpers/EnvironmentVariableConstants.cs | 6 ++-- .../DiagnosticTests.cs | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index 0100cb0dc9..d8a17b5e83 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -346,6 +346,7 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX for backward compatibility. // See https://github.com/microsoft/testfx/issues/7159. string? environmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX); +#pragma warning disable CS0618 // Type or member is obsolete - intentional back-compat fallback to the legacy env var. string? legacyEnvironmentFilePrefix = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); if (!RoslynString.IsNullOrEmpty(legacyEnvironmentFilePrefix)) { @@ -355,6 +356,7 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX, EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX)); } +#pragma warning restore CS0618 if (RoslynString.IsNullOrEmpty(environmentFilePrefix)) { @@ -373,6 +375,7 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( // but fall back to the legacy TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE for backward compatibility. // See https://github.com/microsoft/testfx/issues/7159. string? environmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE); +#pragma warning disable CS0618 // Type or member is obsolete - intentional back-compat fallback to the legacy env var. string? legacyEnvironmentSynchronousWrite = environment.GetEnvironmentVariable(EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); if (!RoslynString.IsNullOrEmpty(legacyEnvironmentSynchronousWrite)) { @@ -382,6 +385,7 @@ private static ApplicationLoggingState CreateFileLoggerIfDiagnosticIsEnabled( EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE, EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE)); } +#pragma warning restore CS0618 if (RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) { diff --git a/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs b/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs index 0065a98b37..6073f436bd 100644 --- a/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs +++ b/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs @@ -24,13 +24,11 @@ internal static class EnvironmentVariableConstants public const string TESTINGPLATFORM_DIAGNOSTIC_VERBOSITY = nameof(TESTINGPLATFORM_DIAGNOSTIC_VERBOSITY); public const string TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_DIRECTORY = nameof(TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_DIRECTORY); - // Deprecated: kept for backward compatibility. Prefer TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX - // which matches the --diagnostic-file-prefix CLI option (see https://github.com/microsoft/testfx/issues/7159). + [Obsolete("Use " + nameof(TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX) + " instead. This name matches the renamed --diagnostic-file-prefix CLI option (see https://github.com/microsoft/testfx/issues/7159). Kept for backward compatibility and may be removed in a future major version.", error: false)] public const string TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX = nameof(TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX); public const string TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX = nameof(TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX); - // Deprecated: kept for backward compatibility. Prefer TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE - // which matches the --diagnostic-synchronous-write CLI option (see https://github.com/microsoft/testfx/issues/7159). + [Obsolete("Use " + nameof(TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE) + " instead. This name matches the renamed --diagnostic-synchronous-write CLI option (see https://github.com/microsoft/testfx/issues/7159). Kept for backward compatibility and may be removed in a future major version.", error: false)] public const string TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE = nameof(TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE); public const string TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE = nameof(TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE); public const string TESTINGPLATFORM_NOBANNER = nameof(TESTINGPLATFORM_NOBANNER); diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs index 5f69aea44a..943336961c 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/DiagnosticTests.cs @@ -1,6 +1,11 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// Suppress CS0618 for the entire file: we intentionally exercise the deprecated legacy +// diagnostic environment variable constants (TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX, +// TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE) to validate back-compat behavior. +#pragma warning disable CS0618 // Type or member is obsolete + using Microsoft.Testing.Platform.Configurations; namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; @@ -245,6 +250,33 @@ public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_NewName_S testHostResult.AssertOutputDoesNotContain("is deprecated and will be removed in a future major version"); } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] + [TestMethod] + public async Task Diag_EnableWithEnvironmentVariables_SynchronousWrite_NewNameTakesPrecedence(string tfm) + { + string diagPath = Path.Combine(AssetFixture.TargetAssetPath, "bin", "Release", tfm, AggregatedConfiguration.DefaultTestResultFolderName); + string diagPathPattern = Path.Combine(diagPath, @"log_.*.diag").Replace(@"\", @"\\"); + + var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, tfm); + + // Legacy env var would request async flush ("0"), the new env var requests sync flush ("1"). + // The new env var must win => the diagnostic report should be written with sync flush. + TestHostResult testHostResult = await testHost.ExecuteAsync( + null, + new Dictionary + { + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC, "1" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE, "0" }, + { EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE, "1" }, + }, + cancellationToken: TestContext.CancellationToken); + + await AssertDiagnosticReportWasGeneratedAsync(testHostResult, diagPathPattern, flushType: "sync"); + + // Setting the legacy env var should still warn even when the new one is also set and wins. + testHostResult.AssertOutputContains($"Warning: The environment variable '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE}' is deprecated and will be removed in a future major version. Use '{EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE}' instead."); + } + [DynamicData(nameof(TargetFrameworks.AllForDynamicData), typeof(TargetFrameworks))] [TestMethod] public async Task Diag_EnableWithEnvironmentVariables_Disable_Succeeded(string tfm)