diff --git a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs index ece463b364..d8a17b5e83 100644 --- a/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs +++ b/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs @@ -341,8 +341,28 @@ 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); +#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)) + { + console.WriteLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.DeprecatedEnvironmentVariableWarning, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_OUTPUT_FILEPREFIX, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILE_PREFIX)); + } +#pragma warning restore CS0618 + + if (RoslynString.IsNullOrEmpty(environmentFilePrefix)) + { + environmentFilePrefix = legacyEnvironmentFilePrefix; + } + if (!RoslynString.IsNullOrEmpty(environmentFilePrefix)) { prefixName = environmentFilePrefix; @@ -350,8 +370,28 @@ 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); +#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)) + { + console.WriteLine(string.Format( + CultureInfo.InvariantCulture, + PlatformResources.DeprecatedEnvironmentVariableWarning, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_FILELOGGER_SYNCHRONOUSWRITE, + EnvironmentVariableConstants.TESTINGPLATFORM_DIAGNOSTIC_SYNCHRONOUS_WRITE)); + } +#pragma warning restore CS0618 + + if (RoslynString.IsNullOrEmpty(environmentSynchronousWrite)) + { + environmentSynchronousWrite = legacyEnvironmentSynchronousWrite; + } + 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..6073f436bd 100644 --- a/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs +++ b/src/Platform/Microsoft.Testing.Platform/Helpers/EnvironmentVariableConstants.cs @@ -23,8 +23,14 @@ 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); + + [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); + + [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); public const string TESTINGPLATFORM_EXITCODE_IGNORE = nameof(TESTINGPLATFORM_EXITCODE_IGNORE); 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 bf4b936ea8..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; @@ -155,6 +160,52 @@ 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))] + [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); + 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_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); + + // 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))] @@ -175,6 +226,55 @@ 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))] + [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"); + 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))]