Skip to content
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
6 changes: 4 additions & 2 deletions src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using NUnit.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[assembly: Parallelizable(ParallelScope.All)]
using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope;

[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- Arcade uses by default xunit as test runner, illink uses nunit instead. -->
<TestRunnerName>NUnit</TestRunnerName>
<TestRunnerName>MSTest</TestRunnerName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;
using Mono.Linker.Tests.Cases.CommandLine.Mvid;
using Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual;
Expand All @@ -16,16 +17,15 @@
using Mono.Linker.Tests.Cases.Warnings.Individual;
using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCasesRunner;
using NUnit.Framework;

namespace Mono.Linker.Tests.TestCases
{
[TestFixture]
[TestClass]
public class IndividualTests
{
private static NPath TestsDirectory => TestDatabase.TestCasesRootDirectory.Parent.Combine("Mono.Linker.Tests");

[Test]
[TestMethod]
public void CanSkipUnresolved()
Comment thread
Youssef1313 marked this conversation as resolved.
{
var testcase = CreateIndividualCase(typeof(CanSkipUnresolved));
Expand All @@ -38,7 +38,7 @@ public void CanSkipUnresolved()
Assert.Fail($"The linked assembly is missing. Should have existed at {result.OutputAssemblyPath}");
}

[Test]
[TestMethod]
public void CanOutputPInvokes()
{
var testcase = CreateIndividualCase(typeof(CanOutputPInvokes));
Comment thread
Youssef1313 marked this conversation as resolved.
Expand All @@ -57,12 +57,12 @@ public void CanOutputPInvokes()
var expected = jsonSerializer.ReadObject(fsExpected) as List<PInvokeInfo>;
foreach (var pinvokePair in Enumerable.Zip(actual, expected, (fst, snd) => Tuple.Create(fst, snd)))
{
Assert.That(pinvokePair.Item1.CompareTo(pinvokePair.Item2), Is.EqualTo(0));
Assert.AreEqual(0, pinvokePair.Item1.CompareTo(pinvokePair.Item2));
}
}
}

[Test]
[TestMethod]
public void CanGenerateWarningSuppressionFileCSharp()
{
var testcase = CreateIndividualCase(typeof(CanGenerateWarningSuppressionFileCSharp));
Expand All @@ -75,12 +75,13 @@ public void CanGenerateWarningSuppressionFileCSharp()
if (!outputPath.Exists())
Assert.Fail($"A cs file with a list of UnconditionalSuppressMessage attributes was expected to exist at {outputPath}");

Assert.That(File.ReadAllLines(outputPath), Is.EquivalentTo(
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations{i + 1}.cs"))));
CollectionAssert.AreEquivalent(
File.ReadAllLines(outputPath),
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations{i + 1}.cs")));
}
}

[Test]
[TestMethod]
public void CanGenerateWarningSuppressionFileXml()
{
var testcase = CreateIndividualCase(typeof(CanGenerateWarningSuppressionFileXml));
Expand All @@ -89,11 +90,12 @@ public void CanGenerateWarningSuppressionFileXml()
if (!outputPath.Exists())
Assert.Fail($"An XML file with a list of UnconditionalSuppressMessage attributes was expected to exist at {outputPath}");

Assert.That(File.ReadAllLines(outputPath), Is.EquivalentTo(
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml"))));
CollectionAssert.AreEquivalent(
File.ReadAllLines(outputPath),
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml")));
}

[Test]
[TestMethod]
public void WarningsAreSorted()
{
var testcase = CreateIndividualCase(typeof(WarningsAreSorted));
Expand All @@ -102,11 +104,12 @@ public void WarningsAreSorted()
.Where(lm => lm.Category != MessageCategory.Info && lm.Category != MessageCategory.Diagnostic).ToList();
loggedMessages.Sort();

Assert.That(loggedMessages.Select(m => m.ToString()), Is.EquivalentTo(
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt"))));
CollectionAssert.AreEquivalent(
loggedMessages.Select(m => m.ToString()).ToArray(),
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt")));
}

[Test]
[TestMethod]
public void InvalidWarningCodeThrows()
{
var testcase = CreateIndividualCase(typeof(CustomStepWithWarnings));
Expand All @@ -121,7 +124,7 @@ public void InvalidWarningCodeThrows()
}
}

[Test]
[TestMethod]
public void CanEnableDependenciesDump()
{
var testcase = CreateIndividualCase(typeof(CanEnableDependenciesDump));
Expand All @@ -132,7 +135,7 @@ public void CanEnableDependenciesDump()
Assert.Fail($"The dependency dump file is missing. Expected it to exist at {outputPath}");
}

[Test]
[TestMethod]
public void CanDumpDependenciesToUncompressedXml()
{
var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedXml));
Expand All @@ -148,11 +151,11 @@ public void CanDumpDependenciesToUncompressedXml()
reader.Read();
reader.Read();
reader.Read();
Assert.That(reader.Name, Is.EqualTo("dependencies"), $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`");
Assert.AreEqual("dependencies", reader.Name, $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`");
}
}

[Test]
[TestMethod]
public void CandumpDependenciesToUncompressedDgml()
{
var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedDgml));
Expand All @@ -167,11 +170,11 @@ public void CandumpDependenciesToUncompressedDgml()
reader.Read();
reader.Read();
reader.Read();
Assert.That(reader.Name, Is.EqualTo("DirectedGraph"), $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`");
Assert.AreEqual("DirectedGraph", reader.Name, $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`");
}
}

[Test]
[TestMethod]
public void CanEnableReducedTracing()
{
var testcase = CreateIndividualCase(typeof(CanEnableReducedTracing));
Expand All @@ -192,10 +195,10 @@ public void CanEnableReducedTracing()
// With reduced tracing there should be less than 65, but to be safe, we'll check for less than 200.
// Reduced tracing on System.Private.CoreLib.dll produces about 130 lines just for NullableAttribute usages.
const int expectedMaxLines = 200;
Assert.That(lineCount, Is.LessThan(expectedMaxLines), $"There were `{lineCount}` lines in the dump file. This is more than expected max of {expectedMaxLines} and likely indicates reduced tracing was not enabled. Dump file can be found at: {outputPath}");
Assert.IsLessThan(expectedMaxLines, lineCount, $"There were `{lineCount}` lines in the dump file. This is more than expected max of {expectedMaxLines} and likely indicates reduced tracing was not enabled. Dump file can be found at: {outputPath}");
Comment thread
Youssef1313 marked this conversation as resolved.
}

[Test]
[TestMethod]
public void DeterministicMvidWorks()
{
var testCase = CreateIndividualCase(typeof(DeterministicMvidWorks));
Expand All @@ -204,17 +207,17 @@ public void DeterministicMvidWorks()

var originalMvid = GetMvid(result.InputAssemblyPath);
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid));
Assert.AreNotEqual(firstOutputMvid, originalMvid);

var result2 = runner.Relink(result);

var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid));
Assert.AreNotEqual(secondOutputMvid, originalMvid);
// The id should match the first output since we relinked the same assembly
Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid));
Assert.AreEqual(secondOutputMvid, firstOutputMvid);
Comment thread
Youssef1313 marked this conversation as resolved.
}

