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 nullables on CrossPlatEngine #3779

Merged
merged 6 commits into from
Jun 20, 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 @@ -9,6 +9,6 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting;

internal interface ITestRuntimeProviderManager
{
ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration, List<string> sources);
ITestRuntimeProvider GetTestHostManagerByUri(string hostUri);
ITestRuntimeProvider? GetTestHostManagerByRunConfiguration(string? runConfiguration, List<string> sources);
ITestRuntimeProvider? GetTestHostManagerByUri(string hostUri);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.Common.Hosting;

/// <summary>
/// Responsible for managing TestRuntimeProviderManager extensions
/// </summary>
public class TestRuntimeProviderManager : ITestRuntimeProviderManager
{
private static TestRuntimeProviderManager s_testHostManager;
private static TestRuntimeProviderManager? s_testHostManager;

private readonly TestRuntimeExtensionManager _testHostExtensionManager;

Expand All @@ -39,20 +37,20 @@ protected TestRuntimeProviderManager(IMessageLogger sessionLogger)
public static TestRuntimeProviderManager Instance
=> s_testHostManager ??= new TestRuntimeProviderManager(TestSessionMessageLogger.Instance);

public ITestRuntimeProvider GetTestHostManagerByUri(string hostUri)
public ITestRuntimeProvider? GetTestHostManagerByUri(string hostUri)
{
var host = _testHostExtensionManager.TryGetTestExtension(hostUri);
return host?.Value;
}

public virtual ITestRuntimeProvider GetTestHostManagerByRunConfiguration(string runConfiguration, List<string> _)
public virtual ITestRuntimeProvider? GetTestHostManagerByRunConfiguration(string? runConfiguration, List<string>? _)
{
foreach (var testExtension in _testHostExtensionManager.TestExtensions)
{
if (testExtension.Value.CanExecuteCurrentRunConfiguration(runConfiguration))
{
// we are creating a new Instance of ITestRuntimeProvider so that each POM gets it's own object of ITestRuntimeProvider
return (ITestRuntimeProvider)Activator.CreateInstance(testExtension.Value.GetType());
return (ITestRuntimeProvider?)Activator.CreateInstance(testExtension.Value.GetType());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void SendTestHostLaunched(TestHostLaunchedPayload testHostLaunchedPayload
}

/// <inheritdoc/>
public BeforeTestRunStartResult? SendBeforeTestRunStartAndGetResult(string settingsXml, IEnumerable<string> sources, bool isTelemetryOptedIn, ITestMessageEventHandler? runEventsHandler)
public BeforeTestRunStartResult? SendBeforeTestRunStartAndGetResult(string? settingsXml, IEnumerable<string> sources, bool isTelemetryOptedIn, ITestMessageEventHandler? runEventsHandler)
{
var isDataCollectionStarted = false;
BeforeTestRunStartResult? result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public TestDiscoveryEventHandler(ITestRequestHandler requestHandler)
/// Handles discovered tests
/// </summary>
/// <param name="discoveredTestCases">List of test cases</param>
public void HandleDiscoveredTests(IEnumerable<TestCase>? discoveredTestCases)
public void HandleDiscoveredTests(IEnumerable<TestCase> discoveredTestCases)
{
EqtTrace.Info("Test Cases found ");
_requestHandler.SendTestCases(discoveredTestCases);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TestRunEventsHandler(ITestRequestHandler requestHandler)
/// Handle test run stats change.
/// </summary>
/// <param name="testRunChangedArgs"> The test run changed args. </param>
public void HandleTestRunStatsChange(TestRunChangedEventArgs? testRunChangedArgs)
public void HandleTestRunStatsChange(TestRunChangedEventArgs testRunChangedArgs)
{
EqtTrace.Info("Sending test run statistics");
_requestHandler.SendTestRunStatistics(testRunChangedArgs);
Expand All @@ -45,7 +45,7 @@ public void HandleTestRunStatsChange(TestRunChangedEventArgs? testRunChangedArgs
/// <param name="lastChunkArgs"> The last chunk args. </param>
/// <param name="runContextAttachments"> The run context attachments. </param>
/// <param name="executorUris"> The executor uris. </param>
public void HandleTestRunComplete(TestRunCompleteEventArgs? testRunCompleteArgs, TestRunChangedEventArgs? lastChunkArgs, ICollection<AttachmentSet>? runContextAttachments, ICollection<string>? executorUris)
public void HandleTestRunComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris)
{
EqtTrace.Info("Sending test run complete");
_requestHandler.SendExecutionComplete(testRunCompleteArgs, lastChunkArgs, runContextAttachments, executorUris);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces;

Expand Down Expand Up @@ -42,6 +43,8 @@ public ConnectedEventArgs(Exception? faultException)
/// <summary>
/// Gets a value indicating whether channel is connected or not, true if it's connected.
/// </summary>
[MemberNotNullWhen(true, nameof(Channel))]
[MemberNotNullWhen(false, nameof(Fault))]
public bool Connected { get; private set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal interface IDataCollectionRequestSender
/// <returns>
/// BeforeTestRunStartResult containing environment variables
/// </returns>
BeforeTestRunStartResult? SendBeforeTestRunStartAndGetResult(string settingXml, IEnumerable<string> sources, bool isTelemetryOptedIn, ITestMessageEventHandler? runEventsHandler);
BeforeTestRunStartResult? SendBeforeTestRunStartAndGetResult(string? settingXml, IEnumerable<string> sources, bool isTelemetryOptedIn, ITestMessageEventHandler? runEventsHandler);

/// <summary>
/// Sends the AfterTestRunEnd event and waits for result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface IDataSerializer
/// <typeparam name="T"> The type of object to deserialize to. </typeparam>
/// <param name="message"> Message object </param>
/// <returns> TestPlatform object </returns>
T? DeserializePayload<T>(Message message);
T? DeserializePayload<T>(Message? message);

/// <summary>
/// Serializes and creates a raw message given a message type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public interface ITestRequestHandler : IDisposable
/// The send test cases.
/// </summary>
/// <param name="discoveredTestCases"> The discovered test cases. </param>
void SendTestCases(IEnumerable<TestCase>? discoveredTestCases);
void SendTestCases(IEnumerable<TestCase> discoveredTestCases);

/// <summary>
/// The send test run statistics.
/// </summary>
/// <param name="testRunChangedArgs"> The test run changed args. </param>
void SendTestRunStatistics(TestRunChangedEventArgs? testRunChangedArgs);
void SendTestRunStatistics(TestRunChangedEventArgs testRunChangedArgs);

/// <summary>
/// Sends the logs back to the server.
Expand All @@ -71,7 +71,7 @@ public interface ITestRequestHandler : IDisposable
/// <param name="lastChunkArgs"> The last chunk args. </param>
/// <param name="runContextAttachments"> The run context attachments. </param>
/// <param name="executorUris"> The executor uris. </param>
void SendExecutionComplete(TestRunCompleteEventArgs? testRunCompleteArgs, TestRunChangedEventArgs? lastChunkArgs, ICollection<AttachmentSet>? runContextAttachments, ICollection<string>? executorUris);
void SendExecutionComplete(TestRunCompleteEventArgs testRunCompleteArgs, TestRunChangedEventArgs lastChunkArgs, ICollection<AttachmentSet> runContextAttachments, ICollection<string> executorUris);

/// <summary>
/// The discovery complete handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ public Message DeserializeMessage(string rawMessage)
/// <param name="message">A <see cref="Message"/> object.</param>
/// <typeparam name="T">Payload type.</typeparam>
/// <returns>The deserialized payload.</returns>
public T? DeserializePayload<T>(Message message)
public T? DeserializePayload<T>(Message? message)
{
if (message is null)
{
return default;
}

if (message.GetType() == typeof(Message))
{
// Message is specifically a Message, and not any of it's child types like VersionedMessage.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class TestRunCriteriaWithSources
/// <param name="runSettings"> The run settings. </param>
/// <param name="testExecutionContext"> The test Execution Context. </param>
[JsonConstructor]
public TestRunCriteriaWithSources(Dictionary<string, IEnumerable<string>> adapterSourceMap, string package, string? runSettings, TestExecutionContext? testExecutionContext)
public TestRunCriteriaWithSources(Dictionary<string, IEnumerable<string>> adapterSourceMap, string? package, string? runSettings, TestExecutionContext? testExecutionContext)
{
AdapterSourceMap = adapterSourceMap;
Package = package;
Expand All @@ -50,5 +50,5 @@ public TestRunCriteriaWithSources(Dictionary<string, IEnumerable<string>> adapte
/// <summary>
/// Gets the test Containers (e.g. .appx, .appxrecipie)
/// </summary>
public string Package { get; private set; }
public string? Package { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TestRunCriteriaWithTests
/// <param name="runSettings"> The test run settings. </param>
/// <param name="testExecutionContext"> The test Execution Context. </param>
[JsonConstructor]
public TestRunCriteriaWithTests(IEnumerable<TestCase> tests, string package, string? runSettings, TestExecutionContext? testExecutionContext)
public TestRunCriteriaWithTests(IEnumerable<TestCase> tests, string? package, string? runSettings, TestExecutionContext? testExecutionContext)
{
Tests = tests;
Package = package;
Expand All @@ -52,5 +52,5 @@ public TestRunCriteriaWithTests(IEnumerable<TestCase> tests, string package, str
/// <summary>
/// Gets the test Containers (e.g. .appx, .appxrecipie)
/// </summary>
public string Package { get; private set; }
public string? Package { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

using CrossPlatEngineResources = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Resources.Resources;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter;

/// <summary>
Expand Down Expand Up @@ -47,7 +45,7 @@ internal class FrameworkHandle : TestExecutionRecorder, IFrameworkHandle2, IDisp
/// <param name="testRunCache"> The test run cache. </param>
/// <param name="testExecutionContext"> The test execution context. </param>
/// <param name="testRunEventsHandler">TestRun Events Handler</param>
public FrameworkHandle(ITestCaseEventsHandler testCaseEventsHandler, ITestRunCache testRunCache,
public FrameworkHandle(ITestCaseEventsHandler? testCaseEventsHandler, ITestRunCache testRunCache,
TestExecutionContext testExecutionContext, IInternalTestRunEventsHandler testRunEventsHandler)
: base(testCaseEventsHandler, testRunCache)
{
Expand All @@ -71,7 +69,7 @@ public FrameworkHandle(ITestCaseEventsHandler testCaseEventsHandler, ITestRunCac
/// <param name="arguments">Command line arguments the process should be launched with.</param>
/// <param name="environmentVariables">Environment variables to be set in target process</param>
/// <returns>Process ID of the started process.</returns>
public int LaunchProcessWithDebuggerAttached(string filePath, string workingDirectory, string arguments, IDictionary<string, string> environmentVariables)
public int LaunchProcessWithDebuggerAttached(string filePath, string? workingDirectory, string? arguments, IDictionary<string, string>? environmentVariables)
{
// If an adapter attempts to launch a process after the run is complete (=> this object is disposed)
// throw an error.
Expand All @@ -86,7 +84,7 @@ public int LaunchProcessWithDebuggerAttached(string filePath, string workingDire
throw new InvalidOperationException(CrossPlatEngineResources.LaunchDebugProcessNotAllowedForANonDebugRun);
}

var processInfo = new TestProcessStartInfo()
var processInfo = new TestProcessStartInfo
{
Arguments = arguments,
EnvironmentVariables = environmentVariables,
Expand Down
11 changes: 4 additions & 7 deletions src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/RunContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Discovery;

using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter;

/// <summary>
/// Provides user specified runSettings and framework provided context of the run.
/// Provides user specified runSettings and framework provided context of the run.
/// </summary>
public class RunContext : DiscoveryContext, IRunContext
{
Expand All @@ -30,17 +27,17 @@ public class RunContext : DiscoveryContext, IRunContext
public bool IsDataCollectionEnabled { get; internal set; }

/// <summary>
/// Gets a value indicating whether the test is being debugged.
/// Gets a value indicating whether the test is being debugged.
/// </summary>
public bool IsBeingDebugged { get; internal set; }

/// <summary>
/// Gets the directory which should be used for storing result files/deployment files etc.
/// </summary>
public string TestRunDirectory { get; internal set; }
public string? TestRunDirectory { get; internal set; }

/// <summary>
/// Gets the directory for Solution.
/// </summary>
public string SolutionDirectory { get; internal set; }
public string? SolutionDirectory { get; internal set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine;

#nullable disable

namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Adapter;

/// <summary>
Expand All @@ -22,7 +20,7 @@ internal class TestExecutionRecorder : TestSessionMessageLogger, ITestExecutionR
{
private readonly List<AttachmentSet> _attachmentSets;
private readonly ITestRunCache _testRunCache;
private readonly ITestCaseEventsHandler _testCaseEventsHandler;
private readonly ITestCaseEventsHandler? _testCaseEventsHandler;

/// <summary>
/// Contains TestCase Ids for test cases that are in progress
Expand All @@ -37,7 +35,7 @@ internal class TestExecutionRecorder : TestSessionMessageLogger, ITestExecutionR
/// </summary>
/// <param name="testCaseEventsHandler"> The test Case Events Handler. </param>
/// <param name="testRunCache"> The test run cache. </param>
public TestExecutionRecorder(ITestCaseEventsHandler testCaseEventsHandler, ITestRunCache testRunCache)
public TestExecutionRecorder(ITestCaseEventsHandler? testCaseEventsHandler, ITestRunCache testRunCache)
{
_testRunCache = testRunCache;
_testCaseEventsHandler = testCaseEventsHandler;
Expand Down Expand Up @@ -70,7 +68,7 @@ internal Collection<AttachmentSet> Attachments
/// <param name="testCase">test case which will be started.</param>
public void RecordStart(TestCase testCase)
{
EqtTrace.Verbose("TestExecutionRecorder.RecordStart: Starting test: {0}.", testCase?.FullyQualifiedName);
EqtTrace.Verbose("TestExecutionRecorder.RecordStart: Starting test: {0}.", testCase.FullyQualifiedName);
_testRunCache.OnTestStarted(testCase);

if (_testCaseEventsHandler != null)
Expand All @@ -95,7 +93,7 @@ public void RecordStart(TestCase testCase)
/// test result to the framework when the test(s) is canceled. </exception>
public void RecordResult(TestResult testResult)
{
EqtTrace.Verbose("TestExecutionRecorder.RecordResult: Received result for test: {0}.", testResult?.TestCase?.FullyQualifiedName);
EqtTrace.Verbose("TestExecutionRecorder.RecordResult: Received result for test: {0}.", testResult.TestCase.FullyQualifiedName);
if (_testCaseEventsHandler != null)
{
// Send TestCaseEnd in case RecordEnd was not called.
Expand All @@ -109,13 +107,13 @@ public void RecordResult(TestResult testResult)

/// <summary>
/// Notify the framework about completion of the test case.
/// Framework sends this event to data collectors enabled in the run. If no data collector is enabled, then the event is ignored.
/// Framework sends this event to data collectors enabled in the run. If no data collector is enabled, then the event is ignored.
/// </summary>
/// <param name="testCase">test case which has completed.</param>
/// <param name="outcome">outcome of the test case.</param>
public void RecordEnd(TestCase testCase, TestOutcome outcome)
{
EqtTrace.Verbose("TestExecutionRecorder.RecordEnd: test: {0} execution completed.", testCase?.FullyQualifiedName);
EqtTrace.Verbose("TestExecutionRecorder.RecordEnd: test: {0} execution completed.", testCase.FullyQualifiedName);
_testRunCache.OnTestCompletion(testCase);
SendTestCaseEnd(testCase, outcome);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class DataCollectorAttachmentProcessorAppDomain : IDataCollectorAttachm
private IMessageLogger? _processAttachmentSetsLogger;
private IProgress<int>? _progressReporter;

public DataCollectorAttachmentProcessorAppDomain(InvokedDataCollector invokedDataCollector, IMessageLogger dataCollectorAttachmentsProcessorsLogger)
public DataCollectorAttachmentProcessorAppDomain(InvokedDataCollector invokedDataCollector, IMessageLogger? dataCollectorAttachmentsProcessorsLogger)
{
_invokedDataCollector = invokedDataCollector ?? throw new ArgumentNullException(nameof(invokedDataCollector));
_appDomain = AppDomain.CreateDomain(invokedDataCollector.Uri.ToString());
Expand Down
Loading