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

Enable nullable on vstest.console #3694

Merged
merged 2 commits into from
Jun 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class ArtifactProcessingManager : IArtifactProcessingManager
private readonly ITestRunAttachmentsProcessingEventsHandler _testRunAttachmentsProcessingEventsHandler;
private readonly IFeatureFlag _featureFlag;

public ArtifactProcessingManager(string testSessionCorrelationId) :
public ArtifactProcessingManager(string? testSessionCorrelationId) :
this(testSessionCorrelationId,
new FileHelper(),
new TestRunAttachmentsProcessingManager(TestPlatformEventSource.Instance, new DataCollectorAttachmentsProcessorsFactory()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.Utilities;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Execution;

[System.Diagnostics.CodeAnalysis.SuppressMessage("ApiDesign", "RS0030:Do not used banned APIs", Justification = "StringUtils is not available for all TFMs of testhost")]
internal static class DebuggerBreakpoint
{
internal static void AttachVisualStudioDebugger(string environmentVariable)
Expand Down Expand Up @@ -87,7 +86,7 @@ private static bool AttachVs(Process process, int? vsPid)
#endif
}

private static string FindAttachVs()
private static string? FindAttachVs()
{
#if NETCOREAPP1_0
return null;
Expand Down Expand Up @@ -115,7 +114,7 @@ private static string FindAttachVs()
#endif
}

private static string FindOnPath(string exeName)
private static string? FindOnPath(string exeName)
{
var paths = Environment.GetEnvironmentVariable("PATH").Split(';');
foreach (var p in paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Globalization;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Execution;

internal static class UiLanguageOverride
Expand All @@ -16,7 +14,7 @@ internal static class UiLanguageOverride

internal static void SetCultureSpecifiedByUser()
{
CultureInfo language = GetOverriddenUiLanguage();
var language = GetOverriddenUiLanguage();
if (language == null)
{
return;
Expand All @@ -32,7 +30,7 @@ private static void ApplyOverrideToCurrentProcess(CultureInfo language)
CultureInfo.DefaultThreadCurrentUICulture = language;
}

private static CultureInfo GetOverriddenUiLanguage()
private static CultureInfo? GetOverriddenUiLanguage()
{
// DOTNET_CLI_UI_LANGUAGE=<culture name> is the main way for users to customize the CLI's UI language.
string dotnetCliLanguage = Environment.GetEnvironmentVariable(DotnetCliUiLanguage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ITestPlatform : IDisposable
/// <summary>
/// Updates the extensions to be used by the test service.
/// </summary>
///
///
/// <param name="pathToAdditionalExtensions">
/// Specifies the path to unit test extensions. If no additional extension is available,
/// then specify null or empty list.
Expand All @@ -36,11 +36,11 @@ void UpdateExtensions(
/// <summary>
/// Creates a discovery request.
/// </summary>
///
///
/// <param name="requestData">Providing common services and data for discovery.</param>
/// <param name="discoveryCriteria">Specifies the discovery parameters.</param>
/// <param name="options">Test platform options.</param>
///
///
/// <returns>A DiscoveryRequest object.</returns>
IDiscoveryRequest CreateDiscoveryRequest(
IRequestData requestData,
Expand All @@ -51,11 +51,11 @@ IDiscoveryRequest CreateDiscoveryRequest(
/// <summary>
/// Creates a test run request.
/// </summary>
///
///
/// <param name="requestData">Providing common services and data for execution.</param>
/// <param name="testRunCriteria">Specifies the test run criteria.</param>
/// <param name="options">Test platform options.</param>
///
///
/// <returns>A RunRequest object.</returns>
ITestRunRequest CreateTestRunRequest(
IRequestData requestData,
Expand All @@ -66,7 +66,7 @@ ITestRunRequest CreateTestRunRequest(
/// <summary>
/// Starts a test session.
/// </summary>
///
///
/// <param name="requestData">
/// Providing common services and data for test session start.
/// </param>
Expand Down
6 changes: 6 additions & 0 deletions src/vstest.console/BannedSymbols.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
M:System.Diagnostics.Debug.Assert(System.Boolean); Use 'TPDebug.Assert' instead
M:System.Diagnostics.Debug.Assert(System.Boolean,System.String); Use 'TPDebug.Assert' instead
M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean); Use 'TPDebug.Assert' instead
M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean,System.String); Use 'TPDebug.Assert' instead
M:System.String.IsNullOrEmpty(System.String); Use 'StringUtils.IsNullOrEmpty' instead
M:System.String.IsNullOrWhiteSpace(System.String); Use 'StringUtils.IsNullOrWhiteSpace' instead
4 changes: 1 addition & 3 deletions src/vstest.console/CommandLine/AssemblyMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities;

internal class AssemblyMetadataProvider : IAssemblyMetadataProvider
{
private static AssemblyMetadataProvider s_instance;
private static AssemblyMetadataProvider? s_instance;
private readonly IFileHelper _fileHelper;

/// <summary>
Expand Down
27 changes: 6 additions & 21 deletions src/vstest.console/CommandLine/CommandArgumentPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.Contracts;
using System.Diagnostics.CodeAnalysis;

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;

#nullable disable
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

namespace Microsoft.VisualStudio.TestPlatform.CommandLine;

Expand Down Expand Up @@ -37,12 +35,7 @@ internal class CommandArgumentPair
/// <param name="input">Input to break up.</param>
public CommandArgumentPair(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
throw new ArgumentException(CommandLineResources.CannotBeNullOrEmpty, nameof(input));
}
Contract.Ensures(!string.IsNullOrWhiteSpace(Command));

ValidateArg.NotNullOrWhiteSpace(input, nameof(input));
Parse(input);
}

Expand All @@ -53,14 +46,7 @@ public CommandArgumentPair(string input)
/// <param name="argument">The argument portion of the input.</param>
public CommandArgumentPair(string command, string argument)
{
if (string.IsNullOrWhiteSpace(command))
{
throw new ArgumentException(CommandLineResources.CannotBeNullOrEmpty, nameof(command));
}

Contract.Ensures(Command == command);
Contract.Ensures(Argument == argument);

ValidateArg.NotNullOrWhiteSpace(command, nameof(command));
Command = command;
Argument = argument;
}
Expand All @@ -69,11 +55,10 @@ public CommandArgumentPair(string command, string argument)
/// Parses the input into the command and argument parts.
/// </summary>
/// <param name="input">Input string to parse.</param>
[MemberNotNull(nameof(Command), nameof(Argument))]
private void Parse(string input)
{
Contract.Requires(!string.IsNullOrWhiteSpace(input));
Contract.Ensures(!string.IsNullOrWhiteSpace(Command));
Contract.Ensures(Argument != null);
ValidateArg.NotNull(input, nameof(input));

// Find the index of the separator (":")
int index = input.IndexOf(Separator, StringComparison.OrdinalIgnoreCase);
Expand Down
6 changes: 2 additions & 4 deletions src/vstest.console/CommandLine/CommandLineException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CommandLine;

/// <summary>
Expand All @@ -24,7 +22,7 @@ public CommandLineException()
/// Initializes with the message.
/// </summary>
/// <param name="message">Message for the exception.</param>
public CommandLineException(string message)
public CommandLineException(string? message)
: base(message)
{
}
Expand All @@ -34,7 +32,7 @@ public CommandLineException(string message)
/// </summary>
/// <param name="message">Message for the exception.</param>
/// <param name="innerException">The inner exception.</param>
public CommandLineException(string message, Exception innerException)
public CommandLineException(string? message, Exception? innerException)
: base(message, innerException)
{
}
Expand Down
34 changes: 17 additions & 17 deletions src/vstest.console/CommandLine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;

Expand All @@ -15,8 +16,6 @@

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CommandLine;

/// <summary>
Expand Down Expand Up @@ -44,13 +43,13 @@ internal class CommandLineOptions
/// </summary>
private readonly TimeSpan _defaultRetrievalTimeout = new(0, 0, 0, 1, 500);

private static CommandLineOptions s_instance;
private static CommandLineOptions? s_instance;

private List<string> _sources = new();

private Architecture _architecture;

private Framework _frameworkVersion;
private Framework? _frameworkVersion;

/// <summary>
/// Gets the instance.
Expand Down Expand Up @@ -111,7 +110,7 @@ public IEnumerable<string> Sources
/// <summary>
/// Path to the custom test adapters.
/// </summary>
public string[] TestAdapterPath { get; set; }
public string[]? TestAdapterPath { get; set; }

/// <summary>
/// Test adapter loading strategy.
Expand All @@ -131,17 +130,17 @@ public IEnumerable<string> Sources
/// <summary>
/// Configuration the project is built for e.g. Debug/Release
/// </summary>
public string Configuration { get; set; }
public string? Configuration { get; set; }

/// <summary>
/// Directory containing the temporary outputs
/// </summary>
public string BuildBasePath { get; set; }
public string? BuildBasePath { get; set; }

/// <summary>
/// Directory containing the binaries to run
/// </summary>
public string Output { get; set; }
public string? Output { get; set; }

/// <summary>
/// Specifies the frequency of the runStats/discoveredTests event
Expand All @@ -156,22 +155,22 @@ public IEnumerable<string> Sources
/// <summary>
/// Test case filter value for run with sources.
/// </summary>
public string TestCaseFilterValue { get; set; }
public string? TestCaseFilterValue { get; set; }

/// <summary>
/// Target Path used by ListFullyQualifiedTests option
/// </summary>
public string ListTestsTargetPath { get; set; }
public string? ListTestsTargetPath { get; set; }

/// <summary>
/// Specifies the Target Device
/// </summary>
public string TargetDevice { get; set; }
public string? TargetDevice { get; set; }

/// <summary>
/// Specifies whether the target device has a Windows Phone context or not
/// </summary>
public bool HasPhoneContext => !string.IsNullOrEmpty(TargetDevice);
public bool HasPhoneContext => !StringUtils.IsNullOrEmpty(TargetDevice);
Evangelink marked this conversation as resolved.
Show resolved Hide resolved

public bool TestAdapterPathsSet => (TestAdapterPath?.Length ?? 0) != 0;

Expand Down Expand Up @@ -224,7 +223,7 @@ public bool ShouldCollectSourceInformation
/// <summary>
/// Gets or sets the target Framework version for test run.
/// </summary>
internal Framework TargetFrameworkVersion
internal Framework? TargetFrameworkVersion
{
get
{
Expand All @@ -240,17 +239,18 @@ internal Framework TargetFrameworkVersion
/// <summary>
/// Gets a value indicating whether /Framework has been specified on command line or not.
/// </summary>
[MemberNotNullWhen(true, nameof(TargetFrameworkVersion))]
internal bool FrameworkVersionSpecified { get; private set; }

/// <summary>
/// Gets or sets the results directory for test run.
/// </summary>
internal string ResultsDirectory { get; set; }
internal string? ResultsDirectory { get; set; }

/// <summary>
/// Gets or sets the /setting switch value. i.e path to settings file.
/// </summary>
internal string SettingsFile { get; set; }
internal string? SettingsFile { get; set; }

/// <summary>
/// Gets or sets the /ArtifactsProcessingMode value.
Expand All @@ -260,15 +260,15 @@ internal Framework TargetFrameworkVersion
/// <summary>
/// Gets or sets the /TestSessionCorrelationId value.
/// </summary>
internal string TestSessionCorrelationId { get; set; }
internal string? TestSessionCorrelationId { get; set; }

/// <summary>
/// Adds a source file to look for tests in.
/// </summary>
/// <param name="source">Path to source file to look for tests in.</param>
public void AddSource(string source)
{
if (string.IsNullOrWhiteSpace(source))
if (source.IsNullOrWhiteSpace())
{
throw new TestSourceException(CommandLineResources.CannotBeNullOrEmpty);
}
Expand Down
Loading