From 7e0c7e87e9be3c04b68cbb4a4dbd0ee27996609e Mon Sep 17 00:00:00 2001 From: Bert Date: Tue, 5 Nov 2024 10:12:31 +0100 Subject: [PATCH] enable dotnetTool integration tests for linux and MacOS (#1701) --- eng/build.yml | 1 + test/coverlet.integration.tests/DotnetTool.cs | 47 +++++++++++++------ test/coverlet.tests.utils/TestUtils.cs | 3 ++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/eng/build.yml b/eng/build.yml index dbacdb65f..adfbcdd6f 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -45,6 +45,7 @@ steps: mergeTestResults: false publishRunAttachments: true failTaskOnFailedTests: true + condition: succeededOrFailed() - template: publish-coverlet-result-files.yml diff --git a/test/coverlet.integration.tests/DotnetTool.cs b/test/coverlet.integration.tests/DotnetTool.cs index 49440ed4a..14a8edc65 100644 --- a/test/coverlet.integration.tests/DotnetTool.cs +++ b/test/coverlet.integration.tests/DotnetTool.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using Coverlet.Tests.Utils; -using Coverlet.Tests.Xunit.Extensions; using Xunit; using Xunit.Abstractions; @@ -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); @@ -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); diff --git a/test/coverlet.tests.utils/TestUtils.cs b/test/coverlet.tests.utils/TestUtils.cs index 595794b6f..3e7478343 100644 --- a/test/coverlet.tests.utils/TestUtils.cs +++ b/test/coverlet.tests.utils/TestUtils.cs @@ -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