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 acceptance tests #3757

Merged
merged 1 commit into from
Jun 15, 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 @@ -7,8 +7,6 @@

using Microsoft.TestPlatform.TestUtilities;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

public class AcceptanceTestBase : IntegrationTestBase
Expand Down Expand Up @@ -76,10 +74,10 @@ protected static void SetTestEnvironment(IntegrationTestEnvironment testEnvironm
{
testEnvironment.VSTestConsoleInfo = runnerInfo.VSTestConsoleInfo;
// The order here matters, it changes how the resulting path is built when we resolve test dlls and other assets.
testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).ToList();
testEnvironment.DllInfos = new[] { runnerInfo.AdapterInfo, runnerInfo.TestHostInfo }.Where(d => d != null).Select(x => x!).ToList();
testEnvironment.DebugInfo = runnerInfo.DebugInfo;

testEnvironment.RunnerFramework = runnerInfo.RunnerFramework;
testEnvironment.RunnerFramework = runnerInfo.RunnerFramework!;
testEnvironment.TargetFramework = runnerInfo.TargetFramework;
testEnvironment.InIsolationValue = runnerInfo.InIsolationValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
using System.IO;
#if !NETFRAMEWORK
using System.Runtime.Loader;

#else
using System.Reflection;

#endif
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down Expand Up @@ -46,7 +42,7 @@ public void RunTestExecutionWithDisableAppDomain(RunnerInfo runnerInfo)
TempDirectory.Path);

// Sets the environment variables used by the test project and test data collector.
var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["TEST_ASSET_APPDOMAIN_TEST_PATH"] = testAppDomainDetailFileName,
["TEST_ASSET_APPDOMAIN_COLLECTOR_PATH"] = dataCollectorAppDomainDetailFileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down Expand Up @@ -70,7 +68,7 @@ public void BlameDataCollectorShouldOutputDumpFile(RunnerInfo runnerInfo)
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, " /testcasefilter:ExitWithStackoverFlow");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath,
};
Expand All @@ -95,7 +93,7 @@ public void BlameDataCollectorShouldNotOutputDumpFileWhenNoCrashOccurs(RunnerInf
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, " /testcasefilter:PassingTest");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand All @@ -120,7 +118,7 @@ public void BlameDataCollectorShouldOutputDumpFileWhenNoCrashOccursButCollectAlw
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, " /testcasefilter:PassingTest");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand All @@ -142,7 +140,7 @@ public void HangDumpOnTimeout(RunnerInfo runnerInfo)
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, $@" /Blame:""CollectHangDump;HangDumpType=full;TestTimeout=3s""");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand All @@ -166,7 +164,7 @@ public void CrashDumpWhenThereIsNoTimeout(RunnerInfo runnerInfo)
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full;CollectAlways=true;CollectHangDump""");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand All @@ -190,7 +188,7 @@ public void CrashDumpOnExit(RunnerInfo runnerInfo)
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full;CollectAlways=true""");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand All @@ -212,7 +210,7 @@ public void CrashDumpOnStackOverflow(RunnerInfo runnerInfo)
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, $@" /Blame:""CollectDump;DumpType=full""");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["PROCDUMP_PATH"] = _procDumpPath
};
Expand Down
2 changes: 0 additions & 2 deletions test/Microsoft.TestPlatform.AcceptanceTests/CUITTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

public class CodeCoverageAcceptanceTestBase : AcceptanceTestBase
Expand All @@ -37,7 +35,7 @@ protected string GetCodeCoverageExePath()
return Path.Combine(GetNetStandardAdapterPath(), "CodeCoverage", "CodeCoverage.exe");
}

protected XmlNode GetModuleNode(XmlNode node, string name)
protected XmlNode? GetModuleNode(XmlNode node, string name)
{
var moduleNode = GetNode(node, "module", name);

Expand All @@ -54,7 +52,7 @@ protected XmlNode GetModuleNode(XmlNode node, string name)
return moduleNode;
}

protected XmlNode GetNode(XmlNode node, string type, string name)
protected XmlNode? GetNode(XmlNode node, string type, string name)
{
return node.SelectSingleNode($"//{type}[@name='{name}']") ?? node.SelectSingleNode($"//{type}[@name='{name.ToLower()}']");
}
Expand Down Expand Up @@ -84,7 +82,7 @@ protected XmlDocument GetXmlCoverage(string coverageResult, TempDirectory tempDi
UseShellExecute = false
});

string analysisOutput = analyze.StandardOutput.ReadToEnd();
string analysisOutput = analyze!.StandardOutput.ReadToEnd();

