Skip to content

Commit

Permalink
Enable nullable on missed files (#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Jun 23, 2022
1 parent ebdb6ad commit 9567e6c
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 126 deletions.
14 changes: 6 additions & 8 deletions src/Microsoft.TestPlatform.Client/Execution/TestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,11 @@ public void HandleTestRunComplete(TestRunCompleteEventArgs runCompleteArgs, Test
}
finally
{
if (isCanceled)
{
State = TestRunState.Canceled;
}
else
{
State = isAborted ? TestRunState.Aborted : TestRunState.Completed;
}
State = isCanceled
? TestRunState.Canceled
: isAborted
? TestRunState.Aborted
: TestRunState.Completed;

// Notify the waiting handle that run is complete
_runCompletionEvent.Set();
Expand Down Expand Up @@ -655,6 +652,7 @@ public int LaunchProcessWithDebuggerAttached(TestProcessStartInfo testProcessSta
{
int processId = -1;

TPDebug.Assert(TestRunCriteria.TestHostLauncher is not null, "TestRunCriteria.TestHostLauncher is null");
// Only launch while the test run is in progress and the launcher is a debug one
if (State == TestRunState.InProgress && TestRunCriteria.TestHostLauncher.IsDebug)
{
Expand Down
14 changes: 10 additions & 4 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,15 @@ private static IEnumerable<string> ExpandAdaptersWithDefaultStrategy(string path
TestPlatformConstants.RunTimeEndsWithPattern);
}

private static IEnumerable<string> GetSources(TestRunCriteria testRunCriteria) =>
testRunCriteria.HasSpecificTests
private static IEnumerable<string> GetSources(TestRunCriteria testRunCriteria)
{
if (testRunCriteria.HasSpecificTests)
{
// If the test execution is with a test filter, filter sources too.
? testRunCriteria.Tests.Select(tc => tc.Source).Distinct()
: testRunCriteria.Sources;
return testRunCriteria.Tests.Select(tc => tc.Source).Distinct();
}

TPDebug.Assert(testRunCriteria.Sources is not null, "testRunCriteria.Sources is null");
return testRunCriteria.Sources;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public int StartTestRun(TestRunCriteria testRunCriteria, IInternalTestRunEventsH
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);
var testPackages = new List<string>(testRunCriteria.HasSpecificSources ? testRunCriteria.Sources :
// If the test execution is with a test filter, group them by sources
testRunCriteria.Tests.GroupBy(tc => tc.Source).Select(g => g.Key));
testRunCriteria.Tests!.GroupBy(tc => tc.Source).Select(g => g.Key));

// This code should be in sync with ProxyExecutionManager.StartTestRun executionContext
var executionContext = new TestExecutionContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public int StartTestRun(TestRunCriteria testRunCriteria, IInternalTestRunEventsH
_runCompletedClients = 0;

// One data aggregator per parallel run
TPDebug.Assert(testRunCriteria.TestRunSettings is not null, "testRunCriteria.TestRunSettings is null");
_currentRunDataAggregator = new ParallelRunDataAggregator(testRunCriteria.TestRunSettings);
if (nonRunnableWorkloads.Count > 0)
{
Expand Down Expand Up @@ -267,9 +268,9 @@ private List<ProviderSpecificWorkload<TestRunCriteria>> SplitToWorkloads(TestRun
}
else
{
var sources = testRunCriteria.Sources;
TPDebug.Assert(testRunCriteria.Sources is not null, "testRunCriteria.Sources is null");
// Each source is grouped with its respective provider.
var providerGroups = sources
var providerGroups = testRunCriteria.Sources
.Select(source => new ProviderSpecificWorkload<string>(source, sourceToTestHostProviderMap[source]))
.GroupBy(psw => psw.Provider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public virtual TestProcessStartInfo UpdateTestProcessStartInfo(TestProcessStartI
/// <param name="runsettingsXml">Run settings string.</param>
///
/// <returns>The run settings after removing non-required nodes.</returns>
public string? RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, Action<TestMessageLevel, string> logMessage)
public string? RemoveNodesFromRunsettingsIfRequired(string? runsettingsXml, Action<TestMessageLevel, string> logMessage)
{
var updatedRunSettingsXml = runsettingsXml;
if (!_makeRunsettingsCompatibleSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal static class TestRunCriteriaExtensions
{
public static TestRunCriteriaWithSources CreateTestRunCriteriaForSources(this TestRunCriteria testRunCriteria, ITestRuntimeProvider? testRuntimeProvider, string? runSettings, TestExecutionContext executionContext, IEnumerable<string>? inputPackages)
{
TPDebug.Assert(testRunCriteria.AdapterSourceMap is not null, "testRunCriteria.AdapterSourceMap is null");
if (TryCheckTestSourceDifferFromPackage(testRuntimeProvider, inputPackages, out IEnumerable<string>? actualTestSources))
{
UpdateTestSources(actualTestSources, testRunCriteria.AdapterSourceMap);
Expand All @@ -31,6 +32,7 @@ public static TestRunCriteriaWithSources CreateTestRunCriteriaForSources(this Te
public static TestRunCriteriaWithTests CreateTestRunCriteriaForTests(this TestRunCriteria testRunCriteria, ITestRuntimeProvider? testRuntimeProvider,
string? runSettings, TestExecutionContext executionContext, IEnumerable<string>? inputPackages)
{
TPDebug.Assert(testRunCriteria.Tests is not null, "testRunCriteria.Tests is null");
if (TryCheckTestSourceDifferFromPackage(testRuntimeProvider, inputPackages, out IEnumerable<string>? actualTestSources))
{
// In UWP scenario TestCase object contains the package as source, which is not actual test source for adapters,
Expand Down
8 changes: 5 additions & 3 deletions src/Microsoft.TestPlatform.CrossPlatEngine/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public IProxyExecutionManager GetExecutionManager(
IDictionary<string, SourceDetail> sourceToSourceDetailMap,
IWarningLogger warningLogger)
{
TPDebug.Assert(testRunCriteria.TestRunSettings is not null, "testRunCriteria.TestRunSettings is null");

// We use mulitple "different" runsettings here. We have runsettings that come with the testRunCriteria,
// and we use that to figure out the common stuff before we try to setup the run. Later we patch the settings
// from the additional details that were passed. Those should not affect the common properties that are used for setup.
Expand Down Expand Up @@ -492,11 +494,11 @@ private static int GetDistinctNumberOfSources(TestRunCriteria testRunCriteria)
{
// No point in creating more processes if number of sources is less than what the user
// configured for.
int numSources = testRunCriteria.HasSpecificTests
int numberOfSources = testRunCriteria.HasSpecificTests
? new HashSet<string>(
testRunCriteria.Tests.Select(testCase => testCase.Source)).Count
: testRunCriteria.Sources.Count();
return numSources;
return numberOfSources;
}

/// <summary>
Expand All @@ -509,7 +511,7 @@ private static int GetDistinctNumberOfSources(TestRunCriteria testRunCriteria)
/// <returns>The parallel level to use.</returns>
private int VerifyParallelSettingAndCalculateParallelLevel(
int sourceCount,
string runSettings)
string? runSettings)
{
// Default is 1.
int parallelLevelToUse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ private CollectorDataEntry ToCollectorEntry(AttachmentSet attachmentSet, Guid te
// (Trx viewer automatically adds In\ to the collected file.
string fileName = Path.Combine(Environment.MachineName, Path.GetFileName(targetFileName));
Uri sourceFileUri = new(fileName, UriKind.Relative);
TPDebug.Assert(uriDataAttachment.Description is not null, "uriDataAttachment.Description is null");
TrxObjectModel.UriDataAttachment dataAttachment = new(uriDataAttachment.Description, sourceFileUri, _trxFileHelper);

uriDataAttachments.Add(dataAttachment);
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public class UriDataAttachment
/// Description of the attachment.
/// </summary>
[DataMember]
public string Description { get; }
public string? Description { get; }

/// <summary>
/// Uri of the attachment.
/// </summary>
[DataMember]
public Uri Uri { get; }

public UriDataAttachment(Uri uri, string description)
public UriDataAttachment(Uri uri, string? description)
{
Uri = uri;
Description = description;
Expand All @@ -76,7 +76,7 @@ public override string ToString()
return $"{nameof(Uri)}: {Uri.AbsoluteUri}, {nameof(Description)}: {Description}";
}

public static UriDataAttachment CreateFrom(string localFilePath, string description)
public static UriDataAttachment CreateFrom(string localFilePath, string? description)
{
var uri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri;
return new UriDataAttachment(uri, description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ public interface ITestRunConfiguration
/// <summary>
/// The specific tests for this test run if any.
/// </summary>
IEnumerable<TestCase> Tests { get; }
IEnumerable<TestCase>? Tests { get; }
}
Loading

0 comments on commit 9567e6c

Please sign in to comment.