Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use !! null check #3341

Merged
merged 7 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ dotnet_diagnostic.CA1806.severity = warning # not default, increased severity to
# CA1834: Consider using 'StringBuilder.Append(char)' when applicable
dotnet_diagnostic.CA1834.severity = warning # not default, increased severity to ensure it is always applied

# IDE0190: Null check can be simplified
# Keep this in sync with the related C# rule: csharp_style_prefer_parameter_null_checking
dotnet_diagnostic.IDE0190.severity = warning # not default, increased severity to ensure it is applied

#### C# Coding Conventions ####

# var preferences
Expand Down Expand Up @@ -248,10 +252,14 @@ csharp_style_unused_value_expression_statement_preference = discard_variable:sil
# Keep this in sync with the related .NET rule: IDE0065
csharp_using_directive_placement = inside_namespace:warning

# IDE0190: Null check can be simplified
# Keep this in sync with the related .NET rule: IDE0190
csharp_style_prefer_parameter_null_checking = true # not default, increased severity to ensure it is applied

#### .NET Formatting Rules ####

# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = warning
dotnet_diagnostic.IDE0055.severity = suggestion # Downgraded to suggestion due to https://github.com/dotnet/roslyn/issues/59414

#### C# Formatting Rules ####

Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"sdk": {
"version": "6.0.100",
"version": "6.0.300-preview.22110.5",
"rollForward": "minor",
"allowPrerelease": false,
"architecture": "x64"
},
"tools": {
"dotnet": "6.0.100"
"dotnet": "6.0.300-preview.22110.5"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22103.1",
Expand Down
10 changes: 5 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function install_cli()
# Skip download of dotnet toolset if REPO API is enabled
local failed=false
local install_script="$TP_TOOLS_DIR/dotnet-install.sh"
local remote_path="https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.sh"
local remote_path="https://dot.net/v1/dotnet-install.sh"

log "Installing dotnet cli..."
local start=$SECONDS
Expand All @@ -212,12 +212,12 @@ function install_cli()
fi
chmod u+x $install_script
# Get netcoreapp1.1 shared components
$install_script --runtime dotnet --version "2.1.0" --channel "release/2.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64
$install_script --runtime dotnet --version "3.1.0" --channel "release/3.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64
$install_script --runtime dotnet --version "5.0.1" --channel "release/5.0.1" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64
$install_script --runtime dotnet --version "2.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64
$install_script --runtime dotnet --version "3.1.0" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64
$install_script --runtime dotnet --version "5.0.1" --install-dir "$TP_DOTNET_DIR" --no-path --architecture x64

log "install_cli: Get the latest dotnet cli toolset..."
$install_script --install-dir "$TP_DOTNET_DIR" --no-path --channel "main" --version $DOTNET_CLI_VERSION
$install_script --install-dir "$TP_DOTNET_DIR" --no-path --version $DOTNET_CLI_VERSION


log " ---- dotnet x64"
Expand Down
2 changes: 1 addition & 1 deletion scripts/common.lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Install-DotNetCli
{
$timer = Start-Timer
Write-Log "Install-DotNetCli: Get dotnet-install.ps1 script..."
$dotnetInstallRemoteScript = "https://raw.githubusercontent.com/dotnet/install-scripts/main/src/dotnet-install.ps1"
$dotnetInstallRemoteScript = "https://dot.net/v1/dotnet-install.ps1"
$dotnetInstallScript = Join-Path $env:TP_TOOLS_DIR "dotnet-install.ps1"
if (-not (Test-Path $env:TP_TOOLS_DIR)) {
New-Item $env:TP_TOOLS_DIR -Type Directory | Out-Null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,8 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
/// More information about <paramref name="managedTypeName"/> and <paramref name="managedMethodName"/> can be found in
/// <see href="https://github.com/microsoft/vstest-docs/blob/main/RFCs/0017-Managed-TestCase-Properties.md">the RFC</see>.
/// </remarks>
public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName, out string[] hierarchyValues)
public static void GetManagedName(MethodBase method!!, out string managedTypeName, out string managedMethodName, out string[] hierarchyValues)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}

if (!ReflectionHelpers.IsMethod(method))
{
throw new NotSupportedException(nameof(method));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,8 @@ public void Dispose()
/// <summary>
/// Invoked when test run is complete
/// </summary>
public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs!!, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
{
if (runCompleteArgs == null)
{
throw new ArgumentNullException(nameof(runCompleteArgs));
}

bool isAborted = runCompleteArgs.IsAborted;
bool isCanceled = runCompleteArgs.IsCanceled;

Expand Down
20 changes: 3 additions & 17 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ protected TestPlatform(
/// <inheritdoc/>
public IDiscoveryRequest CreateDiscoveryRequest(
IRequestData requestData,
DiscoveryCriteria discoveryCriteria,
DiscoveryCriteria discoveryCriteria!!,
TestPlatformOptions options)
{
if (discoveryCriteria == null)
{
throw new ArgumentNullException(nameof(discoveryCriteria));
}

// Update cache with Extension folder's files.
AddExtensionAssemblies(discoveryCriteria.RunSettings);
Expand Down Expand Up @@ -120,14 +116,9 @@ public IDiscoveryRequest CreateDiscoveryRequest(
/// <inheritdoc/>
public ITestRunRequest CreateTestRunRequest(
IRequestData requestData,
TestRunCriteria testRunCriteria,
TestRunCriteria testRunCriteria!!,
TestPlatformOptions options)
{
if (testRunCriteria == null)
{
throw new ArgumentNullException(nameof(testRunCriteria));
}

AddExtensionAssemblies(testRunCriteria.TestRunSettings);

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);
Expand Down Expand Up @@ -162,14 +153,9 @@ public ITestRunRequest CreateTestRunRequest(
/// <inheritdoc/>
public bool StartTestSession(
IRequestData requestData,
StartTestSessionCriteria testSessionCriteria,
StartTestSessionCriteria testSessionCriteria!!,
ITestSessionEventsHandler eventsHandler)
{
if (testSessionCriteria == null)
{
throw new ArgumentNullException(nameof(testSessionCriteria));
}

AddExtensionAssemblies(testSessionCriteria.RunSettings);

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testSessionCriteria.RunSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,8 @@ public static Type GetTestExtensionType(string extensionTypeName)
/// <typeparam name="T">Return type of the test extension</typeparam>
/// <param name="extensionType">Data type of the extension to be instantiated</param>
/// <returns>Test extension instance</returns>
public static T CreateTestExtension<T>(Type extensionType)
public static T CreateTestExtension<T>(Type extensionType!!)
{
if (extensionType == null)
{
throw new ArgumentNullException(nameof(extensionType));
}

EqtTrace.Info("TestPluginManager.CreateTestExtension: Attempting to load test extension: " + extensionType);

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ public class LazyExtension<TExtension, TMetadata>
/// </summary>
/// <param name="instance">Test extension Instance</param>
/// <param name="metadata">test extension metadata</param>
public LazyExtension(TExtension instance, TMetadata metadata)
public LazyExtension(TExtension instance!!, TMetadata metadata)
{
if (instance == null)
{
throw new ArgumentNullException(nameof(instance));
}

if (metadata == null)
{
throw new ArgumentNullException(nameof(instance));
Expand All @@ -54,10 +49,10 @@ public LazyExtension(TExtension instance, TMetadata metadata)
/// </summary>
/// <param name="pluginInfo">Test plugin to instantiated on demand.</param>
/// <param name="metadataType">Metadata type to instantiate on demand</param>
public LazyExtension(TestPluginInformation pluginInfo, Type metadataType)
public LazyExtension(TestPluginInformation pluginInfo!!, Type metadataType!!)
{
TestPluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo));
_metadataType = metadataType ?? throw new ArgumentNullException(nameof(metadataType));
TestPluginInfo = pluginInfo;
_metadataType = metadataType;
IsExtensionCreated = false;
}

Expand All @@ -66,14 +61,9 @@ public LazyExtension(TestPluginInformation pluginInfo, Type metadataType)
/// </summary>
/// <param name="pluginInfo">Test plugin to instantiated on demand</param>
/// <param name="metadata">Test extension metadata</param>
public LazyExtension(TestPluginInformation pluginInfo, TMetadata metadata)
public LazyExtension(TestPluginInformation pluginInfo!!, TMetadata metadata!!)
{
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}

TestPluginInfo = pluginInfo ?? throw new ArgumentNullException(nameof(pluginInfo));
TestPluginInfo = pluginInfo;
_metadata = metadata;
IsExtensionCreated = false;
}
Expand All @@ -83,14 +73,9 @@ public LazyExtension(TestPluginInformation pluginInfo, TMetadata metadata)
/// </summary>
/// <param name="creator">Test extension creator delegate</param>
/// <param name="metadata">test extension metadata</param>
public LazyExtension(Func<TExtension> creator, TMetadata metadata)
public LazyExtension(Func<TExtension> creator!!, TMetadata metadata!!)
{
if (metadata == null)
{
throw new ArgumentNullException(nameof(metadata));
}

_extensionCreator = creator ?? throw new ArgumentNullException(nameof(creator));
_extensionCreator = creator;
_metadata = metadata;
IsExtensionCreated = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ internal class DataCollectorAttachmentProcessor
/// </summary>
public IDataCollectorAttachmentProcessor DataCollectorAttachmentProcessorInstance { get; private set; }

public DataCollectorAttachmentProcessor(string friendlyName, IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessor)
public DataCollectorAttachmentProcessor(string friendlyName, IDataCollectorAttachmentProcessor dataCollectorAttachmentProcessor!!)
{
FriendlyName = string.IsNullOrEmpty(friendlyName) ? throw new ArgumentException("Invalid FriendlyName", nameof(friendlyName)) : friendlyName;
DataCollectorAttachmentProcessorInstance = dataCollectorAttachmentProcessor ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentProcessor));
DataCollectorAttachmentProcessorInstance = dataCollectorAttachmentProcessor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,8 @@ internal void EnableEvents()
/// Raises a test run message event to the enabled loggers.
/// </summary>
/// <param name="args">Arguments to be raised.</param>
internal void RaiseTestRunMessage(TestRunMessageEventArgs args)
internal void RaiseTestRunMessage(TestRunMessageEventArgs args!!)
{
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}

CheckDisposed();

// Sending 0 size as this event is not expected to contain any data.
Expand Down
12 changes: 1 addition & 11 deletions src/Microsoft.TestPlatform.Common/Utilities/FakesUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,8 @@ public static class FakesUtilities
/// <param name="sources">test sources</param>
/// <param name="runSettingsXml">runsettings</param>
/// <returns>updated runsettings for fakes</returns>
public static string GenerateFakesSettingsForRunConfiguration(string[] sources, string runSettingsXml)
public static string GenerateFakesSettingsForRunConfiguration(string[] sources!!, string runSettingsXml!!)
{
if (sources == null)
{
throw new ArgumentNullException(nameof(sources));
}

if (runSettingsXml == null)
{
throw new ArgumentNullException(nameof(runSettingsXml));
}

var doc = new XmlDocument();
using (var xmlReader = XmlReader.Create(
new StringReader(runSettingsXml),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,8 @@ public static void Write(this IOutput output, string message, OutputLevel level,
/// <param name="messageTypeFormat">Format string for the message type.</param>
/// <param name="format">Format string for the error message.</param>
/// <param name="args">Arguments to format into the format string.</param>
private static void Output(IOutput output, OutputLevel level, string messageTypeFormat, string format, params object[] args)
private static void Output(IOutput output!!, OutputLevel level, string messageTypeFormat, string format, params object[] args)
{
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}

output.WriteLine(Format(messageTypeFormat, format, args), level);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public class JobQueue<T> : IDisposable
/// <param name="maxQueueSize">The max Queue Size.</param>
/// <param name="enableBounds">The enable Bounds.</param>
/// <param name="exceptionLogger">The exception Logger.</param>
public JobQueue(Action<T> processJob, string displayName, int maxQueueLength, int maxQueueSize, bool enableBounds, Action<string> exceptionLogger)
public JobQueue(Action<T> processJob!!, string displayName, int maxQueueLength, int maxQueueSize, bool enableBounds, Action<string> exceptionLogger)
{
_processJob = processJob ?? throw new ArgumentNullException(nameof(processJob));
_processJob = processJob;

if (string.IsNullOrWhiteSpace(displayName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ public static void SafeInvoke(this Delegate delegates, object sender, EventArgs
/// <param name="sender">Sender to use when raising the event.</param>
/// <param name="args">Arguments to provide.</param>
/// <param name="traceDisplayName">Name to use when tracing out errors.</param>
public static void SafeInvoke(this Delegate delegates, object sender, object args, string traceDisplayName)
public static void SafeInvoke(this Delegate delegates, object sender, object args!!, string traceDisplayName)
{
if (args == null)
{
throw new ArgumentNullException(nameof(args));
}

if (string.IsNullOrWhiteSpace(traceDisplayName))
{
throw new ArgumentNullException(nameof(traceDisplayName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ internal class TestRunAttachmentsProcessingManager : ITestRunAttachmentsProcessi
/// <summary>
/// Initializes a new instance of the <see cref="TestRunAttachmentsProcessingManager"/> class.
/// </summary>
public TestRunAttachmentsProcessingManager(ITestPlatformEventSource testPlatformEventSource, IDataCollectorAttachmentsProcessorsFactory dataCollectorAttachmentsProcessorsFactory)
public TestRunAttachmentsProcessingManager(ITestPlatformEventSource testPlatformEventSource!!, IDataCollectorAttachmentsProcessorsFactory dataCollectorAttachmentsProcessorsFactory!!)
{
_testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource));
_dataCollectorAttachmentsProcessorsFactory = dataCollectorAttachmentsProcessorsFactory ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsProcessorsFactory));
_testPlatformEventSource = testPlatformEventSource;
_dataCollectorAttachmentsProcessorsFactory = dataCollectorAttachmentsProcessorsFactory;
}

/// <inheritdoc/>
Expand Down Expand Up @@ -209,9 +209,9 @@ private class AttachmentsProcessingMessageLogger : IMessageLogger
{
private readonly ITestRunAttachmentsProcessingEventsHandler _eventsHandler;

public AttachmentsProcessingMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler)
public AttachmentsProcessingMessageLogger(ITestRunAttachmentsProcessingEventsHandler eventsHandler!!)
{
_eventsHandler = eventsHandler ?? throw new ArgumentNullException(nameof(eventsHandler));
_eventsHandler = eventsHandler;
}

public void SendMessage(TestMessageLevel testMessageLevel, string message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ internal class ParallelRunDataAggregator

#endregion

public ParallelRunDataAggregator(string runSettingsXml)
public ParallelRunDataAggregator(string runSettingsXml!!)
{
RunSettings = runSettingsXml ?? throw new ArgumentNullException(nameof(runSettingsXml));
RunSettings = runSettingsXml;
ElapsedTime = TimeSpan.Zero;
RunContextAttachments = new Collection<AttachmentSet>();
RunCompleteArgsAttachments = new List<AttachmentSet>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class TestHostManagerFactory : ITestHostManagerFactory
/// <param name="requestData">
/// Provide common services and data for a discovery/run request.
/// </param>
public TestHostManagerFactory(IRequestData requestData)
public TestHostManagerFactory(IRequestData requestData!!)
{
_requestData = requestData ?? throw new System.ArgumentNullException(nameof(requestData));
_requestData = requestData;
}

/// <summary>
Expand Down
Loading