Skip to content

Commit 081725a

Browse files
committed
Rollback to xunit v2
The v3 upgrade caused all but 33 tests to be quietly omitted from test runs. Fixing that required [opting into the new Microsoft Testing Platform](xunit/xunit#3107 (comment)). But then a few tests failed to be discovered due to this repo's particular requirements for loading MSBuild with the Locator, causing more failures. Analyzing those failures gets harder because [logs are moved or hidden](xunit/xunit#3109). Ultimately after working through all those issues to get at the errors behind tests and test discovery, I'm just out of ideas for how to get msbuild to load before reflection happens on the test assembly, so I'm just rolling back to xunit v2. See also xunit/xunit#3092.
1 parent 8b132b5 commit 081725a

File tree

10 files changed

+31
-80
lines changed

10 files changed

+31
-80
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ NPM packages too.
4646
`dotnet test` will run all tests.
4747

4848
The Visual Studio 2022 Test Explorer will list and execute all tests.
49-
Visual Studio needs a preview feature called "Use testing platform server mode" enabled.
5049

5150
A few tests will fail without a certain VC++ toolset installed.
5251

Directory.Packages.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@
3838
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
3939
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="9.0.0" />
4040
<PackageVersion Include="Validation" Version="2.5.51" />
41-
<PackageVersion Include="Xunit.Combinatorial" Version="2.0.5-alpha" />
41+
<PackageVersion Include="Xunit.Combinatorial" Version="1.6.24" />
42+
<PackageVersion Include="Xunit.SkippableFact" Version="1.5.23" />
4243
</ItemGroup>
4344
<ItemGroup Label="Library.Template">
4445
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
4546
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
46-
<PackageVersion Include="xunit.v3" Version="1.0.0" />
47+
<PackageVersion Include="xunit" Version="2.9.2" />
4748
</ItemGroup>
4849
<ItemGroup>
4950
<!-- Put repo-specific GlobalPackageReference items in this group. -->

test/Cake.GitVersioning.Tests/Cake.GitVersioning.Tests.csproj

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

33
<PropertyGroup>
44
<TargetFrameworks>net8.0</TargetFrameworks>
5-
<OutputType>Exe</OutputType>
6-
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
75
<SignAssembly>false</SignAssembly>
86
<IsTestProject>true</IsTestProject>
97
<IsPackable>false</IsPackable>
@@ -20,7 +18,7 @@
2018
<PackageReference Include="Microsoft.NET.Test.Sdk" />
2119
<PackageReference Include="Nerdbank.GitVersioning.LKG" />
2220
<PackageReference Include="xunit.runner.visualstudio" />
23-
<PackageReference Include="xunit.v3" />
21+
<PackageReference Include="xunit" />
2422
</ItemGroup>
2523

2624
</Project>

test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class AssemblyInfoTest : IClassFixture<MSBuildFixture> // The MSBuildFixture throws PlatformNotSupportedException when run on mono.
1515
{
16-
[Theory]
16+
[SkippableTheory(typeof(PlatformNotSupportedException))]
1717
[InlineData(false)]
1818
[InlineData(true)]
1919
[InlineData(null)]
@@ -49,15 +49,7 @@ public void FSharpGenerator(bool? thisAssemblyClass)
4949
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
5050
}
5151

52-
string built;
53-
try
54-
{
55-
built = info.BuildCode();
56-
}
57-
catch (PlatformNotSupportedException ex)
58-
{
59-
throw SkipException.ForSkip(ex.Message);
60-
}
52+
string built = info.BuildCode();
6153

6254
string expected = $@"//------------------------------------------------------------------------------
6355
// <auto-generated>
@@ -99,7 +91,7 @@ type internal ThisAssembly() =
9991
Assert.Equal(expected, built);
10092
}
10193

102-
[Theory]
94+
[SkippableTheory(typeof(PlatformNotSupportedException))]
10395
[InlineData(null, "MyRootNamespace")]
10496
[InlineData("", "MyRootNamespace")]
10597
[InlineData("MyCustomNamespace", null)]
@@ -117,15 +109,7 @@ public void FSharpGeneratorWithNamespace(string thisAssemblyNamespace, string ro
117109
ThisAssemblyNamespace = thisAssemblyNamespace,
118110
};
119111

120-
string built;
121-
try
122-
{
123-
built = info.BuildCode();
124-
}
125-
catch (PlatformNotSupportedException ex)
126-
{
127-
throw SkipException.ForSkip(ex.Message);
128-
}
112+
string built = info.BuildCode();
129113

