Skip to content

Commit

Permalink
Enable nullable on VS Translation layer (#3781)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Jun 20, 2022
1 parent 8f8c5f2 commit 59bf13d
Show file tree
Hide file tree
Showing 31 changed files with 519 additions and 636 deletions.
2 changes: 1 addition & 1 deletion playground/TestPlatform.Playground/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TestPlatform.Playground;

internal class EnvironmentVariables
{
public static readonly Dictionary<string, string> Variables = new()
public static readonly Dictionary<string, string?> Variables = new()
{
["VSTEST_CONNECTION_TIMEOUT"] = "999",
["VSTEST_DEBUG_NOBP"] = "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void CollectArtifacts(TestRunCompleteEventArgs testRunCompleteEventArgs,
return;
}

if (string.IsNullOrEmpty(_testSessionCorrelationId))
if (_testSessionCorrelationId.IsNullOrEmpty())
{
EqtTrace.Verbose("ArtifactProcessingManager.CollectArtifacts: null testSessionCorrelationId");
return;
Expand Down Expand Up @@ -118,12 +118,13 @@ public async Task PostProcessArtifactsAsync()
}

// This is not expected, anyway we prefer avoid exception for post processing
if (string.IsNullOrEmpty(_testSessionCorrelationId))
if (_testSessionCorrelationId.IsNullOrEmpty())
{
EqtTrace.Error("ArtifactProcessingManager.PostProcessArtifacts: Unexpected null testSessionCorrelationId");
return;
}

TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null");
if (!_fileHelper.DirectoryExists(_processArtifactFolder))
{
EqtTrace.Verbose("ArtifactProcessingManager.PostProcessArtifacts: There are no artifacts to postprocess");
Expand Down Expand Up @@ -218,10 +219,10 @@ private TestArtifacts[] LoadTestArtifacts()
{
TPDebug.Assert(_processArtifactFolder is not null, "_processArtifactFolder is null");
return _fileHelper.GetFiles(_processArtifactFolder, "*.*", SearchOption.AllDirectories)
.Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file })
.GroupBy(grp => grp.TestSessionId)
.Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause
.ToArray();
.Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file })
.GroupBy(grp => grp.TestSessionId)
.Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause
.ToArray();
}

private static Artifact? ParseArtifact(string fileName)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
using System.Diagnostics;
using System.IO;

using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;

#nullable disable

namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer;

