From ff14b2b2d74d8c9857dcf105647d7a7ef3ce4042 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 6 Jun 2023 14:46:29 +1000 Subject: [PATCH 1/3] remove some redundant assignments --- .../ExtensionFramework/TestPluginCache.cs | 2 +- .../ExtensionFramework/TestPluginDiscoverer.cs | 3 +-- .../Filtering/FilterExpression.cs | 3 +-- .../TestSession/ProxyTestSessionManager.cs | 4 ++-- .../TestSession/TestSessionPool.cs | 6 +++--- .../MiniDumpWriteDump.cs | 15 +++++++-------- .../Navigation/FullSymbolReader.cs | 4 ++-- .../common/System/ProcessHelper.cs | 1 - src/vstest.console/CommandLine/Executor.cs | 3 +-- .../Utilities/ArgumentProcessorFactory.cs | 4 ++-- test/Intent/Runner.cs | 2 +- .../Build.cs | 2 +- .../TargetFrameworkTestHostDemultiplexer.cs | 2 +- 13 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs index a62f6c3af4..511efc60c6 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs @@ -128,7 +128,7 @@ public List GetExtensionPaths(string endsWithPattern, bool skipDefaultEx return TestExtensions.GetTestExtensionCache(); } - Dictionary? pluginInfos = null; + Dictionary? pluginInfos; SetupAssemblyResolver(null); // Some times TestPlatform.core.dll assembly fails to load in the current appdomain (from devenv.exe). diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs index 3bbef8f8cf..2ac4444e48 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs @@ -91,9 +91,8 @@ private static void GetTestExtensionsFromFiles( } try { - Assembly? assembly = null; var assemblyName = Path.GetFileNameWithoutExtension(file); - assembly = Assembly.Load(new AssemblyName(assemblyName)); + var assembly = Assembly.Load(new AssemblyName(assemblyName)); if (assembly != null) { GetTestExtensionsFromAssembly(assembly, pluginInfos, file); diff --git a/src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs b/src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs index c2a30a33a8..417d10fae4 100644 --- a/src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs +++ b/src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs @@ -130,8 +130,7 @@ private static void ProcessOperator(Stack filterStack, Operato // Only the leaves have a condition value. if (current._condition != null) { - bool valid = false; - valid = current._condition.ValidForProperties(properties, propertyProvider); + var valid = current._condition.ValidForProperties(properties, propertyProvider); // If it's not valid will add it to the function's return array. return !valid ? new string[1] { current._condition.Name } : null; } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/ProxyTestSessionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/ProxyTestSessionManager.cs index 69f6699855..74e2e22db1 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/ProxyTestSessionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/ProxyTestSessionManager.cs @@ -209,7 +209,7 @@ public virtual bool StartSession(ITestSessionEventsHandler eventsHandler, IReque /// public virtual bool StopSession(IRequestData requestData) { - var testSessionId = string.Empty; + string testSessionId; lock (_lockObject) { if (_testSessionInfo == null) @@ -251,7 +251,7 @@ public virtual bool StopSession(IRequestData requestData) /// The dequeued proxy. public virtual ProxyOperationManager DequeueProxy(string source, string? runSettings) { - ProxyOperationManagerContainer? proxyContainer = null; + ProxyOperationManagerContainer? proxyContainer; lock (_proxyOperationLockObject) { diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs index adfaa12b9b..7d1f1a497a 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs @@ -96,7 +96,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re { // TODO (copoiena): What happens if some request is running for the current session ? // Should we stop the request as well ? Probably yes. - IProxyTestSessionManager? proxyManager = null; + IProxyTestSessionManager? proxyManager; lock (_lockObject) { @@ -133,7 +133,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re { ValidateArg.NotNull(requestData, nameof(requestData)); - ProxyTestSessionManager? sessionManager = null; + ProxyTestSessionManager? sessionManager; lock (_lockObject) { if (!_sessionPool.ContainsKey(testSessionInfo)) @@ -181,7 +181,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re /// True if the operation succeeded, false otherwise. public virtual bool ReturnProxy(TestSessionInfo testSessionInfo, int proxyId) { - ProxyTestSessionManager? sessionManager = null; + ProxyTestSessionManager? sessionManager; lock (_lockObject) { if (!_sessionPool.ContainsKey(testSessionInfo)) diff --git a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/MiniDumpWriteDump.cs b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/MiniDumpWriteDump.cs index a4c1497b1b..fd22eae3e3 100644 --- a/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/MiniDumpWriteDump.cs +++ b/src/Microsoft.TestPlatform.Extensions.BlameDataCollector/MiniDumpWriteDump.cs @@ -28,8 +28,7 @@ public static void CollectDumpUsingMiniDumpWriteDump(Process process, string out using var stream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None); NativeMethods.MinidumpExceptionInformation exceptionInfo = default; - NativeMethods.MinidumpType dumpType = NativeMethods.MinidumpType.MiniDumpNormal; - dumpType = type switch + var dumpType = type switch { MiniDumpTypeOption.Full => NativeMethods.MinidumpType.MiniDumpWithFullMemory | NativeMethods.MinidumpType.MiniDumpWithDataSegs | @@ -39,12 +38,12 @@ public static void CollectDumpUsingMiniDumpWriteDump(Process process, string out NativeMethods.MinidumpType.MiniDumpWithThreadInfo | NativeMethods.MinidumpType.MiniDumpWithTokenInformation, MiniDumpTypeOption.WithHeap => NativeMethods.MinidumpType.MiniDumpWithPrivateReadWriteMemory | - NativeMethods.MinidumpType.MiniDumpWithDataSegs | - NativeMethods.MinidumpType.MiniDumpWithHandleData | - NativeMethods.MinidumpType.MiniDumpWithUnloadedModules | - NativeMethods.MinidumpType.MiniDumpWithFullMemoryInfo | - NativeMethods.MinidumpType.MiniDumpWithThreadInfo | - NativeMethods.MinidumpType.MiniDumpWithTokenInformation, + NativeMethods.MinidumpType.MiniDumpWithDataSegs | + NativeMethods.MinidumpType.MiniDumpWithHandleData | + NativeMethods.MinidumpType.MiniDumpWithUnloadedModules | + NativeMethods.MinidumpType.MiniDumpWithFullMemoryInfo | + NativeMethods.MinidumpType.MiniDumpWithThreadInfo | + NativeMethods.MinidumpType.MiniDumpWithTokenInformation, MiniDumpTypeOption.Mini => NativeMethods.MinidumpType.MiniDumpWithThreadInfo, _ => NativeMethods.MinidumpType.MiniDumpNormal, }; diff --git a/src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs b/src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs index 111636a669..856fbd2127 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs @@ -309,7 +309,7 @@ private void PopulateCacheForTypeAndMethodSymbols() ValidateArg.NotNullOrEmpty(typeName, nameof(typeName)); IDiaEnumSymbols? enumSymbols = null; - IDiaSymbol? typeSymbol = null; + IDiaSymbol? typeSymbol; IDiaSymbol? global = null; try @@ -378,7 +378,7 @@ private void PopulateCacheForTypeAndMethodSymbols() ValidateArg.NotNullOrEmpty(methodName, nameof(methodName)); IDiaEnumSymbols? enumSymbols = null; - IDiaSymbol? methodSymbol = null; + IDiaSymbol? methodSymbol; Dictionary methodSymbolsForType; try diff --git a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs index 5db8da531c..213aa35f89 100644 --- a/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs +++ b/src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs @@ -67,7 +67,6 @@ public object LaunchProcess(string processPath, string? arguments, string? worki catch (Exception) { process.Dispose(); - process = null; //EqtTrace.Error("TestHost Object {0} failed to launch with the following exception: {1}", processPath, exception.Message); throw; diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index dd547de8c8..7b2018f98d 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -276,12 +276,11 @@ private int GetArgumentProcessors(string[] args, out List pr processors.Sort((p1, p2) => Comparer.Default.Compare(p1.Metadata.Value.Priority, p2.Metadata.Value.Priority)); foreach (var processor in processors) { - IArgumentExecutor? executorInstance; try { // Ensure the instance is created. Note that the Lazy not only instantiates // the argument processor, but also initializes it. - executorInstance = processor.Executor?.Value; + var executorInstance = processor.Executor?.Value; } catch (Exception ex) { diff --git a/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs b/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs index d014395236..a46e4f6b7f 100644 --- a/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs +++ b/src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs @@ -276,7 +276,7 @@ public static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation(IA var processorExecutor = processor.Executor; var lazyArgumentProcessor = new Lazy(() => { - IArgumentExecutor? instance = null; + IArgumentExecutor? instance; try { instance = processorExecutor!.Value; @@ -317,7 +317,7 @@ private static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation( var processorExecutor = processor.Executor; var lazyArgumentProcessor = new Lazy(() => { - IArgumentsExecutor? instance = null; + IArgumentsExecutor? instance; try { instance = (IArgumentsExecutor)processorExecutor!.Value; diff --git a/test/Intent/Runner.cs b/test/Intent/Runner.cs index 26a0cb1955..6edf62eb0f 100644 --- a/test/Intent/Runner.cs +++ b/test/Intent/Runner.cs @@ -33,7 +33,7 @@ public static void Run(IEnumerable paths, IRunLogger logger) var methods = types.SelectMany(type => type.GetMethods().SkipExcluded()).ToList(); var methodsWithOnly = methods.Where(m => m.GetCustomAttribute() != null).ToList(); - var methodsToRun = new List(); + List methodsToRun; if (typesWithOnly.Count > 0 || methodsWithOnly.Count > 0) { // Some types or methods are decorated with Only. Putting Only on a type should run all methods in diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs index f0478a6940..b751ccfc29 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/Build.cs @@ -103,7 +103,7 @@ private static void BuildTestAssetsCompatibility() // We use the same version properties for NET.Test.Sdk as for VSTestConsole, for now. foreach (var sdkPropertyName in vstestConsoleVersionProperties) { - string? netTestSdkVersion = null; + string? netTestSdkVersion; if (sdkPropertyName == "VSTestConsoleLatestVersion") { netTestSdkVersion = IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion; diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/TranslationLayerTests/TargetFrameworkTestHostDemultiplexer.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/TranslationLayerTests/TargetFrameworkTestHostDemultiplexer.cs index f3582aaaed..a1454a92a3 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/TranslationLayerTests/TargetFrameworkTestHostDemultiplexer.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/TranslationLayerTests/TargetFrameworkTestHostDemultiplexer.cs @@ -83,7 +83,7 @@ private void ExecuteContainerInMultiHost(RunnerInfo runnerInfo, int expectedHost Assert.AreEqual(expectedHost == -1 ? 1 : expectedHost > 10 ? 10 : expectedHost, hosts.Length); List tests = new(); - int testsRunInsideHost = 0; + int testsRunInsideHost; foreach (var file in hosts) { testsRunInsideHost = 0; From 6a5cfb5f448e7e052b76b24385f80c129b92277e Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 6 Jun 2023 21:07:04 +1000 Subject: [PATCH 2/3] Update TestPluginCache.cs --- .../ExtensionFramework/TestPluginCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs index 511efc60c6..a62f6c3af4 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs @@ -128,7 +128,7 @@ public List GetExtensionPaths(string endsWithPattern, bool skipDefaultEx return TestExtensions.GetTestExtensionCache(); } - Dictionary? pluginInfos; + Dictionary? pluginInfos = null; SetupAssemblyResolver(null); // Some times TestPlatform.core.dll assembly fails to load in the current appdomain (from devenv.exe). From 5b38e51ddc9defc1ebce21af06f80001d41541c1 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 6 Jun 2023 21:07:47 +1000 Subject: [PATCH 3/3] Update TestPluginCache.cs --- .../ExtensionFramework/TestPluginCache.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs index a62f6c3af4..d865c03484 100644 --- a/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs +++ b/src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs @@ -128,7 +128,7 @@ public List GetExtensionPaths(string endsWithPattern, bool skipDefaultEx return TestExtensions.GetTestExtensionCache(); } - Dictionary? pluginInfos = null; + Dictionary? pluginInfos; SetupAssemblyResolver(null); // Some times TestPlatform.core.dll assembly fails to load in the current appdomain (from devenv.exe). @@ -177,6 +177,7 @@ public List GetExtensionPaths(string endsWithPattern, bool skipDefaultEx // Nothing to do here, we just do not want to do an EqtTrace.Fail for this thread // being aborted as it is a legitimate exception to receive. EqtTrace.Verbose("TestPluginCache.DiscoverTestExtensions: Data extension discovery is being aborted due to a thread abort."); + return null; } #endif catch (Exception e)