[Test]
[TestMethod]
public void NewMvidWorks()
{
var testCase = CreateIndividualCase(typeof(NewMvidWorks));
Expand All @@ -223,16 +226,16 @@ public void NewMvidWorks()

var originalMvid = GetMvid(result.InputAssemblyPath);
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid));
Assert.AreNotEqual(firstOutputMvid, originalMvid);

var result2 = runner.Relink(result);

var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid));
Assert.That(secondOutputMvid, Is.Not.EqualTo(firstOutputMvid));
Assert.AreNotEqual(secondOutputMvid, originalMvid);
Assert.AreNotEqual(secondOutputMvid, firstOutputMvid);
}

[Test]
[TestMethod]
public void RetainMvidWorks()
{
var testCase = CreateIndividualCase(typeof(RetainMvid));
Expand All @@ -241,13 +244,13 @@ public void RetainMvidWorks()

var originalMvid = GetMvid(result.InputAssemblyPath);
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
Assert.That(firstOutputMvid, Is.EqualTo(originalMvid));
Assert.AreEqual(firstOutputMvid, originalMvid);

var result2 = runner.Relink(result);

var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
Assert.That(secondOutputMvid, Is.EqualTo(originalMvid));
Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid));
Assert.AreEqual(secondOutputMvid, originalMvid);
Assert.AreEqual(secondOutputMvid, firstOutputMvid);
}

protected static Guid GetMvid(NPath assemblyPath)
Expand Down
Loading
Loading