Skip to content

Commit

Permalink
Enable use NUnit.Tool to run tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
CharliePoole committed Mar 5, 2025
1 parent 593a0ec commit b4ac644
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions recipe/test-runners.cake
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ public abstract class InstallableTestRunner : TestRunner
}

protected FilePath ExecutableRelativePath { get; set; }
protected bool IsDotNetTool { get; set; } = false;

// Path under tools directory where package would be installed by Cake #tool directive.
// NOTE: When used to run unit tests, a #tool directive is required. If derived package
// is only used for package tests, it is optional.
protected DirectoryPath ToolInstallDirectory => BuildSettings.ToolsDirectory + $"{PackageId}.{Version}";
protected DirectoryPath ToolInstallDirectory => IsDotNetTool
? BuildSettings.ToolsDirectory
: BuildSettings.ToolsDirectory + $"{PackageId}.{Version}";
protected bool IsInstalledAsTool =>
ToolInstallDirectory != null && Context.DirectoryExists(ToolInstallDirectory);
Context.DirectoryExists(ToolInstallDirectory);

protected DirectoryPath InstallDirectory;

Expand All @@ -120,10 +123,17 @@ public abstract class InstallableTestRunner : TestRunner
public void Install(DirectoryPath installDirectory)
{
InstallDirectory = installDirectory.Combine($"{PackageId}.{Version}");
Context.CreateDirectory(InstallDirectory);

// If the runner package is already installed as a cake tool, we just copy it
if (IsInstalledAsTool)
Context.CopyDirectory(ToolInstallDirectory, InstallDirectory);
if (IsDotNetTool)
{
Context.CopyFileToDirectory(BuildSettings.ToolsDirectory + ExecutableRelativePath, InstallDirectory);
Context.CopyDirectory(BuildSettings.ToolsDirectory + ".store", InstallDirectory);
}
else
Context.CopyDirectory(ToolInstallDirectory, InstallDirectory);
// Otherwise, we install it to the requested location
else
Context.NuGetInstall(
Expand Down Expand Up @@ -199,7 +209,8 @@ public class NUnitNetCoreConsoleRunner : InstallableTestRunner, IUnitTestRunner,
{
public NUnitNetCoreConsoleRunner(string version) : base("NUnit.ConsoleRunner.NetCore", version)
{
ExecutableRelativePath = version[0] == '3' ? "tools/net8.0/nunit3-console.exe" : "tools/nunit-netcore-console.exe";
IsDotNetTool = true;
ExecutableRelativePath = version[0] == '3' ? "tools/net8.0/nunit3-console.exe" : "nunit.exe";
}

// Run a unit test
Expand Down

0 comments on commit b4ac644

Please sign in to comment.