Skip to content

Commit

Permalink
Merge pull request #1147 from dotnet/rollbackToXunitv2
Browse files Browse the repository at this point in the history
Rollback to xunit v2
  • Loading branch information
AArnott authored Jan 1, 2025
2 parents 26a9056 + 081725a commit 20abff5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 72 deletions.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ NPM packages too.

## Testing

The Visual Studio 2019 Test Explorer will list and execute all tests.
`dotnet test` will run all tests.

The Visual Studio 2022 Test Explorer will list and execute all tests.

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

## Releases

Expand Down
5 changes: 3 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="9.0.0" />
<PackageVersion Include="Validation" Version="2.5.51" />
<PackageVersion Include="Xunit.Combinatorial" Version="2.0.5-alpha" />
<PackageVersion Include="Xunit.Combinatorial" Version="1.6.24" />
<PackageVersion Include="Xunit.SkippableFact" Version="1.5.23" />
</ItemGroup>
<ItemGroup Label="Library.Template">
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
<PackageVersion Include="xunit.v3" Version="1.0.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
</ItemGroup>
<ItemGroup>
<!-- Put repo-specific GlobalPackageReference items in this group. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<SignAssembly>false</SignAssembly>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
Expand All @@ -19,7 +18,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Nerdbank.GitVersioning.LKG" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit" />
</ItemGroup>

</Project>
72 changes: 12 additions & 60 deletions test/Nerdbank.GitVersioning.Tests/AssemblyInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class AssemblyInfoTest : IClassFixture<MSBuildFixture> // The MSBuildFixture throws PlatformNotSupportedException when run on mono.
{
[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
Expand Down Expand Up @@ -49,15 +49,7 @@ public void FSharpGenerator(bool? thisAssemblyClass)
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

string expected = $@"//------------------------------------------------------------------------------
// <auto-generated>
Expand Down Expand Up @@ -99,7 +91,7 @@ type internal ThisAssembly() =
Assert.Equal(expected, built);
}

[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(null, "MyRootNamespace")]
[InlineData("", "MyRootNamespace")]
[InlineData("MyCustomNamespace", null)]
Expand All @@ -117,15 +109,7 @@ public void FSharpGeneratorWithNamespace(string thisAssemblyNamespace, string ro
ThisAssemblyNamespace = thisAssemblyNamespace,
};

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

string expected = $@"//------------------------------------------------------------------------------
// <auto-generated>
Expand Down Expand Up @@ -168,7 +152,7 @@ type internal ThisAssembly() =
Assert.Equal(expected, built);
}

[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
Expand Down Expand Up @@ -204,15 +188,7 @@ public void CSharpGenerator(bool? thisAssemblyClass)
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

string expected = $@"//------------------------------------------------------------------------------
// <auto-generated>
Expand Down Expand Up @@ -252,7 +228,7 @@ internal static partial class ThisAssembly {{
Assert.Equal(expected, built);
}

[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(null, "MyRootNamespace")]
[InlineData("", "MyRootNamespace")]
[InlineData("MyCustomNamespace", null)]
Expand All @@ -270,15 +246,7 @@ public void CSharpGeneratorWithNamespace(string thisAssemblyNamespace, string ro
ThisAssemblyNamespace = thisAssemblyNamespace,
};

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

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

[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(false)]
[InlineData(true)]
[InlineData(null)]
Expand All @@ -335,15 +303,7 @@ public void VisualBasicGenerator(bool? thisAssemblyClass)
info.EmitThisAssemblyClass = thisAssemblyClass.GetValueOrDefault();
}

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

string expected = $@"'------------------------------------------------------------------------------
' <auto-generated>
Expand Down Expand Up @@ -382,7 +342,7 @@ End Class
Assert.Equal(expected, built);
}

[Theory]
[SkippableTheory(typeof(PlatformNotSupportedException))]
[InlineData(null, "MyRootNamespace")]
[InlineData("", "MyRootNamespace")]
[InlineData("MyCustomNamespace", null)]
Expand All @@ -400,15 +360,7 @@ public void VisualBasicGeneratorWithNamespace(string thisAssemblyNamespace, stri
ThisAssemblyNamespace = thisAssemblyNamespace,
};

string built;
try
{
built = info.BuildCode();
}
catch (PlatformNotSupportedException ex)
{
throw SkipException.ForSkip(ex.Message);
}
string built = info.BuildCode();

(string nsStart, string nsEnd) = !string.IsNullOrWhiteSpace(thisAssemblyNamespace)
? ($"{Environment.NewLine}Namespace {thisAssemblyNamespace}", $"{Environment.NewLine}End Namespace")
Expand Down
4 changes: 2 additions & 2 deletions test/Nerdbank.GitVersioning.Tests/BuildIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public async Task AssemblyInfo_HasKeyData(string keyFile, bool delaySigned)
result.BuildResult.ProjectStateAfterBuild.GetPropertyValue("VersionSourceFile"))));
this.Logger.WriteLine(versionCsContent);

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

var publicKeyField = (LiteralExpressionSyntax)fields.SingleOrDefault(f => f.Identifier.ValueText == "PublicKey")?.Initializer.Value;
Expand Down
4 changes: 2 additions & 2 deletions test/Nerdbank.GitVersioning.Tests/GitContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public void SelectCommitByPartialId(bool fromPack, bool oddLength)
Assert.Equal(this.LibGit2Repository.Head.Tip.Sha, this.Context.GitCommitId);
}

[Theory]
[SkippableTheory]
[InlineData(4)]
[InlineData(7)]
[InlineData(8)]
[InlineData(11)]
public void GetShortUniqueCommitId(int length)
{
Assert.SkipWhen(length < 7 && this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context, "LibGit2Sharp never returns commit IDs with fewer than 7 characters.");
Skip.If(length < 7 && this.Context is Nerdbank.GitVersioning.LibGit2.LibGit2Context, "LibGit2Sharp never returns commit IDs with fewer than 7 characters.");
Assert.Equal(this.Context.GitCommitId.Substring(0, length), this.Context.GetShortUniqueCommitId(length));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void GetIdAsVersion_MigrationFromVersionTxtToJson()
public void TestBiggerRepo()
{
string testBiggerRepoPath = @"D:\git\Nerdbank.GitVersioning";
Assert.SkipWhen(!Directory.Exists(testBiggerRepoPath), $"{testBiggerRepoPath} does not exist.");
Skip.If(!Directory.Exists(testBiggerRepoPath), $"{testBiggerRepoPath} does not exist.");

using var largeRepo = new Repository(testBiggerRepoPath);
foreach (Commit commit in largeRepo.Head.Commits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net472</TargetFrameworks>
<OutputType>Exe</OutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<DebugType>full</DebugType>
Expand Down Expand Up @@ -45,7 +44,8 @@
<PackageReference Include="System.Memory" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
<PackageReference Include="Xunit.Combinatorial" />
<PackageReference Include="Xunit.SkippableFact" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions test/Nerdbank.GitVersioning.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 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.

global using Xunit.Abstractions;

0 comments on commit 20abff5

Please sign in to comment.