Skip to content

Commit

Permalink
Fix coverage output
Browse files Browse the repository at this point in the history
  • Loading branch information
dorssel committed Nov 21, 2024
1 parent 80d2427 commit ac71820
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ jobs:
dotnet build --configuration Release --no-restore
- name: Test
run: |
run: >
dotnet run --configuration Release --no-build --project Example
dotnet test --configuration Release --no-build -p:TestingPlatformCommandLineArguments="--report-trx --coverage"
dotnet test --configuration Release --no-build
-p:TestingPlatformCommandLineArguments="--report-trx --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml"
- name: Package
run: dotnet pack --configuration Release --no-build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
.vscode/
bin/
obj/
TestResults/

*.user
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ SPDX-License-Identifier: MIT
<ItemGroup>
<!-- GitVersion.MsBuild -->
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.12.6" />
<!-- UnitTests -->
<PackageVersion Include="Moq" Version="4.20.72" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion GitVersion.MsBuild/GenerateGitVersionInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GenerateGitVersionInformation
[Required]
public string Language { get; set; } = "C#";

public string? UseProjectNamespaceForGitVersionInformation { get; set; } = string.Empty;
public string? UseProjectNamespaceForGitVersionInformation { get; set; }

public string RootNamespace { get; set; } = string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: MIT

# GitVersion.MsBuild (netstandard2.0, Visual Studio compatible)

[![Build](https://github.com/dorssel/gitversion-msbuild/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ABuild+branch%3Amain)
[![Build](https://github.com/dorssel/gitversion-msbuild/actions/workflows/dotnet.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ABuild+branch%3Amain)
[![CodeQL](https://github.com/dorssel/gitversion-msbuild/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ACodeQL+branch%3Amain)
[![Lint](https://github.com/dorssel/gitversion-msbuild/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/dorssel/gitversion-msbuild/actions?query=workflow%3ALint+branch%3Amain)
[![REUSE status](https://api.reuse.software/badge/github.com/dorssel/gitversion-msbuild)](https://api.reuse.software/info/github.com/dorssel/gitversion-msbuild)
Expand Down
123 changes: 121 additions & 2 deletions UnitTests/TaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// SPDX-License-Identifier: MIT

using System.Reflection;
using Dorssel.GitVersion.MsBuild;
using Microsoft.Build.Framework;
using Moq;

namespace UnitTests;

Expand All @@ -25,15 +28,131 @@ static string GetVersionFile()
throw new FileNotFoundException("gitversion.json");
}

[TestMethod]
public void GetVersion_Normal()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GetVersion
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_WithIntermediateOutputPath()
{
var task = new Dorssel.GitVersion.MsBuild.GenerateGitVersionInformation
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UnknownLanguage()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
Language = "Unknown"
};
var result = task.Execute();
Assert.IsFalse(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_Invalid()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
IntermediateOutputPath = TestContext.TestRunDirectory!
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "invalid"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_False()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "false"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_UseProjectNamespaceForGitVersionInformation_True()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "true",
RootNamespace = "Test.Namespace"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_RootNamespace_Empty()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!),
UseProjectNamespaceForGitVersionInformation = "true",
ProjectFile = "TestProject.csproj"
};
var result = task.Execute();
Assert.IsTrue(result);
}

[TestMethod]
public void GenerateGitVersionInformation_Twice()
{
var buildEngine = new Mock<IBuildEngine>();
var task = new GenerateGitVersionInformation
{
BuildEngine = buildEngine.Object,
VersionFile = GetVersionFile(),
SolutionDirectory = TestContext.TestRunDirectory!,
IntermediateOutputPath = Path.Combine(TestContext.TestRunDirectory!, TestContext.TestName!)
};
var result = task.Execute();
Assert.IsTrue(result);
result = task.Execute();
Assert.IsTrue(result);
}
}
1 change: 1 addition & 0 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SPDX-License-Identifier: MIT

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" />
<PackageReference Include="Moq" />
</ItemGroup>

</Project>

0 comments on commit ac71820

Please sign in to comment.