130114
string expected = $@"//------------------------------------------------------------------------------
131115
// <auto-generated>
@@ -168,7 +152,7 @@ type internal ThisAssembly() =
168152
Assert.Equal(expected, built);
169153
}
170154

171-
[Theory]
155+
[SkippableTheory(typeof(PlatformNotSupportedException))]
172156
[InlineData(false)]
173157
[InlineData(true)]
174158
[InlineData(null)]
@@ -204,15 +188,7 @@ public void CSharpGenerator(bool? thisAssemblyClass)
204188
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
205189
}
206190

207-
string built;
208-
try
209-
{
210-
built = info.BuildCode();
211-
}
212-
catch (PlatformNotSupportedException ex)
213-
{
214-
throw SkipException.ForSkip(ex.Message);
215-
}
191+
string built = info.BuildCode();
216192

217193
string expected = $@"//------------------------------------------------------------------------------
218194
// <auto-generated>
@@ -252,7 +228,7 @@ internal static partial class ThisAssembly {{
252228
Assert.Equal(expected, built);
253229
}
254230

255-
[Theory]
231+
[SkippableTheory(typeof(PlatformNotSupportedException))]
256232
[InlineData(null, "MyRootNamespace")]
257233
[InlineData("", "MyRootNamespace")]
258234
[InlineData("MyCustomNamespace", null)]
@@ -270,15 +246,7 @@ public void CSharpGeneratorWithNamespace(string thisAssemblyNamespace, string ro
270246
ThisAssemblyNamespace = thisAssemblyNamespace,
271247
};
272248

273-
string built;
274-
try
275-
{
276-
built = info.BuildCode();
277-
}
278-
catch (PlatformNotSupportedException ex)
279-
{
280-
throw SkipException.ForSkip(ex.Message);
281-
}
249+
string built = info.BuildCode();
282250

283251
(string nsStart, string nsEnd) = !string.IsNullOrWhiteSpace(thisAssemblyNamespace)
284252
? ($"{Environment.NewLine}namespace {thisAssemblyNamespace} {{", $"{Environment.NewLine}}}")
@@ -318,7 +286,7 @@ internal static partial class ThisAssembly {{
318286
Assert.Equal(expected, built);
319287
}
320288

321-
[Theory]
289+
[SkippableTheory(typeof(PlatformNotSupportedException))]
322290
[InlineData(false)]
323291
[InlineData(true)]
324292
[InlineData(null)]
@@ -335,15 +303,7 @@ public void VisualBasicGenerator(bool? thisAssemblyClass)
335303
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
336304
}
337305

338-
string built;
339-
try
340-
{
341-
built = info.BuildCode();
342-
}
343-
catch (PlatformNotSupportedException ex)
344-
{
345-
throw SkipException.ForSkip(ex.Message);
346-
}
306+
string built = info.BuildCode();
347307

348308
string expected = $@"'------------------------------------------------------------------------------
349309
' <auto-generated>
@@ -382,7 +342,7 @@ End Class
382342
Assert.Equal(expected, built);
383343
}
384344

385-
[Theory]
345+
[SkippableTheory(typeof(PlatformNotSupportedException))]
386346
[InlineData(null, "MyRootNamespace")]
387347
[InlineData("", "MyRootNamespace")]
388348
[InlineData("MyCustomNamespace", null)]
@@ -400,15 +360,7 @@ public void VisualBasicGeneratorWithNamespace(string thisAssemblyNamespace, stri
400360
ThisAssemblyNamespace = thisAssemblyNamespace,
401361
};
402362

403-
string built;
404-
try
405-
{
406-
built = info.BuildCode();
407-
}
408-
catch (PlatformNotSupportedException ex)
409-
{
410-
throw SkipException.ForSkip(ex.Message);
411-
}
363+
string built = info.BuildCode();
412364

413365
(string nsStart, string nsEnd) = !string.IsNullOrWhiteSpace(thisAssemblyNamespace)
414366
? ($"{Environment.NewLine}Namespace {thisAssemblyNamespace}", $"{Environment.NewLine}End Namespace")

test/Nerdbank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ public async Task AssemblyInfo_HasKeyData(string keyFile, bool delaySigned)
176176
result.BuildResult.ProjectStateAfterBuild.GetPropertyValue("VersionSourceFile"))));
177177
this.Logger.WriteLine(versionCsContent);
178178

