Skip to content

Commit

Permalink
remove some redundant assignments (#4522)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jun 6, 2023
1 parent 0b8a683 commit c686e7d
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public List<string> GetExtensionPaths(string endsWithPattern, bool skipDefaultEx
return TestExtensions.GetTestExtensionCache<TPluginInfo>();
}

Dictionary<string, TPluginInfo>? pluginInfos = null;
Dictionary<string, TPluginInfo>? pluginInfos;
SetupAssemblyResolver(null);

// Some times TestPlatform.core.dll assembly fails to load in the current appdomain (from devenv.exe).
Expand Down Expand Up @@ -177,6 +177,7 @@ public List<string> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ private static void AddKnownExtensions(ref IEnumerable<string> extensionPaths)
}
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<TPluginInfo, TExtension>(assembly, pluginInfos, file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ private static void ProcessOperator(Stack<FilterExpression> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public virtual bool StartSession(ITestSessionEventsHandler eventsHandler, IReque
/// <inheritdoc/>
public virtual bool StopSession(IRequestData requestData)
{
var testSessionId = string.Empty;
string testSessionId;
lock (_lockObject)
{
if (_testSessionInfo == null)
Expand Down Expand Up @@ -251,7 +251,7 @@ public virtual bool StopSession(IRequestData requestData)
/// <returns>The dequeued proxy.</returns>
public virtual ProxyOperationManager DequeueProxy(string source, string? runSettings)
{
ProxyOperationManagerContainer? proxyContainer = null;
ProxyOperationManagerContainer? proxyContainer;

lock (_proxyOperationLockObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -181,7 +181,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re
/// <returns>True if the operation succeeded, false otherwise.</returns>
public virtual bool ReturnProxy(TestSessionInfo testSessionInfo, int proxyId)
{
ProxyTestSessionManager? sessionManager = null;
ProxyTestSessionManager? sessionManager;
lock (_lockObject)
{
if (!_sessionPool.ContainsKey(testSessionInfo))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ private void PopulateCacheForTypeAndMethodSymbols()
ValidateArg.NotNullOrEmpty(typeName, nameof(typeName));

IDiaEnumSymbols? enumSymbols = null;
IDiaSymbol? typeSymbol = null;
IDiaSymbol? typeSymbol;
IDiaSymbol? global = null;

try
Expand Down Expand Up @@ -378,7 +378,7 @@ private void PopulateCacheForTypeAndMethodSymbols()
ValidateArg.NotNullOrEmpty(methodName, nameof(methodName));

IDiaEnumSymbols? enumSymbols = null;
IDiaSymbol? methodSymbol = null;
IDiaSymbol? methodSymbol;
Dictionary<string, IDiaSymbol> methodSymbolsForType;

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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;
Expand Down
3 changes: 1 addition & 2 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,11 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
processors.Sort((p1, p2) => Comparer<ArgumentProcessorPriority>.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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation(IA
var processorExecutor = processor.Executor;
var lazyArgumentProcessor = new Lazy<IArgumentExecutor>(() =>
{
IArgumentExecutor? instance = null;
IArgumentExecutor? instance;
try
{
instance = processorExecutor!.Value;
Expand Down Expand Up @@ -307,7 +307,7 @@ public static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation(IA
var processorExecutor = processor.Executor;
var lazyArgumentProcessor = new Lazy<IArgumentExecutor>(() =>
{
IArgumentsExecutor? instance = null;
IArgumentsExecutor? instance;
try
{
instance = (IArgumentsExecutor)processorExecutor!.Value;
Expand Down
2 changes: 1 addition & 1 deletion test/Intent/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Run(IEnumerable<string> paths, IRunLogger logger)
var methods = types.SelectMany(type => type.GetMethods().SkipExcluded()).ToList();
var methodsWithOnly = methods.Where(m => m.GetCustomAttribute<OnlyAttribute>() != null).ToList();

var methodsToRun = new List<MethodInfo>();
List<MethodInfo> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void ExecuteContainerInMultiHost(RunnerInfo runnerInfo, int expectedHost
Assert.AreEqual(expectedHost == -1 ? 1 : expectedHost > 10 ? 10 : expectedHost, hosts.Length);

List<string> tests = new();
int testsRunInsideHost = 0;
int testsRunInsideHost;
foreach (var file in hosts)
{
testsRunInsideHost = 0;
Expand Down

0 comments on commit c686e7d

Please sign in to comment.