Skip to content

Commit

Permalink
enable dotnetTool integration tests for linux and MacOS (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertk authored Nov 5, 2024
1 parent c01ef48 commit 7e0c7e8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ steps:
mergeTestResults: false
publishRunAttachments: true
failTaskOnFailedTests: true
condition: succeededOrFailed()

- template: publish-coverlet-result-files.yml

Expand Down
47 changes: 32 additions & 15 deletions test/coverlet.integration.tests/DotnetTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.IO;
using System.Linq;
using Coverlet.Tests.Utils;
using Coverlet.Tests.Xunit.Extensions;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -33,9 +32,10 @@ public void DotnetTool()
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
RunCommand(coverletToolCommandPath, $"\"{publishedTestFile}\" --target \"dotnet\" --targetargs \"test {Path.Combine(clonedTemplateProject.ProjectRootPath, ClonedTemplateProject.ProjectFileName)} --no-build\" --include-test-assembly --output \"{clonedTemplateProject.ProjectRootPath}\"{Path.DirectorySeparatorChar}", out standardOutput, out standardError);
RunCommand(coverletToolCommandPath, $"\"{publishedTestFile}\" --target \"dotnet\" --targetargs \"test {Path.Combine(clonedTemplateProject.ProjectRootPath, ClonedTemplateProject.ProjectFileName)} --no-build\" --include-test-assembly --output \"{outputPath}\"", out standardOutput, out standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
Expand All @@ -50,75 +50,92 @@ public void StandAlone()
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{clonedTemplateProject.ProjectRootPath}\"{Path.DirectorySeparatorChar}", out standardOutput, out standardError);
RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{outputPath}\"", out standardOutput, out standardError);
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
Assert.Contains("Hello World!", standardOutput);
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void StandAloneThreshold()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --output \"{outputPath}\"", out standardOutput, out standardError));
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.Contains("Hello World!", standardOutput);
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void StandAloneThresholdLine()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --output \"{outputPath}\"", out standardOutput, out standardError));
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.Contains("Hello World!", standardOutput);
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.DoesNotContain("The minimum method coverage is below the specified 80", standardOutput);
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void StandAloneThresholdLineAndMethod()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugetConfigWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
string outputPath = $"{clonedTemplateProject.ProjectRootPath}{Path.DirectorySeparatorChar}coverage.json";
DotnetCli($"build -f {_buildTargetFramework} {clonedTemplateProject.ProjectRootPath}", out string standardOutput, out string standardError);
string publishedTestFile = clonedTemplateProject.GetFiles("*" + ClonedTemplateProject.AssemblyName + ".dll").Single(f => !f.Contains("obj") && !f.Contains("ref"));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{clonedTemplateProject.ProjectRootPath}\"\\", out standardOutput, out standardError));
Assert.False(RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --threshold 80 --threshold-type line --threshold-type method --output \"{outputPath}\"", out standardOutput, out standardError));
if (!string.IsNullOrEmpty(standardError))
{
_output.WriteLine(standardError);
}
else
{
// make standard output available in trx file
_output.WriteLine(standardOutput);
}
Assert.Contains("Hello World!", standardOutput);
Assert.True(File.Exists(outputPath));
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
Assert.Contains("The minimum line coverage is below the specified 80", standardOutput);
Assert.Contains("The minimum method coverage is below the specified 80", standardOutput);
Expand Down
3 changes: 3 additions & 0 deletions test/coverlet.tests.utils/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public static BuildConfiguration GetAssemblyBuildConfiguration()

public static string GetAssemblyTargetFramework()
{
#if NET6_0
return "net6.0";
#endif
#if NET7_0
return "net7.0";
#endif
Expand Down

0 comments on commit 7e0c7e8

Please sign in to comment.