-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added minimum coverage thresholds to validate coverage goals
- Loading branch information
1 parent
5fe2b28
commit 7bf6158
Showing
12 changed files
with
302 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
|
||
namespace Palmmedia.ReportGenerator.Core | ||
{ | ||
/// <summary> | ||
/// Exception indicating that mimimum coverage goals are not satisfied. | ||
/// </summary> | ||
[Serializable] | ||
internal class LowCoverageException : Exception | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LowCoverageException"/> class. | ||
/// </summary> | ||
public LowCoverageException() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LowCoverageException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
public LowCoverageException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LowCoverageException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <param name="inner">The inner exception.</param> | ||
public LowCoverageException(string message, Exception inner) | ||
: base(message, inner) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Palmmedia.ReportGenerator.Core | ||
{ | ||
/// <summary> | ||
/// Minimum coverage thresholds. | ||
/// </summary> | ||
public class MinimumCoverageThresholds | ||
{ | ||
/// <summary> | ||
/// Gets or sets minimum line coverage. If line coverage falls below this treshold, ReportGenerator will exit unsuccessfully. | ||
/// </summary> | ||
public int? LineCoverage { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets minimum branch coverage. If branch coverage falls below this treshold, ReportGenerator will exit unsuccessfully. | ||
/// </summary> | ||
public int? BranchCoverage { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets minimum method coverage. If method coverage falls below this treshold, ReportGenerator will exit unsuccessfully. | ||
/// </summary> | ||
public int? MethodCoverage { get; set; } | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/ReportGenerator.Core/MinimumCoverageThresholdsValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Palmmedia.ReportGenerator.Core.Parser; | ||
using Palmmedia.ReportGenerator.Core.Parser.Analysis; | ||
using Palmmedia.ReportGenerator.Core.Properties; | ||
|
||
namespace Palmmedia.ReportGenerator.Core | ||
{ | ||
public class MinimumCoverageThresholdsValidator | ||
Check warning on line 9 in src/ReportGenerator.Core/MinimumCoverageThresholdsValidator.cs GitHub Actions / build
|
||
{ | ||
/// <summary> | ||
/// The minimum coverage thresholds. | ||
/// </summary> | ||
private readonly MinimumCoverageThresholds minimumCoverageThresholds; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MinimumCoverageThresholdsValidator" /> class. | ||
/// </summary> | ||
/// <param name="minimumCoverageThresholds">The minimum coverage thresholds.</param> | ||
public MinimumCoverageThresholdsValidator(MinimumCoverageThresholds minimumCoverageThresholds) | ||
{ | ||
if (minimumCoverageThresholds == null) | ||
{ | ||
throw new ArgumentNullException(nameof(minimumCoverageThresholds)); | ||
} | ||
|
||
this.minimumCoverageThresholds = minimumCoverageThresholds; | ||
} | ||
|
||
/// <summary> | ||
/// Validates the coverage thresholds. | ||
/// </summary> | ||
/// <param name="parserResult">The parser result.</param> | ||
public void Validate(ParserResult parserResult) | ||
{ | ||
if (!this.minimumCoverageThresholds.LineCoverage.HasValue | ||
&& !this.minimumCoverageThresholds.BranchCoverage.HasValue | ||
&& !this.minimumCoverageThresholds.MethodCoverage.HasValue) | ||
{ | ||
return; | ||
} | ||
|
||
var errors = new List<string>(); | ||
|
||
var summaryResult = new SummaryResult(parserResult); | ||
|
||
if (this.minimumCoverageThresholds.LineCoverage.HasValue | ||
&& summaryResult.CoverageQuota.HasValue | ||
&& summaryResult.CoverageQuota.Value < this.minimumCoverageThresholds.LineCoverage.Value) | ||
{ | ||
errors.Add(string.Format(Resources.ErrorLowLineCoverage, summaryResult.CoverageQuota.Value, this.minimumCoverageThresholds.LineCoverage.Value)); | ||
} | ||
|
||
if (this.minimumCoverageThresholds.BranchCoverage.HasValue | ||
&& summaryResult.BranchCoverageQuota.HasValue | ||
&& summaryResult.BranchCoverageQuota.Value < this.minimumCoverageThresholds.BranchCoverage.Value) | ||
{ | ||
errors.Add(string.Format(Resources.ErrorLowBranchCoverage, summaryResult.BranchCoverageQuota.Value, this.minimumCoverageThresholds.BranchCoverage.Value)); | ||
} | ||
|
||
if (this.minimumCoverageThresholds.MethodCoverage.HasValue | ||
&& summaryResult.CodeElementCoverageQuota.HasValue | ||
&& summaryResult.CodeElementCoverageQuota < this.minimumCoverageThresholds.MethodCoverage.Value) | ||
{ | ||
errors.Add(string.Format(Resources.ErrorLowMethodCoverage, summaryResult.CodeElementCoverageQuota.Value, this.minimumCoverageThresholds.MethodCoverage.Value)); | ||
} | ||
|
||
if (errors.Count > 0) | ||
{ | ||
throw new LowCoverageException(string.Join("\r\n", errors)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.