Skip to content

Commit

Permalink
Merge branch 'hotfix/0.24.2'
Browse files Browse the repository at this point in the history
* hotfix/0.24.2:
  (#124) Remove usage of IsNetCore method
  (#123) Only install OpenCover when needed
  • Loading branch information
gep13 committed Sep 1, 2023
2 parents ff1bccd + d6dba21 commit 3210c4d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
1 change: 0 additions & 1 deletion Chocolatey.Cake.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class BuildTasks
public CakeTaskBuilder PublishAwsLambdasTask { get; set; }

// Testing Tasks
public CakeTaskBuilder InstallOpenCoverTask { get; set; }
public CakeTaskBuilder TestNUnitTask { get; set; }
public CakeTaskBuilder TestxUnitTask { get; set; }
public CakeTaskBuilder DotNetTestTask { get; set; }
Expand Down
91 changes: 43 additions & 48 deletions Chocolatey.Cake.Recipe/Content/testing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ using System.Xml.XPath;

Tuple<string, Exception> testsException = null;

BuildParameters.Tasks.InstallOpenCoverTask = Task("Install-OpenCover")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping because not running on windows")
.WithCriteria(() => BuildParameters.ShouldRunTests, "Skipping because running tests is not enabled")
.Does(() => RequireTool(ToolSettings.OpenCoverTool, () => {
}));

BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit")
.IsDependentOn("Install-OpenCover")
.WithCriteria(() => BuildParameters.ShouldRunNUnit, "Skipping because NUnit is not enabled")
.WithCriteria(() => BuildParameters.ShouldRunTests, "Skipping because running tests is not enabled")
.WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.PublishedNUnitTests), "Skipping because there are no published NUnit tests")
Expand Down Expand Up @@ -68,20 +61,22 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit")
{
Information("Running OpenCover and NUnit...");

OpenCover(tool => {
tool.NUnit3(assembliesToTest, new NUnit3Settings {
Work = BuildParameters.Paths.Directories.NUnitTestResults
});
},
BuildParameters.Paths.Files.TestCoverageOutputFilePath,
new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0
}
.WithFilter(ToolSettings.TestCoverageFilter)
.ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute)
.ExcludeByFile(ToolSettings.TestCoverageExcludeByFile));
RequireTool(ToolSettings.OpenCoverTool, () => {
OpenCover(tool => {
tool.NUnit3(assembliesToTest, new NUnit3Settings {
Work = BuildParameters.Paths.Directories.NUnitTestResults
});
},
BuildParameters.Paths.Files.TestCoverageOutputFilePath,
new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0
}
.WithFilter(ToolSettings.TestCoverageFilter)
.ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute)
.ExcludeByFile(ToolSettings.TestCoverageExcludeByFile));
});
}
else
{
Expand All @@ -100,7 +95,6 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit")
});

BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit")
.IsDependentOn("Install-OpenCover")
.WithCriteria(() => BuildParameters.ShouldRunxUnit, "Skipping because xUnit is not enabled")
.WithCriteria(() => BuildParameters.ShouldRunTests, "Skipping because running tests is not enabled")
.WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.PublishedxUnitTests), "Skipping because there are no published xUnit tests")
Expand Down Expand Up @@ -139,22 +133,24 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit")
{
Information("Running OpenCover and xUnit...");

OpenCover(tool => {
tool.XUnit2(assembliesToTest, new XUnit2Settings {
OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults,
XmlReport = true,
NoAppDomain = true
});
},
BuildParameters.Paths.Files.TestCoverageOutputFilePath,
new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0
}
.WithFilter(ToolSettings.TestCoverageFilter)
.ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute)
.ExcludeByFile(ToolSettings.TestCoverageExcludeByFile));
RequireTool(ToolSettings.OpenCoverTool, () => {
OpenCover(tool => {
tool.XUnit2(assembliesToTest, new XUnit2Settings {
OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults,
XmlReport = true,
NoAppDomain = true
});
},
BuildParameters.Paths.Files.TestCoverageOutputFilePath,
new OpenCoverSettings
{
OldStyle = true,
ReturnTargetCodeOffset = 0
}
.WithFilter(ToolSettings.TestCoverageFilter)
.ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute)
.ExcludeByFile(ToolSettings.TestCoverageExcludeByFile));
});
}
else
{
Expand All @@ -175,7 +171,6 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit")
});

BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest")
.IsDependentOn("Install-OpenCover")
.WithCriteria(() => BuildParameters.ShouldRunDotNetTest, "Skipping because dotnet test is not enabled")
.WithCriteria(() => BuildParameters.ShouldRunTests, "Skipping because running tests is not enabled")
.Does(() => {
Expand Down Expand Up @@ -282,27 +277,27 @@ BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest")
return args;
};

if (parsedProject.IsNetCore && coverletPackage != null)
if (coverletPackage != null)
{
Information("Running DotNetCoreTest...");
Information("Running DotNetCoreTest along with Coverlet...");

coverletSettings.CoverletOutputName = parsedProject.RootNameSpace.Replace('.', '-');
DotNetCoreTest(project.FullPath, settings, coverletSettings);
}
else if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows)
else if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows || !BuildParameters.ShouldRunOpenCover)
{
Information("Invoking Test Action..");

testAction(Context);
}
else
{
if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover)
{
Information("Running OpenCover...");
Information("Running OpenCover...");

// We can not use msbuild properties together with opencover
settings.ArgumentCustomization = null;
// We can not use msbuild properties together with opencover
settings.ArgumentCustomization = null;

RequireTool(ToolSettings.OpenCoverTool, () => {
OpenCover(testAction,
BuildParameters.Paths.Files.TestCoverageOutputFilePath,
new OpenCoverSettings {
Expand All @@ -314,7 +309,7 @@ BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest")
.WithFilter(ToolSettings.TestCoverageFilter)
.ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute)
.ExcludeByFile(ToolSettings.TestCoverageExcludeByFile));
}
});
}
}
}).OnError((exception) =>
Expand Down

0 comments on commit 3210c4d

Please sign in to comment.