From 4270ae8ac82e6a8cf7cd64ab3f37bf02347c387f Mon Sep 17 00:00:00 2001 From: nohwnd Date: Wed, 30 Jun 2021 23:09:33 +0200 Subject: [PATCH 1/5] Custom procdump command line --- .../Client/ProxyOperationManager.cs | 10 +++++--- .../ProcDumpArgsBuilder.cs | 23 ++++++++++++++----- .../Resources/Resources.Designer.cs | 11 ++++++++- .../Resources/Resources.resx | 4 ++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 1323c9f243..1064d3700c 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -297,18 +297,20 @@ public virtual bool SetupChannel(IEnumerable sources, string runSettings /// public virtual void Close() { + bool? testHostExitedWithinTimeout = null; try { // Do not send message if the host did not launch. if (this.testHostLaunched) { + testHostExitedWithinTimeout = false; this.RequestSender.EndSession(); // We want to give test host a chance to safely close. // The upper bound for wait should be 100ms. var timeout = 100; EqtTrace.Verbose("ProxyOperationManager.Close: waiting for test host to exit for {0} ms", timeout); - this.testHostExited.Wait(timeout); + testHostExitedWithinTimeout = this.testHostExited.Wait(timeout); } } catch (Exception ex) @@ -320,8 +322,10 @@ public virtual void Close() finally { this.initialized = false; - - EqtTrace.Warning("ProxyOperationManager: Timed out waiting for test host to exit. Will terminate process."); + if (testHostExitedWithinTimeout == false) + { + EqtTrace.Warning("ProxyOperationManager: Timed out waiting for test host to exit. Will terminate process."); + } // Please clean up test host. this.TestHostManager.CleanTestHostAsync(CancellationToken.None).Wait(); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs index 034fbbcf9a..23e7d91d6e 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpArgsBuilder.cs @@ -3,6 +3,7 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector { + using System; using System.Collections.Generic; using System.Text; @@ -17,15 +18,25 @@ public string BuildTriggerBasedProcDumpArgs(int processId, string filename, IEnu // -t: Write a dump when the process terminates. // -ma: Full dump argument. // -f: Filter the exceptions. - StringBuilder procDumpArgument = new StringBuilder($"-accepteula -e 1 -g {(collectAlways ? "-t " : string.Empty)}"); - if (isFullDump) + var procdumpOverride = Environment.GetEnvironmentVariable("VSTEST_DUMP_PROCDUMPARGS")?.Trim(); + StringBuilder procDumpArgument; + if (!string.IsNullOrWhiteSpace(procdumpOverride)) { - procDumpArgument.Append("-ma "); + procDumpArgument = new StringBuilder(procdumpOverride).Append(" "); } - - foreach (var exceptionFilter in procDumpExceptionsList) + else { - procDumpArgument.Append($"-f {exceptionFilter} "); + procDumpArgument = new StringBuilder($"-accepteula -e 1 -g {(collectAlways ? "-t " : string.Empty)}"); + + if (isFullDump) + { + procDumpArgument.Append("-ma "); + } + + foreach (var exceptionFilter in procDumpExceptionsList) + { + procDumpArgument.Append($"-f {exceptionFilter} "); + } } procDumpArgument.Append($"{processId} {filename}.dmp"); diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs index e34c6b30ba..50448d32c8 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.TestPlatform.Extensions.BlameDataCollector.Resources { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -180,6 +180,15 @@ internal static string Seconds { } } + /// + /// Looks up a localized string similar to Terminated process {0} - {1}, because of timeout. . + /// + internal static string Terminated { + get { + return ResourceManager.GetString("Terminated", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unexpected value '{0}' provided as timeout. Please provide a value in this format: 1.5h / 90m / 5400s / 5400000ms / 5400000. /// diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.resx b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.resx index 4d5c69c20d..0284803b89 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.resx @@ -163,6 +163,10 @@ This test may, or may not be the source of the crash. seconds + + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + Unexpected value '{0}' provided as timeout. Please provide a value in this format: 1.5h / 90m / 5400s / 5400000ms / 5400000 From f80be62fb21c73b373e0f0828c98409919f98c41 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Fri, 9 Jul 2021 08:00:55 +0200 Subject: [PATCH 2/5] Add env var for timeout --- .../Client/ProxyOperationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 1064d3700c..933f149dfd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -308,7 +308,7 @@ public virtual void Close() // We want to give test host a chance to safely close. // The upper bound for wait should be 100ms. - var timeout = 100; + var timeout = int.TryParse(Environment.GetEnvironmentVariable("VSTEST_TESTHOST_TIMEOUT"), out var t) ? t : 100; EqtTrace.Verbose("ProxyOperationManager.Close: waiting for test host to exit for {0} ms", timeout); testHostExitedWithinTimeout = this.testHostExited.Wait(timeout); } From 65c9a9c0cc5e8ce412eb04524032cbe6db060270 Mon Sep 17 00:00:00 2001 From: nohwnd Date: Fri, 9 Jul 2021 09:33:04 +0200 Subject: [PATCH 3/5] update xlf --- .../Resources/xlf/Resources.cs.xlf | 5 +++++ .../Resources/xlf/Resources.de.xlf | 5 +++++ .../Resources/xlf/Resources.es.xlf | 5 +++++ .../Resources/xlf/Resources.fr.xlf | 5 +++++ .../Resources/xlf/Resources.it.xlf | 5 +++++ .../Resources/xlf/Resources.ja.xlf | 5 +++++ .../Resources/xlf/Resources.ko.xlf | 5 +++++ .../Resources/xlf/Resources.pl.xlf | 5 +++++ .../Resources/xlf/Resources.pt-BR.xlf | 5 +++++ .../Resources/xlf/Resources.ru.xlf | 5 +++++ .../Resources/xlf/Resources.tr.xlf | 5 +++++ .../Resources/xlf/Resources.xlf | 5 +++++ .../Resources/xlf/Resources.zh-Hans.xlf | 5 +++++ .../Resources/xlf/Resources.zh-Hant.xlf | 5 +++++ 14 files changed, 70 insertions(+) diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.cs.xlf index 3781d6a61c..24afdd1955 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.cs.xlf @@ -78,6 +78,11 @@ Tento test může a nemusí být příčinou chybového ukončení. sekundy + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.de.xlf index 8751849d00..e730ae3838 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.de.xlf @@ -78,6 +78,11 @@ Dieser Test kann, muss aber nicht unbedingt die Absturzursache sein. Sekunden + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.es.xlf index 8890c61094..997c8f8233 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.es.xlf @@ -78,6 +78,11 @@ Esta prueba puede ser el origen del bloqueo o no serlo. segundos + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.fr.xlf index 1bab835425..1292de8d6f 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.fr.xlf @@ -78,6 +78,11 @@ Ce test est éventuellement à l'origine du plantage. secondes + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.it.xlf index d666f1b951..1cca192248 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.it.xlf @@ -78,6 +78,11 @@ Il test potrebbe essere l'origine dell'arresto anomalo. secondi + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ja.xlf index 689a680dc8..ba6db40d5c 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ja.xlf @@ -78,6 +78,11 @@ This test may, or may not be the source of the crash. + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ko.xlf index 87b9f0865f..052c895a07 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ko.xlf @@ -78,6 +78,11 @@ This test may, or may not be the source of the crash. + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pl.xlf index b8e229978d..ad008884b0 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pl.xlf @@ -78,6 +78,11 @@ Ten test może, ale nie musi być źródłem awarii. s + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pt-BR.xlf index 183db0826f..e5dc3376c2 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.pt-BR.xlf @@ -78,6 +78,11 @@ Esse teste pode ser a origem da falha ou não. segundos + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ru.xlf index 174393655e..273004e6dc 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.ru.xlf @@ -78,6 +78,11 @@ This test may, or may not be the source of the crash. с + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.tr.xlf index 96e906da89..eac47239f6 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.tr.xlf @@ -78,6 +78,11 @@ Bu test, kilitlenmenin kaynağı olmayabilir veya olmayabilir. saniye + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.xlf index 9667764550..847c500dac 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.xlf @@ -75,6 +75,11 @@ This test may, or may not be the source of the crash. seconds + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hans.xlf index c3ea2af6ad..3967bf50f7 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hans.xlf @@ -78,6 +78,11 @@ This test may, or may not be the source of the crash. + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hant.xlf index 491532f393..f2e3dc5e62 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/xlf/Resources.zh-Hant.xlf @@ -78,6 +78,11 @@ This test may, or may not be the source of the crash. + + Terminated process {0} - {1}, because of timeout. + Terminated process {0} - {1}, because of timeout. + {0} process id, {1} process name + \ No newline at end of file From 805f5e7e48c354c86b3361f7e76a2865ab71a4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Sat, 12 Feb 2022 15:41:14 +0100 Subject: [PATCH 4/5] Enable pattern code style --- .editorconfig | 30 ++++++++++--- .../ManagedNameHelper.Reflection.cs | 16 +++---- .../TestIdProvider.cs | 43 +++++++----------- .../Execution/TestRunRequest.cs | 7 ++- .../TestPlatformDataCollectionLogger.cs | 2 +- .../Filtering/FastFilter.cs | 2 +- .../Utilities/FakesUtilities.cs | 7 +-- .../ValidateArg.cs | 4 +- .../Discovery/DiscovererEnumerator.cs | 3 +- .../EventHandlers/TestRequestHandler.cs | 2 +- .../Execution/BaseRunTests.cs | 2 +- .../Execution/RunTestsWithSources.cs | 2 +- .../Execution/RunTestsWithTests.cs | 2 +- .../ProcDumpDumper.cs | 2 +- .../WindowsHangDumper.cs | 2 +- .../Logging/Events/TestRunMessageEventArgs.cs | 2 +- .../Navigation/PortablePdbReader.cs | 2 + .../TestResult.cs | 2 +- .../Utilities/AssemblyLoadWorker.cs | 2 +- .../Utilities/Sha1Helper.cs | 44 +++++++------------ .../common/System/ProcessHelper.cs | 2 +- .../net451/System/PlatformEnvironment.cs | 4 +- .../Hosting/DotnetTestHostManager.cs | 4 +- .../InferRunSettingsHelper.cs | 5 ++- .../CommandLine/AssemblyMetadataProvider.cs | 2 +- src/vstest.console/CommandLine/Executor.cs | 6 +-- src/vstest.console/Internal/ConsoleLogger.cs | 8 ++-- .../Processors/PlatformArgumentProcessor.cs | 2 +- .../ResultsDirectoryArgumentProcessor.cs | 2 +- .../IntegrationTestBase.cs | 2 +- 30 files changed, 104 insertions(+), 111 deletions(-) diff --git a/.editorconfig b/.editorconfig index bc6ff2c493..9789e177cf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -164,6 +164,22 @@ dotnet_diagnostic.CA1507.severity=warning # not default, increased severity to e # CA2215: Dispose methods should call base class dispose dotnet_diagnostic.CA2215.severity=warning # not default, increased severity to ensure it is applied +# IDE0019: Use pattern matching +# Keep this in sync with csharp_style_pattern_matching_over_as_with_null_check +dotnet_diagnostic.IDE0019.severity = warning # not default, increased severity to ensure it is applied + +# IDE0020: +# Keep this in sync with csharp_style_pattern_matching_over_is_with_cast_check +dotnet_diagnostic.IDE0020.severity = warning # not default, increased severity to ensure it is applied + +# IDE0078: Use pattern matching +# Keep this in sync with csharp_style_prefer_pattern_matching +dotnet_diagnostic.IDE0078.severity = warning # not default, increased severity to ensure it is applied + +# IDE0083: Use pattern matching (not operator) +# Keep this in sync with csharp_style_prefer_not_pattern +dotnet_diagnostic.IDE0083.severity = warning # not default, increased severity to ensure it is applied + #### C# Coding Conventions #### # var preferences @@ -183,11 +199,15 @@ csharp_style_expression_bodied_operators = false:silent csharp_style_expression_bodied_properties = true:silent # Pattern matching preferences -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_prefer_not_pattern = true:suggestion -csharp_style_prefer_pattern_matching = true:silent -csharp_style_prefer_switch_expression = true:suggestion +# Keep this in sync with IDE0019 +csharp_style_pattern_matching_over_as_with_null_check = true:warning +# Keep this in sync with IDE0020 and IDE0038 +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +# Keep this in sync with IDE0083 +csharp_style_prefer_not_pattern = true:warning +# Keep this in sync with IDE0078 +csharp_style_prefer_pattern_matching = true:warning +csharp_style_prefer_switch_expression = true:warning # Null-checking preferences csharp_style_conditional_delegate_call = true:suggestion diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs index cb7d4714f6..97afc36b2b 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs @@ -389,7 +389,7 @@ private static void NormalizeAndAppendString(StringBuilder b, string name) char c = name[i]; if (NeedsEscaping(c, i)) { - if (c == '\\' || c == '\'') + if (c is '\\' or '\'') { // var encoded = Convert.ToString(((uint)c), 16); // b.Append("\\u"); @@ -494,15 +494,11 @@ private static bool NeedsEscaping(char c, int pos) } var category = CharUnicodeInfo.GetUnicodeCategory(c); - if (category == UnicodeCategory.NonSpacingMark // Mn - || category == UnicodeCategory.SpacingCombiningMark // Mc - || category == UnicodeCategory.ConnectorPunctuation // Pc - || category == UnicodeCategory.Format) // Cf - { - return false; - } - - return true; + return category + is not UnicodeCategory.NonSpacingMark // Mn + and not UnicodeCategory.SpacingCombiningMark // Mc + and not UnicodeCategory.ConnectorPunctuation // Pc + and not UnicodeCategory.Format; // Cf } private static string GetTypeString(Type type, bool closedType) diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/TestIdProvider.cs b/src/Microsoft.TestPlatform.AdapterUtilities/TestIdProvider.cs index 8928327407..0d92210242 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/TestIdProvider.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/TestIdProvider.cs @@ -145,20 +145,14 @@ public Sha1Implementation() /// private static uint F(int t, uint b, uint c, uint d) { - if (t >= 0 && t <= 19) + return t switch { - return (b & c) | (~b & d); - } - else if ((t >= 20 && t <= 39) || (t >= 60 && t <= 79)) - { - return b ^ c ^ d; - } - else - { - return t >= 40 && t <= 59 - ? (b & c) | (b & d) | (c & d) - : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)); - } + >= 0 and <= 19 => b & c | ~b & d, + >= 20 and <= 39 or >= 60 and <= 79 => b ^ c ^ d, + _ => t is >= 40 and <= 59 + ? b & c | b & d | c & d + : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)) + }; } /// @@ -173,22 +167,15 @@ private static uint F(int t, uint b, uint c, uint d) /// private static uint K(int t) { - if (t >= 0 && t <= 19) - { - return 0x5A827999u; - } - else if (t >= 20 && t <= 39) - { - return 0x6ED9EBA1u; - } - else if (t >= 40 && t <= 59) + return t switch { - return 0x8F1BBCDCu; - } - else - { - return t >= 60 && t <= 79 ? 0xCA62C1D6u : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)); - } + >= 0 and <= 19 => 0x5A827999u, + >= 20 and <= 39 => 0x6ED9EBA1u, + >= 40 and <= 59 => 0x8F1BBCDCu, + _ => t is >= 60 and <= 79 + ? 0xCA62C1D6u + : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)) + }; } /// diff --git a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs index cd9042ffb1..dd414f88f0 100644 --- a/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs +++ b/src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs @@ -189,10 +189,9 @@ public bool WaitForCompletion(int timeout) throw new ObjectDisposedException("testRunRequest"); } - if (State != TestRunState.InProgress - && !(State == TestRunState.Completed - || State == TestRunState.Canceled - || State == TestRunState.Aborted)) + if (State + is not TestRunState.InProgress + and not (TestRunState.Completed or TestRunState.Canceled or TestRunState.Aborted)) { // If run is already terminated, then we should not throw an exception. throw new InvalidOperationException(ClientResources.WaitForCompletionOperationIsNotAllowedWhenNoTestRunIsActive); diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/TestPlatformDataCollectionLogger.cs b/src/Microsoft.TestPlatform.Common/DataCollection/TestPlatformDataCollectionLogger.cs index eaf55fbb72..62ba5a474f 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/TestPlatformDataCollectionLogger.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/TestPlatformDataCollectionLogger.cs @@ -127,7 +127,7 @@ private void SendTextMessage(DataCollectionContext context, string text, TestMes ValidateArg.NotNull(text, nameof(text)); Debug.Assert( - level >= TestMessageLevel.Informational && level <= TestMessageLevel.Error, + level is >= TestMessageLevel.Informational and <= TestMessageLevel.Error, "Invalid level: " + level); // Make sure the data collection context is not a derived data collection context. This diff --git a/src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs b/src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs index c8c925cc38..78cad37e15 100644 --- a/src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs +++ b/src/Microsoft.TestPlatform.Common/Filtering/FastFilter.cs @@ -189,7 +189,7 @@ internal void AddCondition(Condition condition) AddProperty(condition.Name, condition.Value); // Don't support `Contains`. - if (_fastFilterOperation != Operation.Equal && _fastFilterOperation != Operation.NotEqual) + if (_fastFilterOperation is not Operation.Equal and not Operation.NotEqual) { _containsValidFilter = false; } diff --git a/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs b/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs index ba464e6ff2..54ff0a3a37 100644 --- a/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs +++ b/src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs @@ -172,9 +172,10 @@ private static bool AddFallbackFakesSettings( // The fallback settings is for the old implementation of fakes // that only supports .Net Framework versions - if (framework != FrameworkVersion.Framework35 && - framework != FrameworkVersion.Framework40 && - framework != FrameworkVersion.Framework45) + if (framework + is not FrameworkVersion.Framework35 + and not FrameworkVersion.Framework40 + and not FrameworkVersion.Framework45) { return false; } diff --git a/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs b/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs index fead7d6dbb..bbbb147f92 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/ValidateArg.cs @@ -142,7 +142,7 @@ public static void TypeOf([ValidatedNotNull] object arg, string parameterName { NotNull(arg, parameterName); - if (!(arg is T)) + if (arg is not T) { var message = string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgumentNotTypeOf, typeof(T).FullName); throw new ArgumentException(message, parameterName); @@ -218,7 +218,7 @@ public static void TypeOf([ValidatedNotNull] object arg, string parameterName { NotNull(arg, parameterName, propertyName); - if (!(arg is T)) + if (arg is not T) { var message = string.Format(CultureInfo.CurrentCulture, Resources.Error_ArgumentPropertyNotTypeOf, propertyName, typeof(T).FullName); throw new ArgumentException(message, parameterName); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs index f631481ef6..b94a5c8f9e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Discovery/DiscovererEnumerator.cs @@ -381,8 +381,7 @@ internal static Dictionary> execut // host by default. // Same goes if all adapters implement the new test executor interface but at // least one of them needs the test platform to attach to the default test host. - if (!(executor.Value is ITestExecutor2) + if (executor.Value is not ITestExecutor2 || ShouldAttachDebuggerToTestHost(executor, executorUriExtensionTuple, RunContext)) { EqtTrace.Verbose("Attaching to default test host."); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs index 5dbd33c55d..fef747ad30 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithSources.cs @@ -125,7 +125,7 @@ protected override bool ShouldAttachDebuggerToTestHost( { // If the adapter doesn't implement the new test executor interface we should attach to // the default test host by default to preserve old behavior. - return !(executor?.Value is ITestExecutor2 convertedExecutor) + return executor?.Value is not ITestExecutor2 convertedExecutor || convertedExecutor.ShouldAttachToTestHost( _executorUriVsSourceList[executorUriExtensionTuple], runContext); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithTests.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithTests.cs index a170561044..db0379cd85 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithTests.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/RunTestsWithTests.cs @@ -83,7 +83,7 @@ protected override bool ShouldAttachDebuggerToTestHost( { // If the adapter doesn't implement the new test executor interface we should attach to // the default test host by default to preserve old behavior. - return !(executor?.Value is ITestExecutor2 convertedExecutor) + return executor?.Value is not ITestExecutor2 convertedExecutor || convertedExecutor.ShouldAttachToTestHost(_executorUriVsTestList[executorUri], runContext); } diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs index c86fbf4707..08c080e560 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcDumpDumper.cs @@ -274,7 +274,7 @@ private bool TryGetProcDumpExecutable(int processId, out string path) } else { - filename = _environment.OperatingSystem == PlatformOperatingSystem.Unix || _environment.OperatingSystem == PlatformOperatingSystem.OSX + filename = _environment.OperatingSystem is PlatformOperatingSystem.Unix or PlatformOperatingSystem.OSX ? Constants.ProcdumpUnixProcess : throw new NotSupportedException($"Not supported platform {_environment.OperatingSystem}"); } diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs index 7dea5cc2b6..5831274ec5 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/WindowsHangDumper.cs @@ -37,7 +37,7 @@ public WindowsHangDumper(Action logWarning) public void Dump(int processId, string outputDirectory, DumpTypeOption type) { var process = Process.GetProcessById(processId); - var processTree = process.GetProcessTree().Where(p => p.Process.ProcessName != "conhost" && p.Process.ProcessName != "WerFault").ToList(); + var processTree = process.GetProcessTree().Where(p => p.Process.ProcessName is not "conhost" and not "WerFault").ToList(); if (processTree.Count > 1) { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestRunMessageEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestRunMessageEventArgs.cs index 8a3afd2f92..d2d3198897 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestRunMessageEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Logging/Events/TestRunMessageEventArgs.cs @@ -28,7 +28,7 @@ public TestRunMessageEventArgs(TestMessageLevel level, string message) throw new ArgumentException(CommonResources.CannotBeNullOrEmpty, nameof(message)); } - if (level < TestMessageLevel.Informational || level > TestMessageLevel.Error) + if (level is < TestMessageLevel.Informational or > TestMessageLevel.Error) { throw new ArgumentOutOfRangeException(nameof(level)); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs index bbeaee513a..c0b025859a 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/PortablePdbReader.cs @@ -95,8 +95,10 @@ public DiaNavigationData GetDiaNavigationData(MethodInfo methodInfo) internal static bool IsPortable(Stream stream) { // First four bytes should be 'BSJB' +#pragma warning disable IDE0078 // Use pattern matching (may change code meaning) var result = (stream.ReadByte() == 'B') && (stream.ReadByte() == 'S') && (stream.ReadByte() == 'J') && (stream.ReadByte() == 'B'); +#pragma warning restore IDE0078 // Use pattern matching (may change code meaning) stream.Position = 0; return result; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs b/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs index 6fb7767b14..20005b66c6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestResult.cs @@ -357,6 +357,6 @@ public static class TestResultProperties private static bool ValidateOutcome(object value) { - return (TestOutcome)value <= TestOutcome.NotFound && (TestOutcome)value >= TestOutcome.None; + return (TestOutcome)value is <= TestOutcome.NotFound and >= TestOutcome.None; } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs index 10b7a8ecb1..836bbafbcd 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/AssemblyLoadWorker.cs @@ -307,7 +307,7 @@ private static string GetArchitectureForSource(string imagePath) // magic number.32bit or 64bit assembly. UInt16 magic = reader.ReadUInt16(); - if (magic != 0x010B && magic != 0x020B) + if (magic is not 0x010B and not 0x020B) { validImage = false; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/Sha1Helper.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/Sha1Helper.cs index b3333f0f39..3b780b2b61 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/Sha1Helper.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/Sha1Helper.cs @@ -67,20 +67,14 @@ internal class Sha1Implementation /// private static uint F(int t, uint b, uint c, uint d) { - if (t >= 0 && t <= 19) + return t switch { - return (b & c) | (~b & d); - } - else if ((t >= 20 && t <= 39) || (t >= 60 && t <= 79)) - { - return b ^ c ^ d; - } - else - { - return t >= 40 && t <= 59 - ? (b & c) | (b & d) | (c & d) - : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)); - } + >= 0 and <= 19 => b & c | ~b & d, + >= 20 and <= 39 or >= 60 and <= 79 => b ^ c ^ d, + _ => t is >= 40 and <= 59 + ? b & c | b & d | c & d + : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)) + }; } /// @@ -95,23 +89,15 @@ private static uint F(int t, uint b, uint c, uint d) /// private static uint K(int t) { - - if (t >= 0 && t <= 19) + return t switch { - return 0x5A827999u; - } - else if (t >= 20 && t <= 39) - { - return 0x6ED9EBA1u; - } - else if (t >= 40 && t <= 59) - { - return 0x8F1BBCDCu; - } - else - { - return t >= 60 && t <= 79 ? 0xCA62C1D6u : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)); - } + >= 0 and <= 19 => 0x5A827999u, + >= 20 and <= 39 => 0x6ED9EBA1u, + >= 40 and <= 59 => 0x8F1BBCDCu, + _ => t is >= 60 and <= 79 + ? 0xCA62C1D6u + : throw new ArgumentException("Argument out of bounds! 0 <= t < 80", nameof(t)) + }; } /// diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs index c10815e652..423a30fb0d 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs @@ -198,7 +198,7 @@ public int GetProcessId(object process) public string GetNativeDllDirectory() { var osArchitecture = new PlatformEnvironment().Architecture; - return osArchitecture == PlatformArchitecture.ARM || osArchitecture == PlatformArchitecture.ARM64 + return osArchitecture is PlatformArchitecture.ARM or PlatformArchitecture.ARM64 ? Path.Combine(GetCurrentProcessLocation(), GetCurrentProcessArchitecture().ToString().ToLower(), Arm) : Path.Combine(GetCurrentProcessLocation(), GetCurrentProcessArchitecture().ToString().ToLower()); } diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/System/PlatformEnvironment.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/System/PlatformEnvironment.cs index ba32edce04..b385f9717f 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/net451/System/PlatformEnvironment.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/net451/System/PlatformEnvironment.cs @@ -35,7 +35,9 @@ public PlatformOperatingSystem OperatingSystem // CLR 2.x. See below link for more information: // http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform int p = (int)Environment.OSVersion.Platform; - return (p == 4) || (p == 6) || (p == 128) ? PlatformOperatingSystem.Unix : PlatformOperatingSystem.Windows; + return p is 4 or 6 or 128 + ? PlatformOperatingSystem.Unix + : PlatformOperatingSystem.Windows; } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index b3efae5b03..79655c90a3 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -262,7 +262,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( && !IsWinOnArm()) { // testhost.exe is 64-bit and has no suffix other versions have architecture suffix. - var exeName = _architecture == Architecture.X64 || _architecture == Architecture.Default || _architecture == Architecture.AnyCPU + var exeName = _architecture is Architecture.X64 or Architecture.Default or Architecture.AnyCPU ? "testhost.exe" : $"testhost.{_architecture.ToString().ToLowerInvariant()}.exe"; @@ -283,7 +283,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( { // testhost.dll is present in path {testHostNugetRoot}\lib\netcoreapp2.1\testhost.dll // testhost.(x86).exe is present in location {testHostNugetRoot}\build\netcoreapp2.1\{x86/x64}\{testhost.x86.exe/testhost.exe} - var folderName = _architecture == Architecture.X64 || _architecture == Architecture.Default || _architecture == Architecture.AnyCPU + var folderName = _architecture is Architecture.X64 or Architecture.Default or Architecture.AnyCPU ? Architecture.X64.ToString().ToLowerInvariant() : _architecture.ToString().ToLowerInvariant(); diff --git a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs index 0122ec20fb..0c1557a71f 100644 --- a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs +++ b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs @@ -701,12 +701,13 @@ private static bool IsSettingIncompatible(Architecture sourcePlatform, /// private static bool IsPlatformIncompatible(Architecture sourcePlatform, Architecture targetPlatform) { - if (sourcePlatform == Architecture.Default || - sourcePlatform == Architecture.AnyCPU) + if (sourcePlatform is Architecture.Default or Architecture.AnyCPU) { return false; } + return targetPlatform == Architecture.X64 && !Is64BitOperatingSystem() || sourcePlatform != targetPlatform; + static bool Is64BitOperatingSystem() { #if !NETSTANDARD1_3 diff --git a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs index f711028f8a..8a83e777de 100644 --- a/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs +++ b/src/vstest.console/CommandLine/AssemblyMetadataProvider.cs @@ -249,7 +249,7 @@ public Architecture GetArchitectureForSource(string imagePath) // magic number.32bit or 64bit assembly. var magic = reader.ReadUInt16(); - if (magic != 0x010B && magic != 0x020B) + if (magic is not 0x010B and not 0x020B) { validImage = false; } diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index 507bb84f0b..ba92aba184 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -255,7 +255,7 @@ private int GetArgumentProcessors(string[] args, out List pr } catch (Exception ex) { - if (ex is CommandLineException || ex is TestPlatformException || ex is SettingsException) + if (ex is CommandLineException or TestPlatformException or SettingsException) { Output.Error(false, ex.Message); result = 1; @@ -359,7 +359,7 @@ private bool ExecuteArgumentProcessor(IArgumentProcessor processor, ref int exit } catch (Exception ex) { - if (ex is CommandLineException || ex is TestPlatformException || ex is SettingsException || ex is InvalidOperationException) + if (ex is CommandLineException or TestPlatformException or SettingsException or InvalidOperationException) { EqtTrace.Error("ExecuteArgumentProcessor: failed to execute argument process: {0}", ex); Output.Error(false, ex.Message); @@ -382,7 +382,7 @@ private bool ExecuteArgumentProcessor(IArgumentProcessor processor, ref int exit } Debug.Assert( - result >= ArgumentProcessorResult.Success && result <= ArgumentProcessorResult.Abort, + result is >= ArgumentProcessorResult.Success and <= ArgumentProcessorResult.Abort, "Invalid argument processor result."); if (result == ArgumentProcessorResult.Fail) diff --git a/src/vstest.console/Internal/ConsoleLogger.cs b/src/vstest.console/Internal/ConsoleLogger.cs index 9adeba9279..f2e120db9a 100644 --- a/src/vstest.console/Internal/ConsoleLogger.cs +++ b/src/vstest.console/Internal/ConsoleLogger.cs @@ -456,7 +456,7 @@ private void TestMessageHandler(object sender, TestRunMessageEventArgs e) { case TestMessageLevel.Informational: { - if (VerbosityLevel == Verbosity.Quiet || VerbosityLevel == Verbosity.Minimal) + if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) { break; } @@ -596,7 +596,7 @@ private void TestResultHandler(object sender, TestResultEventArgs e) case TestOutcome.Passed: { - if (VerbosityLevel == Verbosity.Normal || VerbosityLevel == Verbosity.Detailed) + if (VerbosityLevel is Verbosity.Normal or Verbosity.Detailed) { // Pause the progress indicator before displaying test result information _progressIndicator?.Pause(); @@ -735,7 +735,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) } } - if (VerbosityLevel == Verbosity.Quiet || VerbosityLevel == Verbosity.Minimal) + if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) { TestOutcome sourceOutcome = TestOutcome.None; if (sourceSummary.FailedTests > 0) @@ -827,7 +827,7 @@ private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) totalTests += sourceSummary.TotalTests; } - if (VerbosityLevel == Verbosity.Quiet || VerbosityLevel == Verbosity.Minimal) + if (VerbosityLevel is Verbosity.Quiet or Verbosity.Minimal) { if (e.IsCanceled) { diff --git a/src/vstest.console/Processors/PlatformArgumentProcessor.cs b/src/vstest.console/Processors/PlatformArgumentProcessor.cs index bfdbca216c..2e5d5325e8 100644 --- a/src/vstest.console/Processors/PlatformArgumentProcessor.cs +++ b/src/vstest.console/Processors/PlatformArgumentProcessor.cs @@ -136,7 +136,7 @@ public void Initialize(string argument) } var validPlatforms = Enum.GetValues(typeof(Architecture)).Cast() - .Where(e => e != Architecture.AnyCPU && e != Architecture.Default) + .Where(e => e is not Architecture.AnyCPU and not Architecture.Default) .ToList(); var validPlatform = Enum.TryParse(argument, true, out Architecture platform); diff --git a/src/vstest.console/Processors/ResultsDirectoryArgumentProcessor.cs b/src/vstest.console/Processors/ResultsDirectoryArgumentProcessor.cs index 47c3a95858..d9bdaa52ba 100644 --- a/src/vstest.console/Processors/ResultsDirectoryArgumentProcessor.cs +++ b/src/vstest.console/Processors/ResultsDirectoryArgumentProcessor.cs @@ -148,7 +148,7 @@ public void Initialize(string argument) var di = Directory.CreateDirectory(argument); } - catch (Exception ex) when (ex is NotSupportedException || ex is SecurityException || ex is ArgumentException || ex is PathTooLongException || ex is IOException) + catch (Exception ex) when (ex is NotSupportedException or SecurityException or ArgumentException or PathTooLongException or IOException) { throw new CommandLineException(string.Format(CommandLineResources.InvalidResultsDirectoryPathCommand, argument, ex.Message)); } diff --git a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs index 0cc20ac898..db6fa58391 100644 --- a/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs +++ b/test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs @@ -776,7 +776,7 @@ protected static void AssertExpectedNumberOfHostProcesses(int expectedNumOfProce protected static string GetDownloadedDotnetMuxerFromTools(string architecture) { - if (architecture != "X86" && architecture != "X64") + if (architecture is not "X86" and not "X64") { throw new NotSupportedException(nameof(architecture)); } From 6b94bd138f20f91bac8da7fb64102aeb357ba954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Thu, 10 Mar 2022 08:52:33 +0100 Subject: [PATCH 5/5] Apply suggestions from code review --- .../Client/ProxyOperationManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index 933f149dfd..d4c92db438 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -308,7 +308,7 @@ public virtual void Close() // We want to give test host a chance to safely close. // The upper bound for wait should be 100ms. - var timeout = int.TryParse(Environment.GetEnvironmentVariable("VSTEST_TESTHOST_TIMEOUT"), out var t) ? t : 100; + var timeout = int.TryParse(Environment.GetEnvironmentVariable("VSTEST_TESTHOST_SHUTDOWN_TIMEOUT"), out var t) ? t : 100; EqtTrace.Verbose("ProxyOperationManager.Close: waiting for test host to exit for {0} ms", timeout); testHostExitedWithinTimeout = this.testHostExited.Wait(timeout); }