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

refactor: upgrade to xunit v3 #728

Merged
merged 11 commits into from
Jan 25, 2025
Prev Previous commit
Next Next commit
Fix pipeline as xunit3 produces executables
  • Loading branch information
vbreuss committed Jan 25, 2025
commit 93111497da1753be97d9b468d00a38fd9a19e8d3
1 change: 0 additions & 1 deletion .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"CodeAnalysisEnd",
"CodeCoverage",
"Compile",
"DotNetFrameworkUnitTests",
"DotNetUnitTests",
"MutationComment",
"MutationTestPreparation",
Expand Down
2 changes: 1 addition & 1 deletion Pipeline/Build.Compile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ partial class Build
{
SemVer = GitVersion?.SemVer;

if (GitHubActions.IsPullRequest && GitVersion != null)
if (GitHubActions?.IsPullRequest == true && GitVersion != null)
{
string buildNumber = GitHubActions.RunNumber.ToString();
Console.WriteLine(
Expand Down
50 changes: 5 additions & 45 deletions Pipeline/Build.UnitTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.Xunit;
using Serilog;
using System;
using System.Linq;
using static Nuke.Common.Tools.Xunit.XunitTasks;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

// ReSharper disable AllUnderscoreLocalParameterName
Expand All @@ -18,51 +15,15 @@ partial class Build
{
const int MaxRetries = 1;

Target DotNetFrameworkUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin)
.Executes(() =>
{
string[] testAssemblies = UnitTestProjects
.SelectMany(project =>
project.Directory.GlobFiles(
$"bin/{(Configuration == Configuration.Debug ? "Debug" : "Release")}/net48/*.Tests.dll"))
.Select(p => p.ToString())
.ToArray();

Assert.NotEmpty(testAssemblies.ToList());

string net48 = "net48";
for (int retry = MaxRetries; retry >= 0; retry--)
{
try
{
Xunit2(s => s
.SetFramework(net48)
.AddTargetAssemblies(testAssemblies)
);
}
catch (Exception ex)
{
if (retry == 0)
{
Log.Error($"All {MaxRetries + 1} tries failed: {ex}");
throw;
}

Log.Error($"Error during unit tests: {ex}");
Log.Information($"Retry {MaxRetries - retry + 1} of {MaxRetries} times:");
}
}
});

Target DotNetUnitTests => _ => _
.Unlisted()
.DependsOn(Compile)
.Executes(() =>
{
string net48 = "net48";
string[] excludedFrameworks =
EnvironmentInfo.IsWin
? []
: ["net48"];
for (int retry = MaxRetries; retry >= 0; retry--)
{
try
Expand All @@ -78,7 +39,7 @@ partial class Build
(settings, project) => settings
.SetProjectFile(project)
.CombineWith(
project.GetTargetFrameworks()?.Except([net48]),
project.GetTargetFrameworks()?.Except(excludedFrameworks),
(frameworkSettings, framework) => frameworkSettings
.SetFramework(framework)
.AddLoggers(
Expand Down Expand Up @@ -111,6 +72,5 @@ partial class Build
];

Target UnitTests => _ => _
.DependsOn(DotNetFrameworkUnitTests)
.DependsOn(DotNetUnitTests);
}
2 changes: 0 additions & 2 deletions Pipeline/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ partial class Build : NukeBuild
GitHubActions GitHubActions => GitHubActions.Instance;

public static int Main() => Execute<Build>([
x => x.ApiChecks,
x => x.UnitTests,
x => x.MutationTests,
]);
}
Loading