Skip to content
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

Make unit tests run on non-windows systems #140

Merged
merged 4 commits into from
Jul 1, 2024
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
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-2022 ]
os: [ windows-2022, ubuntu-22.04, macos-12 ]

env:
AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }}
AZURE_SOURCE: ${{ secrets.AZURE_SOURCE }}
AZURE_USER: ${{ secrets.AZURE_USER }}
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
GITTER_ROOM_ID: ${{ secrets.GITTER_ROOM_ID }}
GPR_PASSWORD: ${{ secrets.GPR_PASSWORD }}
GPR_SOURCE: ${{ secrets.GPR_SOURCE }}
GPR_USER: ${{ secrets.GPR_USER }}
GITTER_TOKEN: ${{ secrets.GITTER_TOKEN }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
NUGET_SOURCE: "https://api.nuget.org/v3/index.json"
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
Expand All @@ -47,6 +45,11 @@ jobs:
- name: Fetch all tags and branches
run: git fetch --prune --unshallow

# install libgit2-dev on ubuntu, so libgit2sharp works
- name: Install libgit-dev
if: runner.os == 'Linux'
run: sudo apt-get install -y libgit2-dev

- uses: actions/[email protected]
with:
dotnet-version: |
Expand Down Expand Up @@ -76,11 +79,14 @@ jobs:
uses: actions/upload-artifact@v4
with:
if-no-files-found: warn
name: issues
path: BuildArtifacts/report.html
name: ${{ matrix.os }} Issues
path: |
BuildArtifacts/report.html
BuildArtifacts/**/coverlet/*.xml

- name: Upload Packages
uses: actions/upload-artifact@v4
if: runner.os == 'Windows'
with:
if-no-files-found: warn
name: package
Expand Down
9 changes: 7 additions & 2 deletions Source/Cake.Coveralls.Tests/CoverallsIoRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ internal sealed class CoverallsIoRunnerFixture : ToolFixture<CoverallsIoSettings
public CoverallsIoRunnerFixture()
: base("coveralls.net.exe")
{
CodeCoverageReportFilePath = "c:/temp/coverage.xml";
CodeCoverageReportFilePath = FileSystem.GetFile("/temp/coverage.xml").Path.FullPath;
}

public FilePath CodeCoverageReportFilePath { get; set; }
public FilePath CodeCoverageReportFilePath { get; private set; }

protected override void RunTool()
{
var tool = new CoverallsIoRunner(FileSystem, Environment, ProcessRunner, Tools);
tool.Run(CodeCoverageReportFilePath, Settings);
}

public void WithoutCodeCoverageReportFilePath()
{
CodeCoverageReportFilePath = null;
}
}
}
24 changes: 5 additions & 19 deletions Source/Cake.Coveralls.Tests/CoverallsIoRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void Should_Throw_If_CoverallsIo_Executable_Was_Not_Found()
}

[Theory]
[WindowsOnlyInlineData("C:/CoverallsIo/coveralls.net.exe", "C:/CoverallsIo/coveralls.net.exe")]
[InlineData("/bin/tools/CoverallsIo/coveralls.net.exe", "/bin/tools/CoverallsIo/coveralls.net.exe")]
[InlineData("./tools/CoverallsIo/coveralls.net.exe", "/Working/tools/CoverallsIo/coveralls.net.exe")]
public void Should_Use_CoverallsIo_Runner_From_Tool_Path_If_Provided(string toolPath, string expected)
Expand All @@ -55,21 +56,6 @@ public void Should_Use_CoverallsIo_Runner_From_Tool_Path_If_Provided(string tool
Assert.Equal(expected, result.Path.FullPath);
}

[Theory]
[InlineData("C:/CoverallsIo/coveralls.net.exe", "C:/CoverallsIo/coveralls.net.exe")]
public void Should_Use_CoverallsIo_Runner_From_Tool_Path_If_Provided_On_Windows(string toolPath, string expected)
{
// Given
var fixture = new CoverallsIoRunnerFixture { Settings = { ToolPath = toolPath } };
fixture.GivenSettingsToolPathExist();

// When
var result = fixture.Run();

// Then
Assert.Equal(expected, result.Path.FullPath);
}

[Fact]
public void Should_Find_CoverallsIo_Runner_If_Tool_Path_Not_Provided()
{
Expand All @@ -88,7 +74,7 @@ public void Should_Throw_If_Code_Coverage_File_Path_Is_Null()
{
// Given
var fixture = new CoverallsIoRunnerFixture();
fixture.CodeCoverageReportFilePath = null;
fixture.WithoutCodeCoverageReportFilePath();

// When
var result = Record.Exception(() => fixture.Run());
Expand Down Expand Up @@ -151,7 +137,7 @@ public void Should_Set_Debug()
var result = fixture.Run();

// Then
Assert.Equal("--opencover \"c:/temp/coverage.xml\" --debug", result.Args);
Assert.Equal($"--opencover \"{fixture.CodeCoverageReportFilePath}\" --debug", result.Args);
}

[Fact]
Expand All @@ -164,7 +150,7 @@ public void Should_Set_Full_Sources()
var result = fixture.Run();

// Then
Assert.Equal("--opencover \"c:/temp/coverage.xml\" --full-sources", result.Args);
Assert.Equal($"--opencover \"{fixture.CodeCoverageReportFilePath}\" --full-sources", result.Args);
}

[Fact]
Expand All @@ -177,7 +163,7 @@ public void Should_Set_RepoToken()
var result = fixture.Run();

// Then
Assert.Equal("--opencover \"c:/temp/coverage.xml\" --repo-token \"abcdef\"", result.Args);
Assert.Equal($"--opencover \"{fixture.CodeCoverageReportFilePath}\" --repo-token \"abcdef\"", result.Args);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions Source/Cake.Coveralls.Tests/CoverallsNetRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ internal sealed class CoverallsNetRunnerFixture : ToolFixture<CoverallsNetSettin
public CoverallsNetRunnerFixture()
: base("csmacnz.Coveralls.exe")
{
CodeCoverageReportFilePath = "c:/temp/coverage.xml";
CodeCoverageReportFilePath = FileSystem.GetFile("/temp/coverage.xml").Path.FullPath;
ReportType = CoverallsNetReportType.OpenCover;
}

public FilePath CodeCoverageReportFilePath { get; set; }
public FilePath CodeCoverageReportFilePath { get; private set; }

public CoverallsNetReportType ReportType { get; set; }
public CoverallsNetReportType ReportType { get; }

protected override void RunTool()
{
var tool = new CoverallsNetRunner(FileSystem, Environment, ProcessRunner, Tools);
tool.Run(CodeCoverageReportFilePath, ReportType, Settings);
}

public void WithoutCodeCoverageReportFilePath()
{
CodeCoverageReportFilePath = null;
}
}
}
62 changes: 27 additions & 35 deletions Source/Cake.Coveralls.Tests/CoverallsNetRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void Should_Throw_If_CoverallsNet_Executable_Was_Not_Found()
}

[Theory]
[WindowsOnlyInlineData("C:/CoverallsNet/csmacnz.Coveralls.exe", "C:/CoverallsNet/csmacnz.Coveralls.exe")]
[InlineData("/bin/tools/CoverallsNet/csmacnz.Coveralls.exe", "/bin/tools/CoverallsNet/csmacnz.Coveralls.exe")]
[InlineData("./tools/CoverallsNet/csmacnz.Coveralls.exe", "/Working/tools/CoverallsNet/csmacnz.Coveralls.exe")]
public void Should_Use_CoverallsNet_Runner_From_Tool_Path_If_Provided(string toolPath, string expected)
Expand All @@ -55,21 +56,6 @@ public void Should_Use_CoverallsNet_Runner_From_Tool_Path_If_Provided(string too
Assert.Equal(expected, result.Path.FullPath);
}

[Theory]
[InlineData("C:/CoverallsNet/csmacnz.Coveralls.exe", "C:/CoverallsNet/csmacnz.Coveralls.exe")]
public void Should_Use_CoverallsNet_Runner_From_Tool_Path_If_Provided_On_Windows(string toolPath, string expected)
{
// Given
var fixture = new CoverallsNetRunnerFixture { Settings = { ToolPath = toolPath } };
fixture.GivenSettingsToolPathExist();

// When
var result = fixture.Run();

// Then
Assert.Equal(expected, result.Path.FullPath);
}

[Fact]
public void Should_Find_CoverallsNet_Runner_If_Tool_Path_Not_Provided()
{
Expand All @@ -88,7 +74,7 @@ public void Should_Throw_If_Code_Coverage_File_Path_Is_Null()
{
// Given
var fixture = new CoverallsNetRunnerFixture();
fixture.CodeCoverageReportFilePath = null;
fixture.WithoutCodeCoverageReportFilePath();

// When
var result = Record.Exception(() => fixture.Run());
Expand Down Expand Up @@ -141,17 +127,20 @@ public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code()
Assert.Equal("CoverallsNet: Process returned an error (exit code 1).", result.Message);
}

[Fact]
public void Should_Set_Output_File_Path()
[Theory]
[WindowsOnlyInlineData("c:/temp/output.xml", "c:/temp/output.xml")]
[InlineData("/temp/output.xml", "/temp/output.xml")]
[InlineData("./temp/output.xml", "/Working/temp/output.xml")]
public void Should_Set_Output_File_Path(string path, string expected)
{
// Given
var fixture = new CoverallsNetRunnerFixture { Settings = { OutputFilePath = "c:/temp/output.xml" } };
var fixture = new CoverallsNetRunnerFixture { Settings = { OutputFilePath = path } };

// When
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --output \"c:/temp/output.xml\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --output \"{expected}\"", result.Args);
}

[Fact]
Expand All @@ -164,20 +153,23 @@ public void Should_Set_Use_Relative_Paths()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --useRelativePaths", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --useRelativePaths", result.Args);
}

[Fact]
public void Should_Set_Base_File_Path()
[Theory]
[WindowsOnlyInlineData("c:/temp", "c:/temp")]
[InlineData("/temp", "/temp")]
[InlineData("./temp", "/Working/temp")]
public void Should_Set_Base_File_Path(string path, string expected)
{
// Given
var fixture = new CoverallsNetRunnerFixture { Settings = { BaseFilePath = "c:/temp" } };
var fixture = new CoverallsNetRunnerFixture { Settings = { BaseFilePath = path } };

// When
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --basePath \"c:/temp\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --basePath \"{expected}\"", result.Args);
}

[Fact]
Expand All @@ -190,7 +182,7 @@ public void Should_Set_Repo_Token()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --repoToken \"abcdef\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --repoToken \"abcdef\"", result.Args);
}

[Fact]
Expand All @@ -203,7 +195,7 @@ public void Should_Set_Repo_Token_Variable()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --repoTokenVariable \"COVERALLS_REPO_TOKEN\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --repoTokenVariable \"COVERALLS_REPO_TOKEN\"", result.Args);
}

[Fact]
Expand All @@ -216,7 +208,7 @@ public void Should_Set_Commit_Id()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --commitId \"123456\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --commitId \"123456\"", result.Args);
}

[Fact]
Expand All @@ -229,7 +221,7 @@ public void Should_Set_Commit_Branch()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --commitBranch \"master\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --commitBranch \"master\"", result.Args);
}

[Fact]
Expand All @@ -242,7 +234,7 @@ public void Should_Set_Commit_Author()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --commitAuthor \"gep13\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --commitAuthor \"gep13\"", result.Args);
}

[Fact]
Expand All @@ -255,7 +247,7 @@ public void Should_Set_Commit_Email()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --commitEmail \"[email protected]\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --commitEmail \"[email protected]\"", result.Args);
}

[Fact]
Expand All @@ -268,7 +260,7 @@ public void Should_Set_Commit_Message()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --commitMessage \"boom!\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --commitMessage \"boom!\"", result.Args);
}

[Fact]
Expand All @@ -281,7 +273,7 @@ public void Should_Set_Job_Id()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --jobId 123456", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --jobId 123456", result.Args);
}

[Fact]
Expand All @@ -294,7 +286,7 @@ public void Should_Set_Service_Name()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --serviceName \"coveralls.net\"", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --serviceName \"coveralls.net\"", result.Args);
}

[Fact]
Expand All @@ -307,7 +299,7 @@ public void Should_Set_Treat_Upload_Errors_As_Warnings()
var result = fixture.Run();

// Then
Assert.Equal("--opencover --input \"c:/temp/coverage.xml\" --treatUploadErrorsAsWarnings", result.Args);
Assert.Equal($"--opencover --input \"{fixture.CodeCoverageReportFilePath}\" --treatUploadErrorsAsWarnings", result.Args);
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions Source/Cake.Coveralls.Tests/WindowsOnlyInlineData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit.Sdk;

namespace Cake.Coveralls.Tests
{
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public class WindowsOnlyInlineDataAttribute : DataAttribute
{
private readonly object[] data;

/// <summary>
/// Initializes a new instance of the <see cref="WindowsOnlyInlineDataAttribute" /> class.
/// </summary>
/// <param name="data">The data values to pass to the theory.</param>
public WindowsOnlyInlineDataAttribute(params object[] data)
{
this.data = data;
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Skip = "This test only runs on Windows.";
}
}

/// <inheritdoc />
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
return new[]
{
data,
};
}
}
}
Loading