Skip to content

Make tests run on all platforms #1492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Toni Solarin-Sodara
// Copyright (c) Toni Solarin-Sodara
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -34,9 +34,7 @@ public void Dispose()
_disposeAction?.Invoke();
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void TestCoreLibInstrumentation()
{
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), nameof(TestCoreLibInstrumentation)));
Expand All @@ -55,7 +53,7 @@ public void TestCoreLibInstrumentation()
partialMockFileSystem.CallBase = true;
partialMockFileSystem.Setup(fs => fs.OpenRead(It.IsAny<string>())).Returns((string path) =>
{
if (Path.GetFileName(path) == files[1])
if (Path.GetFileName(path.Replace(@"\", @"/")) == files[1])
{
return File.OpenRead(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), files[1]));
}
Expand All @@ -66,7 +64,7 @@ public void TestCoreLibInstrumentation()
});
partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) =>
{
if (Path.GetFileName(path) == files[1])
if (Path.GetFileName(path.Replace(@"\", @"/")) == files[1])
{
return File.Exists(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), files[1]));
}
Expand Down Expand Up @@ -446,9 +444,7 @@ public void SkipEmbeddedPpdbWithoutLocalSource()
loggerMock.VerifyNoOtherCalls();
}

[ConditionalFact]
[SkipOnOS(OS.MacOS)]
[SkipOnOS(OS.Linux)]
[Fact]
public void SkipPpdbWithoutLocalSource()
{
string dllFileName = "75d9f96508d74def860a568f426ea4a4.dll";
Expand All @@ -458,7 +454,7 @@ public void SkipPpdbWithoutLocalSource()
partialMockFileSystem.CallBase = true;
partialMockFileSystem.Setup(fs => fs.OpenRead(It.IsAny<string>())).Returns((string path) =>
{
if (Path.GetFileName(path) == pdbFileName)
if (Path.GetFileName(path.Replace(@"\", @"/")) == pdbFileName)
{
return File.OpenRead(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName));
}
Expand All @@ -469,7 +465,7 @@ public void SkipPpdbWithoutLocalSource()
});
partialMockFileSystem.Setup(fs => fs.Exists(It.IsAny<string>())).Returns((string path) =>
{
if (Path.GetFileName(path) == pdbFileName)
if (Path.GetFileName(path.Replace(@"\", @"/")) == pdbFileName)
{
return File.Exists(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), pdbFileName));
}
Expand Down
14 changes: 5 additions & 9 deletions test/coverlet.integration.tests/DotnetTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,31 @@ private string InstallTool(string 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 ");
return Path.Combine(projectPath, "coverletTool", "coverlet");
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void DotnetTool()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugeConfigtWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
DotnetCli($"build {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}\"\\", out standardOutput, out standardError);
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);
Assert.Contains("Passed!", standardOutput);
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
}

[ConditionalFact]
[SkipOnOS(OS.Linux)]
[SkipOnOS(OS.MacOS)]
[Fact]
public void StandAlone()
{
using ClonedTemplateProject clonedTemplateProject = CloneTemplateProject();
UpdateNugeConfigtWithLocalPackageFolder(clonedTemplateProject.ProjectRootPath!);
string coverletToolCommandPath = InstallTool(clonedTemplateProject.ProjectRootPath!);
DotnetCli($"build {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}\"\\", out standardOutput, out standardError);
RunCommand(coverletToolCommandPath, $"\"{Path.GetDirectoryName(publishedTestFile)}\" --target \"dotnet\" --targetargs \"{publishedTestFile}\" --output \"{clonedTemplateProject.ProjectRootPath}\"{Path.DirectorySeparatorChar}", out standardOutput, out standardError);
Assert.Contains("Hello World!", standardOutput);
AssertCoverage(clonedTemplateProject, standardOutput: standardOutput);
}
Expand Down