Skip to content

Commit 7e2ee62

Browse files
authored
Update Mono.Linker.Tests to MSTest (dotnet#126412)
Related to dotnet/arcade#16428
1 parent 93578ff commit 7e2ee62

23 files changed

Lines changed: 368 additions & 314 deletions
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using NUnit.Framework;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
55

6-
[assembly: Parallelizable(ParallelScope.All)]
6+
using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope;
7+
8+
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]

src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
<PropertyGroup>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
5-
<!-- Arcade uses by default xunit as test runner, illink uses nunit instead. -->
6-
<TestRunnerName>NUnit</TestRunnerName>
5+
<TestRunnerName>MSTest</TestRunnerName>
76
</PropertyGroup>
87

98
<ItemGroup>

src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using System.Runtime.Serialization.Json;
99
using System.Xml;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
1011
using Mono.Cecil;
1112
using Mono.Linker.Tests.Cases.CommandLine.Mvid;
1213
using Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual;
@@ -16,16 +17,15 @@
1617
using Mono.Linker.Tests.Cases.Warnings.Individual;
1718
using Mono.Linker.Tests.Extensions;
1819
using Mono.Linker.Tests.TestCasesRunner;
19-
using NUnit.Framework;
2020

2121
namespace Mono.Linker.Tests.TestCases
2222
{
23-
[TestFixture]
23+
[TestClass]
2424
public class IndividualTests
2525
{
2626
private static NPath TestsDirectory => TestDatabase.TestCasesRootDirectory.Parent.Combine("Mono.Linker.Tests");
2727

28-
[Test]
28+
[TestMethod]
2929
public void CanSkipUnresolved()
3030
{
3131
var testcase = CreateIndividualCase(typeof(CanSkipUnresolved));
@@ -38,7 +38,7 @@ public void CanSkipUnresolved()
3838
Assert.Fail($"The linked assembly is missing. Should have existed at {result.OutputAssemblyPath}");
3939
}
4040

41-
[Test]
41+
[TestMethod]
4242
public void CanOutputPInvokes()
4343
{
4444
var testcase = CreateIndividualCase(typeof(CanOutputPInvokes));
@@ -57,12 +57,12 @@ public void CanOutputPInvokes()
5757
var expected = jsonSerializer.ReadObject(fsExpected) as List<PInvokeInfo>;
5858
foreach (var pinvokePair in Enumerable.Zip(actual, expected, (fst, snd) => Tuple.Create(fst, snd)))
5959
{
60-
Assert.That(pinvokePair.Item1.CompareTo(pinvokePair.Item2), Is.EqualTo(0));
60+
Assert.AreEqual(0, pinvokePair.Item1.CompareTo(pinvokePair.Item2));
6161
}
6262
}
6363
}
6464

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

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

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

92-
Assert.That(File.ReadAllLines(outputPath), Is.EquivalentTo(
93-
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml"))));
93+
CollectionAssert.AreEquivalent(
94+
File.ReadAllLines(outputPath),
95+
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml")));
9496
}
9597

96-
[Test]
98+
[TestMethod]
9799
public void WarningsAreSorted()
98100
{
99101
var testcase = CreateIndividualCase(typeof(WarningsAreSorted));
@@ -102,11 +104,12 @@ public void WarningsAreSorted()
102104
.Where(lm => lm.Category != MessageCategory.Info && lm.Category != MessageCategory.Diagnostic).ToList();
103105
loggedMessages.Sort();
104106

105-
Assert.That(loggedMessages.Select(m => m.ToString()), Is.EquivalentTo(
106-
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt"))));
107+
CollectionAssert.AreEquivalent(
108+
loggedMessages.Select(m => m.ToString()).ToArray(),
109+
File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt")));
107110
}
108111

109-
[Test]
112+
[TestMethod]
110113
public void InvalidWarningCodeThrows()
111114
{
112115
var testcase = CreateIndividualCase(typeof(CustomStepWithWarnings));
@@ -121,7 +124,7 @@ public void InvalidWarningCodeThrows()
121124
}
122125
}
123126

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

135-
[Test]
138+
[TestMethod]
136139
public void CanDumpDependenciesToUncompressedXml()
137140
{
138141
var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedXml));
@@ -148,11 +151,11 @@ public void CanDumpDependenciesToUncompressedXml()
148151
reader.Read();
149152
reader.Read();
150153
reader.Read();
151-
Assert.That(reader.Name, Is.EqualTo("dependencies"), $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`");
154+
Assert.AreEqual("dependencies", reader.Name, $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`");
152155
}
153156
}
154157

155-
[Test]
158+
[TestMethod]
156159
public void CandumpDependenciesToUncompressedDgml()
157160
{
158161
var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedDgml));
@@ -167,11 +170,11 @@ public void CandumpDependenciesToUncompressedDgml()
167170
reader.Read();
168171
reader.Read();
169172
reader.Read();
170-
Assert.That(reader.Name, Is.EqualTo("DirectedGraph"), $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`");
173+
Assert.AreEqual("DirectedGraph", reader.Name, $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`");
171174
}
172175
}
173176

174-
[Test]
177+
[TestMethod]
175178
public void CanEnableReducedTracing()
176179
{
177180
var testcase = CreateIndividualCase(typeof(CanEnableReducedTracing));
@@ -192,10 +195,10 @@ public void CanEnableReducedTracing()
192195
// With reduced tracing there should be less than 65, but to be safe, we'll check for less than 200.
193196
// Reduced tracing on System.Private.CoreLib.dll produces about 130 lines just for NullableAttribute usages.
194197
const int expectedMaxLines = 200;
195-
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}");
198+
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}");
196199
}
197200

