Skip to content

Commit

Permalink
Fix warnings on main (IDE only) (#3914)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Aug 1, 2022
1 parent 5bae4ce commit 200a783
Show file tree
Hide file tree
Showing 37 changed files with 65 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ private DataCollectorExtensionManager DataCollectorExtensionManager
{
get
{
if (_dataCollectorExtensionManager == null)
{
// TODO : change IMessageSink and use IMessageLogger instead.
_dataCollectorExtensionManager = DataCollectorExtensionManager.Create(TestSessionMessageLogger.Instance);
}
// TODO : change IMessageSink and use IMessageLogger instead.
_dataCollectorExtensionManager ??= DataCollectorExtensionManager.Create(TestSessionMessageLogger.Instance);

return _dataCollectorExtensionManager;
}
Expand All @@ -141,10 +138,7 @@ public static DataCollectionManager Create(IMessageSink messageSink, IRequestDat
{
lock (SyncObject)
{
if (Instance == null)
{
Instance = new DataCollectionManager(messageSink, requestData);
}
Instance ??= new DataCollectionManager(messageSink, requestData);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ public List<string> GetExtensionPaths(string endsWithPattern, bool skipDefaultEx
// Discover the test extensions from candidate assemblies.
pluginInfos = GetTestExtensions<TPluginInfo, TExtension>(allExtensionPaths);

if (TestExtensions == null)
{
TestExtensions = new TestExtensions();
}
TestExtensions ??= new TestExtensions();

TestExtensions.AddExtension(pluginInfos);

Expand Down Expand Up @@ -333,10 +330,7 @@ internal Dictionary<string, TPluginInfo> GetTestExtensions<TPluginInfo, TExtensi
var pluginInfos = GetTestExtensions<TPluginInfo, TExtension>(new List<string>() { extensionAssembly });

// Add extensions discovered to the cache.
if (TestExtensions == null)
{
TestExtensions = new TestExtensions();
}
TestExtensions ??= new TestExtensions();

TestExtensions.AddExtension(pluginInfos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ private Assembly ExtensionManagerDefAssembly
{
get
{
if (_extensionManagerAssembly == null)
{
_extensionManagerAssembly = Assembly.Load(new AssemblyName(ExtensionManagerAssemblyName));
}
_extensionManagerAssembly ??= Assembly.Load(new AssemblyName(ExtensionManagerAssemblyName));
return _extensionManagerAssembly;
}
}
Expand Down Expand Up @@ -183,10 +180,7 @@ private Assembly SettingsManagerAssembly
{
get
{
if (_settingsManagerAssembly == null)
{
_settingsManagerAssembly = Assembly.Load(new AssemblyName(SettingsManagerAssemblyName));
}
_settingsManagerAssembly ??= Assembly.Load(new AssemblyName(SettingsManagerAssemblyName));

return _settingsManagerAssembly;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Microsoft.TestPlatform.Common/RunSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public static RunSettingsManager Instance

lock (LockObject)
{
if (s_runSettingsManagerInstance == null)
{
s_runSettingsManagerInstance = new RunSettingsManager();
}
s_runSettingsManagerInstance ??= new RunSettingsManager();
}

return s_runSettingsManagerInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private static Type[] DiscoverTestExtensionTypesV2AttributeInternal(Assembly loa
continue;
}

if (extensions is null) extensions = new List<Tuple<int, Type>>();
extensions ??= new List<Tuple<int, Type>>();
extensions.Add(Tuple.Create(version, extensionType));
EqtTrace.Verbose($"MetadataReaderExtensionsHelper: Valid extension found: extension type '{extension}' identifier '{extensionIdentifier}' implementation '{extensionType}' version '{version}'");
}
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.TestPlatform.Common/Utilities/SimpleJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,7 @@ internal static StringBuilder EscapeBuilder
{
get
{
if (s_escapeBuilder == null)
s_escapeBuilder = new StringBuilder();
s_escapeBuilder ??= new StringBuilder();
return s_escapeBuilder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public static DataCollectionTestCaseEventSender Create()
{
lock (SyncObject)
{
if (Instance == null)
{
Instance = new DataCollectionTestCaseEventSender();
}
Instance ??= new DataCollectionTestCaseEventSender();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,7 @@ private static T Deserialize<T>(JsonSerializer serializer, JToken jToken)

private static JsonSerializer GetPayloadSerializer(int? version)
{
if (version == null)
{
version = 1;
}
version ??= 1;

return version switch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public static ConsoleOutput Instance

lock (LockObject)
{
if (s_consoleOutput == null)
{
s_consoleOutput = new ConsoleOutput();
}
s_consoleOutput ??= new ConsoleOutput();
}

return s_consoleOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ public void Abort(ITestDiscoveryEventsHandler2 eventHandler)
return;
}

if (_baseTestDiscoveryEventsHandler is null)
{
_baseTestDiscoveryEventsHandler = eventHandler;
}
_baseTestDiscoveryEventsHandler ??= eventHandler;

if (_isCommunicationEstablished)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, IInternalTestRu
public virtual void Cancel(IInternalTestRunEventsHandler eventHandler)
{
// Just in case ExecuteAsync isn't called yet, set the eventhandler.
if (_baseTestRunEventsHandler == null)
{
_baseTestRunEventsHandler = eventHandler;
}
_baseTestRunEventsHandler ??= eventHandler;

// Do nothing if the proxy is not initialized yet.
if (_proxyOperationManager == null)
Expand All @@ -299,10 +296,7 @@ public virtual void Cancel(IInternalTestRunEventsHandler eventHandler)
public void Abort(IInternalTestRunEventsHandler eventHandler)
{
// Just in case ExecuteAsync isn't called yet, set the eventhandler.
if (_baseTestRunEventsHandler == null)
{
_baseTestRunEventsHandler = eventHandler;
}
_baseTestRunEventsHandler ??= eventHandler;

// Do nothing if the proxy is not initialized yet.
if (_proxyOperationManager == null)
Expand Down Expand Up @@ -355,10 +349,7 @@ public bool AttachDebuggerToProcess(AttachDebuggerInfo attachDebuggerInfo)
// TestHost did not provide any additional TargetFramework info for the process it wants to attach to,
// specify the TargetFramework of the testhost, in case it is just an old testhost that is not aware
// of this capability.
if (attachDebuggerInfo.TargetFramework is null)
{
attachDebuggerInfo.TargetFramework = _proxyOperationManager?.TestHostManagerFramework?.ToString();
};
attachDebuggerInfo.TargetFramework ??= _proxyOperationManager?.TestHostManagerFramework?.ToString();

if (attachDebuggerInfo.Sources is null || !attachDebuggerInfo.Sources.Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ public override int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testP
{
if (_dataCollectionEnvironmentVariables != null)
{
if (testProcessStartInfo.EnvironmentVariables == null)
{
testProcessStartInfo.EnvironmentVariables = new Dictionary<string, string?>();
}
testProcessStartInfo.EnvironmentVariables ??= new Dictionary<string, string?>();

foreach (var envVariable in _dataCollectionEnvironmentVariables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ private TestLoggerExtensionManager TestLoggerExtensionManager
{
get
{
if (_testLoggerExtensionManager == null)
{
_testLoggerExtensionManager = TestLoggerExtensionManager.Create(_messageLogger);
}
_testLoggerExtensionManager ??= TestLoggerExtensionManager.Create(_messageLogger);

return _testLoggerExtensionManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ internal static void AddTelemetry(TestResult testResult, IDictionary<string, int
// add additional info for mstestadapter/v1
if (IsMsTestV1Adapter(executorUri))
{
if (s_testTypeProperty == null)
{
// this is present when the legacy runner is used, and contains a guid which
// is the test type.
// GenericTestType 982B8C01-1A8A-48F5-B98A-67EE64BC8687
// OrderedTestType ec4800e8-40e5-4ab3-8510-b8bf29b1904d
// UnitTestType 13CDC9D9-DDB5-4fa4-A97D-D965CCFC6D4B
// WebTestType 4e7599fa-5ecb-43e9-a887-cd63cf72d207
// CodedWebTestType 37e36796-fb51-4610-8d5c-e00ceaa68b9f
s_testTypeProperty = TestProperty.Register("TestType", "TestType", typeof(Guid), typeof(TestResult));
}
// this is present when the legacy runner is used, and contains a guid which
// is the test type.
// GenericTestType 982B8C01-1A8A-48F5-B98A-67EE64BC8687
// OrderedTestType ec4800e8-40e5-4ab3-8510-b8bf29b1904d
// UnitTestType 13CDC9D9-DDB5-4fa4-A97D-D965CCFC6D4B
// WebTestType 4e7599fa-5ecb-43e9-a887-cd63cf72d207
// CodedWebTestType 37e36796-fb51-4610-8d5c-e00ceaa68b9f
s_testTypeProperty ??= TestProperty.Register("TestType", "TestType", typeof(Guid), typeof(TestResult));

if (s_extensionIdProperty == null)
{
s_extensionIdProperty = TestProperty.Register("ExtensionId", "ExtensionId", typeof(string), typeof(TestResult));
}
s_extensionIdProperty ??= TestProperty.Register("ExtensionId", "ExtensionId", typeof(string), typeof(TestResult));
// Get addional data from test result passed by MSTestv1
// Only legacy tests have testtype.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public static TestSessionPool Instance
{
lock (InstanceLockObject)
{
if (s_instance == null)
{
s_instance = new TestSessionPool();
}
s_instance ??= new TestSessionPool();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ private void AddToParentResult(Guid parentExecutionId, ObjectModel.TestResult te

if (Results.TryGetValue(parentExecutionId, out var parentTestResult))
{
if (parentTestResult.InnerTestResults == null)
parentTestResult.InnerTestResults = new List<ObjectModel.TestResult>();
parentTestResult.InnerTestResults ??= new List<ObjectModel.TestResult>();

parentTestResult.InnerTestResults.Add(testResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ internal sealed class TestCategoryItem : IXmlTestStore
public TestCategoryItem(string? category)
{
// Treat null as empty.
if (category == null)
{
category = string.Empty;
}
category ??= string.Empty;


_category = StripIllegalChars(category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public List<TestEntry> TestEntries
{
get
{
if (_testEntries == null)
{
_testEntries = new List<TestEntry>();
}
_testEntries ??= new List<TestEntry>();

return _testEntries;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ public static TestListCategory UncategorizedResults
{
lock (ReservedCategoryLock)
{
if (s_uncategorizedResults == null)
{
s_uncategorizedResults = new TestListCategory(
s_uncategorizedResults ??= new TestListCategory(
TrxLoggerResources.TS_UncategorizedResults, TestListCategoryId.Uncategorized, TestListCategoryId.Root);
}
}
}

Expand All @@ -89,11 +86,8 @@ public static TestListCategory AllResults
{
lock (ReservedCategoryLock)
{
if (s_allResults == null)
{
s_allResults = new TestListCategory(
s_allResults ??= new TestListCategory(
TrxLoggerResources.TS_AllResults, TestListCategoryId.AllItems, TestListCategoryId.Root);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ public string ErrorMessage
get { return _errorInfo?.Message ?? string.Empty; }
set
{
if (_errorInfo == null)
_errorInfo = new TestResultErrorInfo();
_errorInfo ??= new TestResultErrorInfo();

_errorInfo.Message = value;
}
Expand All @@ -315,8 +314,7 @@ public string ErrorStackTrace

set
{
if (_errorInfo == null)
_errorInfo = new TestResultErrorInfo();
_errorInfo ??= new TestResultErrorInfo();

_errorInfo.StackTrace = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public List<ITestResult> InnerResults
{
get
{
if (_innerResults == null)
{
_innerResults = new List<ITestResult>();
}
_innerResults ??= new List<ITestResult>();
return _innerResults;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ private string ChildElementName
{
get
{
if (_childElementName == null)
{
// All we can do here is to delegate to T. Cannot cast T to IXmlTestStoreCustom as T is a type, not an instance.
_childElementName = typeof(T).Name;
}
// All we can do here is to delegate to T. Cannot cast T to IXmlTestStoreCustom as T is a type, not an instance.
_childElementName ??= typeof(T).Name;
return _childElementName;
}
}
Expand Down
Loading

0 comments on commit 200a783

Please sign in to comment.