diff --git a/test/coverlet.integration.tests/BaseTest.cs b/test/coverlet.integration.tests/BaseTest.cs index 000caea..73df393 100644 --- a/test/coverlet.integration.tests/BaseTest.cs +++ b/test/coverlet.integration.tests/BaseTest.cs @@ -53,7 +53,7 @@ namespace Coverlet.Integration.Tests return manifest.Metadata.Version.OriginalVersion; } - private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true) + private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "16.4.0") { DirectoryInfo finalRoot = Directory.CreateDirectory(Guid.NewGuid().ToString("N")); foreach (string file in (Directory.GetFiles($"../../../../coverlet.integration.template", "*.cs") @@ -74,7 +74,7 @@ namespace Coverlet.Integration.Tests "); - AddMicrosoftNETTestSdkRef(finalRoot.FullName); + AddMicrosoftNETTestSdkRef(finalRoot.FullName, testSDKVersion); return new ClonedTemplateProject(finalRoot.FullName, cleanupOnDispose); } @@ -123,7 +123,7 @@ namespace Coverlet.Integration.Tests xml.Save(nugetFile); } - private protected void AddMicrosoftNETTestSdkRef(string projectPath) + private protected void AddMicrosoftNETTestSdkRef(string projectPath, string version) { string csproj = Path.Combine(projectPath, "coverlet.integration.template.csproj"); if (!File.Exists(csproj)) @@ -139,8 +139,7 @@ namespace Coverlet.Integration.Tests xml.Element("Project") .Element("ItemGroup") .Add(new XElement("PackageReference", new XAttribute("Include", "Microsoft.NET.Test.Sdk"), - // We use this due to know issue until official release https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md - new XAttribute("Version", "16.5.0-preview-20200110-02"))); + new XAttribute("Version", version))); xml.Save(csproj); } @@ -277,8 +276,9 @@ namespace Coverlet.Integration.Tests class ClonedTemplateProject : IDisposable { + private bool _cleanupOnDispose; + public string? ProjectRootPath { get; private set; } - public bool _cleanupOnDispose { get; set; } // We need to have a different asm name to avoid issue with collectors, we filter [coverlet.*]* by default // https://github.com/tonerdo/coverlet/pull/410#discussion_r284526728 diff --git a/test/coverlet.integration.tests/Collectors.cs b/test/coverlet.integration.tests/Collectors.cs index 05f7858..9a87eb5 100644 --- a/test/coverlet.integration.tests/Collectors.cs +++ b/test/coverlet.integration.tests/Collectors.cs @@ -1,21 +1,55 @@ -using System.IO; +using System; +using System.IO; using System.Linq; using Xunit; namespace Coverlet.Integration.Tests { - public class Collectors : BaseTest + public class TestSDK_16_2_0 : Collectors { + public TestSDK_16_2_0() + { + TestSDKVersion = "16.2.0"; + } + + private protected override void AssertCollectorsInjection(ClonedTemplateProject clonedTemplateProject) + { + // Check out/in process collectors injection + Assert.Contains("[coverlet]", File.ReadAllText(clonedTemplateProject.GetFiles("log.datacollector.*.txt").Single())); + + // There is a bug in this SDK version https://github.com/microsoft/vstest/pull/2221 + // in-proc coverlet.collector.dll collector with version != 1.0.0.0 won't be loaded + // Assert.Contains("[coverlet]", File.ReadAllText(clonedTemplateProject.GetFiles("log.host.*.txt").Single())); + } + } + + public class TestSDK_Preview : Collectors + { + public TestSDK_Preview() + { + TestSDKVersion = "16.5.0-preview-20200110-02"; + } + } + + public abstract class Collectors : BaseTest + { + protected string? TestSDKVersion { get; set; } + private ClonedTemplateProject PrepareTemplateProject() { - ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(); + if (TestSDKVersion is null) + { + throw new ArgumentNullException("Invalid TestSDKVersion"); + } + + ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(testSDKVersion: TestSDKVersion); UpdateNugeConfigtWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!); AddCoverletCollectosRef(clonedTemplateProject.ProjectRootPath!); return clonedTemplateProject; } - private void AssertCollectorsInjection(ClonedTemplateProject clonedTemplateProject) + private protected virtual void AssertCollectorsInjection(ClonedTemplateProject clonedTemplateProject) { // Check out/in process collectors injection Assert.Contains("[coverlet]", File.ReadAllText(clonedTemplateProject.GetFiles("log.datacollector.*.txt").Single())); diff --git a/test/coverlet.integration.tests/DotnetTool.cs b/test/coverlet.integration.tests/DotnetTool.cs index 71aeacc..8b2be4d 100644 --- a/test/coverlet.integration.tests/DotnetTool.cs +++ b/test/coverlet.integration.tests/DotnetTool.cs @@ -9,7 +9,7 @@ namespace Coverlet.Integration.Tests { private string InstallTool(string projectPath) { - DotnetCli($"tool install coverlet.console --version {GetPackageVersion("*console*.nupkg")} --tool-path \"{Path.Combine(projectPath, "coverletTool")}\"", out string standardOutput, out string standardError, projectPath); + _ = DotnetCli($"tool install coverlet.console --version {GetPackageVersion("*console*.nupkg")} --tool-path \"{Path.Combine(projectPath, "coverletTool")}\"", out string standardOutput, out _, projectPath); Assert.Contains("was successfully installed.", standardOutput); return Path.Combine(projectPath, "coverletTool", "coverlet "); } diff --git a/test/coverlet.integration.tests/Msbuild.cs b/test/coverlet.integration.tests/Msbuild.cs index 0bc0356..0a8cb92 100644 --- a/test/coverlet.integration.tests/Msbuild.cs +++ b/test/coverlet.integration.tests/Msbuild.cs @@ -8,7 +8,7 @@ namespace Coverlet.Integration.Tests { private ClonedTemplateProject PrepareTemplateProject() { - ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(false); + ClonedTemplateProject clonedTemplateProject = CloneTemplateProject(); UpdateNugeConfigtWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!); AddCoverletMsbuildRef(clonedTemplateProject.ProjectRootPath!); return clonedTemplateProject;