/// <summary>
Expand All @@ -21,9 +20,10 @@ public class ConsoleParameters
{
internal static readonly ConsoleParameters Default = new();

private string _logFilePath;
private readonly IFileHelper _fileHelper;

private string? _logFilePath;

/// <summary>
/// Create instance of <see cref="ConsoleParameters"/>
/// </summary>
Expand All @@ -43,12 +43,12 @@ public ConsoleParameters(IFileHelper fileHelper)
/// Environment variables to be set for the process. This will merge the specified entries to the environment variables
/// inherited from the current process. If you wish to provide a full set of environment variables yourself set <see cref="InheritEnvironmentVariables"/> to false.
/// </summary>
public Dictionary<string, string> EnvironmentVariables { get; set; } = new Dictionary<string, string>();
public Dictionary<string, string?> EnvironmentVariables { get; set; } = new();

/// <summary>
/// When set to true (default), all environment variables are inherited from the current process and the entries provided in <see cref="EnvironmentVariables"/> are merged with that set.
/// When set to false, only the values you provide in <see cref="EnvironmentVariables"/> are used. Giving you full control of the environment vstest.console is started with.
/// This is only rarely useful and can lead to vstest.console not being able to start at all.
/// This is only rarely useful and can lead to vstest.console not being able to start at all.
/// You most likely want to use <see cref="System.Environment.GetEnvironmentVariables(System.EnvironmentVariableTarget)"/> and combine
/// <see cref="System.EnvironmentVariableTarget.Machine"/> and <see cref="System.EnvironmentVariableTarget.User"/> responses.
/// </summary>
Expand All @@ -62,7 +62,7 @@ public ConsoleParameters(IFileHelper fileHelper)
/// <summary>
/// Full path for the log file
/// </summary>
public string LogFilePath
public string? LogFilePath
{
get
{
Expand All @@ -71,15 +71,15 @@ public string LogFilePath

set
{
ValidateArg.NotNullOrEmpty(value, "LogFilePath");
ValidateArg.NotNullOrEmpty(value!, "LogFilePath");
var directoryPath = Path.GetDirectoryName(value);
if (!string.IsNullOrEmpty(directoryPath) && !_fileHelper.DirectoryExists(directoryPath))
if (!directoryPath.IsNullOrEmpty() && !_fileHelper.DirectoryExists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}

// Ensure path is double quoted. if path has white space then it can create problem.
_logFilePath = value.AddDoubleQuote();
_logFilePath = value!.AddDoubleQuote();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer;

/// <summary>
Expand Down Expand Up @@ -54,7 +52,7 @@ public void HandleLogMessage(TestMessageLevel level, string message)
/// </summary>
/// <param name="discoveryCompleteEventArgs"></param>
/// <param name="lastChunk"></param>
public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable<TestCase> lastChunk)
public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryCompleteEventArgs, IEnumerable<TestCase>? lastChunk)
{
_testDiscoveryEventsHandler.HandleDiscoveryComplete(discoveryCompleteEventArgs.TotalCount, lastChunk, discoveryCompleteEventArgs.IsAborted);
}
Expand All @@ -63,7 +61,7 @@ public void HandleDiscoveryComplete(DiscoveryCompleteEventArgs discoveryComplete
/// Handles Discovery Tests
/// </summary>
/// <param name="discoveredTestCases"></param>
public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)
public void HandleDiscoveredTests(IEnumerable<TestCase>? discoveredTestCases)
{
_testDiscoveryEventsHandler.HandleDiscoveredTests(discoveredTestCases);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using System;

#nullable disable

namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;

/// <summary>
Expand All @@ -23,12 +21,12 @@ public interface ITestSession : IDisposable, ITestSessionAsync
/// Gets the underlying test session info object.
/// </summary>
[Obsolete("This API is not final yet and is subject to changes.", false)]
TestSessionInfo TestSessionInfo { get; }
TestSessionInfo? TestSessionInfo { get; }

/// <summary>
/// Starts test discovery.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the discovery.</param>
/// <param name="discoverySettings">The run settings for the discovery.</param>
/// <param name="discoveryEventsHandler">The discovery event handler.</param>
Expand All @@ -41,7 +39,7 @@ void DiscoverTests(
/// <summary>
/// Starts test discovery.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the discovery.</param>
/// <param name="discoverySettings">The run settings for the discovery.</param>
/// <param name="options">The test platform options.</param>
Expand All @@ -62,7 +60,7 @@ void DiscoverTests(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="testRunEventsHandler">The run event handler.</param>
Expand All @@ -75,7 +73,7 @@ void RunTests(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="options">The test platform options.</param>
Expand All @@ -90,7 +88,7 @@ void RunTests(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="testCases">The list of test cases for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="testRunEventsHandler">The run event handler.</param>
Expand All @@ -103,7 +101,7 @@ void RunTests(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="testCases">The list of test cases for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="options">The test platform options.</param>
Expand All @@ -118,7 +116,7 @@ void RunTests(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="testRunEventsHandler">The run event handler.</param>
Expand All @@ -133,7 +131,7 @@ void RunTestsWithCustomTestHost(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="sources">The list of source assemblies for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="options">The test platform options.</param>
Expand All @@ -150,7 +148,7 @@ void RunTestsWithCustomTestHost(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="testCases">The list of test cases for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="testRunEventsHandler">The run event handler.</param>
Expand All @@ -165,7 +163,7 @@ void RunTestsWithCustomTestHost(
/// <summary>
/// Starts a test run.
/// </summary>
///
///
/// <param name="testCases">The list of test cases for the test run.</param>
/// <param name="runSettings">The run settings for the run.</param>
/// <param name="options">The test platform options.</param>
Expand All @@ -182,17 +180,17 @@ void RunTestsWithCustomTestHost(
/// <summary>
/// Stops the test session.
/// </summary>
///
///
/// <returns>True if the session was successfuly stopped, false otherwise.</returns>
[Obsolete("This API is not final yet and is subject to changes.", false)]
bool StopTestSession();

/// <summary>
/// Stops the test session.
/// </summary>
///
///
/// <param name="eventsHandler">The session event handler.</param>
///
///
/// <returns>True if the session was successfuly stopped, false otherwise.</returns>
[Obsolete("This API is not final yet and is subject to changes.", false)]
bool StopTestSession(ITestSessionEventsHandler eventsHandler);
Expand All @@ -203,7 +201,7 @@ void RunTestsWithCustomTestHost(
///
/// <param name="options">Test Platform options.</param>
/// <param name="eventsHandler">The session event handler.</param>
///
///
/// <returns>True if the session was successfuly stopped, false otherwise.</returns>
[Obsolete("This API is not final yet and is subject to changes.", false)]
bool StopTestSession(TestPlatformOptions options, ITestSessionEventsHandler eventsHandler);
Expand Down
Loading

0 comments on commit 59bf13d

Please sign in to comment.