179-
SyntaxTree sourceFile = CSharpSyntaxTree.ParseText(versionCsContent, cancellationToken: TestContext.Current.CancellationToken);
180-
SyntaxNode syntaxTree = await sourceFile.GetRootAsync(TestContext.Current.CancellationToken);
179+
SyntaxTree sourceFile = CSharpSyntaxTree.ParseText(versionCsContent);
180+
SyntaxNode syntaxTree = await sourceFile.GetRootAsync();
181181
IEnumerable<VariableDeclaratorSyntax> fields = syntaxTree.DescendantNodes().OfType<VariableDeclaratorSyntax>();
182182

183183
var publicKeyField = (LiteralExpressionSyntax)fields.SingleOrDefault(f => f.Identifier.ValueText == "PublicKey")?.Initializer.Value;

test/Nerdbank.GitVersioning.Tests/GitContextTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public void SelectCommitByPartialId(bool fromPack, bool oddLength)
9393
Assert.Equal(this.LibGit2Repository.Head.Tip.Sha, this.Context.GitCommitId);
9494
}
9595

96-
[Theory]
96+
[SkippableTheory]
9797
[InlineData(4)]
9898
[InlineData(7)]
9999
[InlineData(8)]
100100
[InlineData(11)]
101101
public void GetShortUniqueCommitId(int length)
102102
{
103-
Assert.SkipWhen(length < 7 && this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context, "LibGit2Sharp never returns commit IDs with fewer than 7 characters.");
103+
Skip.If(length < 7 && this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context, "LibGit2Sharp never returns commit IDs with fewer than 7 characters.");
104104
Assert.Equal(this.Context.GitCommitId.Substring(0, length), this.Context.GetShortUniqueCommitId(length));
105105
}
106106

test/Nerdbank.GitVersioning.Tests/LibGit2GitExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public void GetIdAsVersion_MigrationFromVersionTxtToJson()
467467
public void TestBiggerRepo()
468468
{
469469
string testBiggerRepoPath = @"D:\git\Nerdbank.GitVersioning";
470-
Assert.SkipWhen(!Directory.Exists(testBiggerRepoPath), $"{testBiggerRepoPath} does not exist.");
470+
Skip.If(!Directory.Exists(testBiggerRepoPath), $"{testBiggerRepoPath} does not exist.");
471471

472472
using var largeRepo = new Repository(testBiggerRepoPath);
473473
foreach (Commit commit in largeRepo.Head.Commits)

test/Nerdbank.GitVersioning.Tests/Nerdbank.GitVersioning.Tests.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<PropertyGroup>
33
<TargetFrameworks>net9.0</TargetFrameworks>
44
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net472</TargetFrameworks>
5-
<OutputType>Exe</OutputType>
6-
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
75
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
86
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
97
<DebugType>full</DebugType>
@@ -46,7 +44,8 @@
4644
<PackageReference Include="System.Memory" />
4745
<PackageReference Include="System.Threading.Tasks.Dataflow" />
4846
<PackageReference Include="Xunit.Combinatorial" />
47+
<PackageReference Include="Xunit.SkippableFact" />
4948
<PackageReference Include="xunit.runner.visualstudio" />
50-
<PackageReference Include="xunit.v3" />
49+
<PackageReference Include="xunit" />
5150
</ItemGroup>
5251
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
global using Xunit.Abstractions;

tools/dotnet-test-cloud.ps1

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ if ($x86) {
4444
}
4545
}
4646

47-
$testBinLog = Join-Path $ArtifactStagingFolder build_logs test.binlog
48-
$testResultsDirectory = Join-Path $ArtifactStagingFolder test_logs
47+
$testBinLog = Join-Path $ArtifactStagingFolder (Join-Path build_logs test.binlog)
48+
$testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log)
4949

5050
& $dotnet test $RepoRoot `
5151
--no-build `
@@ -56,10 +56,8 @@ $testResultsDirectory = Join-Path $ArtifactStagingFolder test_logs
5656
--blame-hang-timeout 60s `
5757
--blame-crash `
5858
-bl:"$testBinLog" `
59-
-- `
60-
--results-directory $testResultsDirectory `
61-
--report-xunit-trx `
62-
--long-running 60 `
59+
--diag "$testDiagLog;TraceLevel=info" `
60+
--logger trx `
6361

6462
$unknownCounter = 0
6563
Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx |% {

0 commit comments

Comments
 (0)