Skip to content

Commit

Permalink
GH-2703: Add hideskipped option for OpenCover
Browse files Browse the repository at this point in the history
* fixes #2703
  • Loading branch information
Aditya Shrotri authored and devlead committed Sep 7, 2020
1 parent ef06dd2 commit b67bc59
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Cake.Common.Tests/Unit/Tools/OpenCover/OpenCoverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,27 @@ public void Should_Append_LogLevel()
"-log:All", result.Args);
}

[Fact]
public void Should_Append_HideSkipped()
{
// Given
var fixture = new OpenCoverFixture();
fixture.Settings.HideSkippedOption = OpenCoverHideSkippedOption.File
| OpenCoverHideSkippedOption.MissingPdb
| OpenCoverHideSkippedOption.Filter
| OpenCoverHideSkippedOption.All
| OpenCoverHideSkippedOption.Attribute;

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

// Then
Assert.Equal("-target:\"/Working/tools/Test.exe\" " +
"-targetargs:\"-argument\" " +
"-register:user -output:\"/Working/result.xml\" " +
"-hideskipped:All", result.Args);
}

[Fact]
public void Should_Append_MergeByHash()
{
Expand Down
45 changes: 45 additions & 0 deletions src/Cake.Common/Tools/OpenCover/OpenCoverHideSkippedOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Cake.Common.Tools.OpenCover
{
using System;

/// <summary>
/// Represents the hide skipped option for OpenCover.
/// </summary>
[Flags]
public enum OpenCoverHideSkippedOption
{
/// <summary>
/// Removes no information from output file.
/// </summary>
None = 0,

/// <summary>
/// Removes information from output files that relates to classes/modules that have been skipped (filtered) due to use of the -excludebyfile -switch.
/// </summary>
File = 1,

/// <summary>
/// Removes information from output files that relates to classes/modules that have been skipped (filtered) due to use of the -filter -switch.
/// </summary>
Filter = 2,

/// <summary>
/// Removes information from output files that relates to classes/modules that have been skipped (filtered) due to use of the -excludebyattribute -switch.
/// </summary>
Attribute = 4,

/// <summary>
/// Removes missing Pdb information from output file.
/// </summary>
MissingPdb = 8,

/// <summary>
/// Removes all information from output file.
/// </summary>
All = File | Filter | Attribute | MissingPdb
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Cake.Common.Tools.OpenCover
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

/// <summary>
/// Extensions class for <see cref="OpenCoverHideSkippedOption"/>.
/// </summary>
public static class OpenCoverHideSkippedOptionExtensions
{
/// <summary>
/// Get flags.
/// </summary>
/// <param name="openCoverHideSkippedOption">
/// The input.
/// </param>
/// <returns>
/// The <see cref="IEnumerable"/>.
/// </returns>
public static IEnumerable<OpenCoverHideSkippedOption> GetFlags(this OpenCoverHideSkippedOption openCoverHideSkippedOption)
{
foreach (OpenCoverHideSkippedOption value in Enum.GetValues(openCoverHideSkippedOption.GetType()))
{
if (openCoverHideSkippedOption.HasFlag(value))
{
yield return value;
}
}
}
}
}
15 changes: 15 additions & 0 deletions src/Cake.Common/Tools/OpenCover/OpenCoverRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Cake.Common.Tools.OpenCover
/// </summary>
public sealed class OpenCoverRunner : Tool<OpenCoverSettings>
{
private const string HideSkippedConstant = "-hideskipped";
private readonly ICakeEnvironment _environment;

/// <summary>
Expand Down Expand Up @@ -165,6 +166,20 @@ private ProcessArgumentBuilder GetArguments(
builder.AppendSwitch("-log", ":", settings.LogLevel.ToString());
}

// HideSkipped Option
if (settings.HideSkippedOption != OpenCoverHideSkippedOption.None)
{
if (settings.HideSkippedOption == OpenCoverHideSkippedOption.All)
{
builder.AppendSwitch(HideSkippedConstant, ":", "All");
}
else
{
var hideSkippedOptions = string.Join(";", settings.HideSkippedOption.GetFlags());
builder.AppendSwitch(HideSkippedConstant, ":", hideSkippedOptions);
}
}

// Merge by hash
if (settings.MergeByHash)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Cake.Common/Tools/OpenCover/OpenCoverSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public sealed class OpenCoverSettings : ToolSettings
/// </summary>
public OpenCoverLogLevel LogLevel { get; set; }

/// <summary>
/// Gets or sets the hide skipped option of OpenCover.
/// </summary>
public OpenCoverHideSkippedOption HideSkippedOption { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to merge the coverage results for an assembly
/// regardless of where it was loaded assuming it has the same file-hash in each location.
Expand Down Expand Up @@ -115,6 +120,7 @@ public OpenCoverSettings()
_excludedFileFilters = new HashSet<string>(StringComparer.Ordinal);
Register = "user";
LogLevel = OpenCoverLogLevel.Info;
HideSkippedOption = OpenCoverHideSkippedOption.None;
_excludeDirectories = new HashSet<DirectoryPath>();
_searchDirectories = new HashSet<DirectoryPath>();
}
Expand Down

0 comments on commit b67bc59

Please sign in to comment.