analyze.WaitForExit();
watch.Stop();
Expand All @@ -98,11 +96,11 @@ protected XmlDocument GetXmlCoverage(string coverageResult, TempDirectory tempDi

protected void AssertCoverage(XmlNode node, double expectedCoverage)
{
var coverage = node.Attributes["block_coverage"] != null
? double.Parse(node.Attributes["block_coverage"].Value)
: double.Parse(node.Attributes["line-rate"].Value) * 100;
Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Result: {coverage}");
Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes["name"].Value}. Expected at least: {expectedCoverage}. Found: {coverage}");
var coverage = node.Attributes!["block_coverage"] != null
? double.Parse(node.Attributes!["block_coverage"]!.Value)
: double.Parse(node.Attributes!["line-rate"]!.Value) * 100;
Console.WriteLine($"Checking coverage for {node.Name} {node.Attributes!["name"]!.Value}. Expected at least: {expectedCoverage}. Result: {coverage}");
Assert.IsTrue(coverage > expectedCoverage, $"Coverage check failed for {node.Name} {node.Attributes!["name"]!.Value}. Expected at least: {expectedCoverage}. Found: {coverage}");
}

protected static string GetCoverageFileNameFromTrx(string trxFilePath, string resultsDirectory)
Expand All @@ -114,18 +112,18 @@ protected static string GetCoverageFileNameFromTrx(string trxFilePath, string re
var deploymentElements = doc.GetElementsByTagName("Deployment");
Assert.IsTrue(deploymentElements.Count == 1,
"None or more than one Deployment tags found in trx file:{0}", trxFilePath);
var deploymentDir = deploymentElements[0].Attributes.GetNamedItem("runDeploymentRoot")?.Value;
var deploymentDir = deploymentElements[0]!.Attributes!.GetNamedItem("runDeploymentRoot")?.Value;
Assert.IsTrue(string.IsNullOrEmpty(deploymentDir) == false,
"runDeploymentRoot attribute not found in trx file:{0}", trxFilePath);
var collectors = doc.GetElementsByTagName("Collector");

string fileName = string.Empty;
string? fileName = string.Empty;
for (int i = 0; i < collectors.Count; i++)
{
if (string.Equals(collectors[i].Attributes.GetNamedItem("collectorDisplayName").Value,
if (string.Equals(collectors[i]!.Attributes!.GetNamedItem("collectorDisplayName")!.Value,
"Code Coverage", StringComparison.OrdinalIgnoreCase))
{
fileName = collectors[i].FirstChild?.FirstChild?.FirstChild?.Attributes.GetNamedItem("href")
fileName = collectors[i]?.FirstChild?.FirstChild?.FirstChild?.Attributes?.GetNamedItem("href")
?.Value;
}
}
Expand Down
18 changes: 8 additions & 10 deletions test/Microsoft.TestPlatform.AcceptanceTests/CodeCoverageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

internal struct TestParameters
Expand Down Expand Up @@ -305,31 +303,31 @@ private string CreateArguments(

private void AssertSkippedMethod(XmlDocument document)
{
var module = GetModuleNode(document.DocumentElement, "codecoveragetest.dll");
var module = GetModuleNode(document.DocumentElement!, "codecoveragetest.dll");
Assert.IsNotNull(module);

var coverage = double.Parse(module.Attributes["block_coverage"].Value);
var coverage = double.Parse(module.Attributes!["block_coverage"]!.Value);
Assert.IsTrue(coverage > ExpectedMinimalModuleCoverage);

var testSignFunction = GetNode(module, "skipped_function", "TestSign()");
Assert.IsNotNull(testSignFunction);
Assert.AreEqual("name_excluded", testSignFunction.Attributes["reason"].Value);
Assert.AreEqual("name_excluded", testSignFunction.Attributes!["reason"]!.Value);

var skippedTestMethod = GetNode(module, "skipped_function", "__CxxPureMSILEntry_Test()");
Assert.IsNotNull(skippedTestMethod);
Assert.AreEqual("name_excluded", skippedTestMethod.Attributes["reason"].Value);
Assert.AreEqual("name_excluded", skippedTestMethod.Attributes!["reason"]!.Value);

var testAbsFunction = GetNode(module, "function", "TestAbs()");
Assert.IsNotNull(testAbsFunction);
}

private void ValidateCoverageData(XmlDocument document, string moduleName, bool validateSourceFileNames)
{
var module = GetModuleNode(document.DocumentElement, moduleName.ToLower());
var module = GetModuleNode(document.DocumentElement!, moduleName.ToLower());

if (module == null)
{
module = GetModuleNode(document.DocumentElement, moduleName);
module = GetModuleNode(document.DocumentElement!, moduleName);
}
Assert.IsNotNull(module);

Expand All @@ -348,9 +346,9 @@ private void AssertSourceFileName(XmlNode module)

var found = false;
var sourcesNode = module.SelectSingleNode("./source_files");
foreach (XmlNode node in sourcesNode.ChildNodes)
foreach (XmlNode node in sourcesNode!.ChildNodes)
{
if (node.Attributes["path"].Value.Contains(expectedFileName))
if (node.Attributes!["path"]!.Value.Contains(expectedFileName))
{
found = true;
break;
Expand Down
18 changes: 8 additions & 10 deletions test/Microsoft.TestPlatform.AcceptanceTests/DataCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand All @@ -40,7 +38,7 @@ public void ExecuteTestsWithDataCollection(RunnerInfo runnerInfo)
var arguments = PrepareArguments(assemblyPaths, null, runSettings, FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path);
arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /TestAdapterPath:{extensionsPath}");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["TEST_ASSET_SAMPLE_COLLECTOR_PATH"] = TempDirectory.Path,
};
Expand Down Expand Up @@ -70,7 +68,7 @@ public void ExecuteTestsWithDataCollectionUsingCollectArgument(RunnerInfo runner
var arguments = PrepareArguments(assemblyPaths, null, null, FrameworkArgValue, runnerInfo.InIsolationValue, TempDirectory.Path);
arguments = string.Concat(arguments, $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector", $" /TestAdapterPath:{extensionsPath}");

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["TEST_ASSET_SAMPLE_COLLECTOR_PATH"] = TempDirectory.Path,
};
Expand Down Expand Up @@ -135,13 +133,13 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo)
runSettingsXml.Add(new XElement("RunConfiguration", new XElement("MaxCpuCount", 2)));

// Set datacollector parameters
runSettingsXml.Element("DataCollectionRunSettings")
.Element("DataCollectors")
.Element("DataCollector")
runSettingsXml.Element("DataCollectionRunSettings")!
.Element("DataCollectors")!
.Element("DataCollector")!
.Add(new XElement("Configuration", new XElement("MergeFile", "MergedFile.txt")));
runSettingsXml.Save(runSettings);

var env = new Dictionary<string, string>
var env = new Dictionary<string, string?>
{
["SampleDataCollectorTempPath"] = TempDirectory.Path,
};
Expand All @@ -156,8 +154,8 @@ public void DataCollectorAttachmentProcessor(RunnerInfo runnerInfo)
{
while (!streamReader.EndOfStream)
{
string line = streamReader.ReadLine();
Assert.IsTrue(line.StartsWith("SessionEnded_Handler_"));
string? line = streamReader.ReadLine();
Assert.IsTrue(line!.StartsWith("SessionEnded_Handler_"));
fileContent.Add(line);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
[TestCategory("Windows-Review")]
public class DeprecateExtensionsPathWarningTests : AcceptanceTestBase
{
private IList<string> _adapterDependencies;
private IList<string> _copiedFiles;
private readonly IList<string> _adapterDependencies;
private readonly IList<string> _copiedFiles;

[TestCleanup]
public void Cleanup()
Expand All @@ -36,11 +34,10 @@ public void Cleanup()
}
}

[TestInitialize]
public void CopyAdapterToExtensions()
public DeprecateExtensionsPathWarningTests()
{
_copiedFiles = new List<string>();
var extensionsDir = Path.Combine(Path.GetDirectoryName(GetConsoleRunnerPath()), "Extensions");
var extensionsDir = Path.Combine(Path.GetDirectoryName(GetConsoleRunnerPath())!, "Extensions");
_adapterDependencies = Directory.GetFiles(GetTestAdapterPath(), "*.dll", SearchOption.TopDirectoryOnly);

try
Expand Down Expand Up @@ -69,7 +66,7 @@ public void VerifyDeprecatedWarningIsThrownWhenAdaptersPickedFromExtensionDirect

public override string GetConsoleRunnerPath()
{
DirectoryInfo currentDirectory = new DirectoryInfo(typeof(DeprecateExtensionsPathWarningTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent.Parent.Parent.Parent.Parent.Parent;
DirectoryInfo currentDirectory = new DirectoryInfo(typeof(DeprecateExtensionsPathWarningTests).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent!.Parent!.Parent!.Parent!.Parent!.Parent!;

return Path.Combine(currentDirectory.FullName, "artifacts", BuildConfiguration, "net451", "win7-x64", "vstest.console.exe");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#nullable disable

namespace Microsoft.TestPlatform.AcceptanceTests;

[TestClass]
Expand Down
Loading