198-
[Test]
201+
[TestMethod]
199202
public void DeterministicMvidWorks()
200203
{
201204
var testCase = CreateIndividualCase(typeof(DeterministicMvidWorks));
@@ -204,17 +207,17 @@ public void DeterministicMvidWorks()
204207

205208
var originalMvid = GetMvid(result.InputAssemblyPath);
206209
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
207-
Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid));
210+
Assert.AreNotEqual(firstOutputMvid, originalMvid);
208211

209212
var result2 = runner.Relink(result);
210213

211214
var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
212-
Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid));
215+
Assert.AreNotEqual(secondOutputMvid, originalMvid);
213216
// The id should match the first output since we relinked the same assembly
214-
Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid));
217+
Assert.AreEqual(secondOutputMvid, firstOutputMvid);
215218
}
216219

217-
[Test]
220+
[TestMethod]
218221
public void NewMvidWorks()
219222
{
220223
var testCase = CreateIndividualCase(typeof(NewMvidWorks));
@@ -223,16 +226,16 @@ public void NewMvidWorks()
223226

224227
var originalMvid = GetMvid(result.InputAssemblyPath);
225228
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
226-
Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid));
229+
Assert.AreNotEqual(firstOutputMvid, originalMvid);
227230

228231
var result2 = runner.Relink(result);
229232

230233
var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
231-
Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid));
232-
Assert.That(secondOutputMvid, Is.Not.EqualTo(firstOutputMvid));
234+
Assert.AreNotEqual(secondOutputMvid, originalMvid);
235+
Assert.AreNotEqual(secondOutputMvid, firstOutputMvid);
233236
}
234237

235-
[Test]
238+
[TestMethod]
236239
public void RetainMvidWorks()
237240
{
238241
var testCase = CreateIndividualCase(typeof(RetainMvid));
@@ -241,13 +244,13 @@ public void RetainMvidWorks()
241244

242245
var originalMvid = GetMvid(result.InputAssemblyPath);
243246
var firstOutputMvid = GetMvid(result.OutputAssemblyPath);
244-
Assert.That(firstOutputMvid, Is.EqualTo(originalMvid));
247+
Assert.AreEqual(firstOutputMvid, originalMvid);
245248

246249
var result2 = runner.Relink(result);
247250

248251
var secondOutputMvid = GetMvid(result2.OutputAssemblyPath);
249-
Assert.That(secondOutputMvid, Is.EqualTo(originalMvid));
250-
Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid));
252+
Assert.AreEqual(secondOutputMvid, originalMvid);
253+
Assert.AreEqual(secondOutputMvid, firstOutputMvid);
251254
}
252255

253256
protected static Guid GetMvid(NPath assemblyPath)

0 commit comments

Comments
 (0)