Skip to content

Commit 356bf27

Browse files
author
Paulo Barbosa
committed
Resolve discussions
1 parent 29aaeb8 commit 356bf27

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

Diff for: src/coverlet.console/Program.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,14 @@ static int Main(string[] args)
208208

209209
foreach (var thresholdValue in thresholdValues)
210210
{
211-
thresholdTypeFlagValues[thresholdTypeFlagQueue.Dequeue()] = double.Parse(thresholdValue);
211+
if (double.TryParse(thresholdValue, out var value))
212+
{
213+
thresholdTypeFlagValues[thresholdTypeFlagQueue.Dequeue()] = value;
214+
}
215+
else
216+
{
217+
throw new Exception($"Invalid threshold value must be numeric");
218+
}
212219
}
213220
}
214221
else

Diff for: src/coverlet.core/CoverageResult.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,22 @@ public ThresholdTypeFlags GetThresholdTypesBelowThreshold(CoverageSummary summar
149149
double line = summary.CalculateLineCoverage(Modules).AverageModulePercent;
150150
double branch = summary.CalculateBranchCoverage(Modules).AverageModulePercent;
151151
double method = summary.CalculateMethodCoverage(Modules).AverageModulePercent;
152-
var numModules = Modules.Count;
153-
152+
154153
if ((thresholdTypes & ThresholdTypeFlags.Line) != ThresholdTypeFlags.None)
155154
{
156-
if ((line / numModules) < thresholdTypeFlagValues[ThresholdTypeFlags.Line])
155+
if (line < thresholdTypeFlagValues[ThresholdTypeFlags.Line])
157156
thresholdTypeFlags |= ThresholdTypeFlags.Line;
158157
}
159158

160159
if ((thresholdTypes & ThresholdTypeFlags.Branch) != ThresholdTypeFlags.None)
161160
{
162-
if ((branch / numModules) < thresholdTypeFlagValues[ThresholdTypeFlags.Branch])
161+
if (branch < thresholdTypeFlagValues[ThresholdTypeFlags.Branch])
163162
thresholdTypeFlags |= ThresholdTypeFlags.Branch;
164163
}
165164

166165
if ((thresholdTypes & ThresholdTypeFlags.Method) != ThresholdTypeFlags.None)
167166
{
168-
if ((method / numModules) < thresholdTypeFlagValues[ThresholdTypeFlags.Method])
167+
if (method < thresholdTypeFlagValues[ThresholdTypeFlags.Method])
169168
thresholdTypeFlags |= ThresholdTypeFlags.Method;
170169
}
171170
}

Diff for: src/coverlet.msbuild.tasks/CoverageResultTask.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ public override bool Execute()
157157

158158
foreach (var threshold in thresholdValues)
159159
{
160-
thresholdTypeFlagValues[thresholdTypeFlagQueue.Dequeue()] = double.Parse(threshold);
160+
if (double.TryParse(threshold, out var value))
161+
{
162+
thresholdTypeFlagValues[thresholdTypeFlagQueue.Dequeue()] = value;
163+
}
164+
else
165+
{
166+
throw new Exception($"Invalid threshold value must be numeric");
167+
}
161168
}
162169
}
163170
else
@@ -182,7 +189,6 @@ public override bool Execute()
182189

183190
var coverageTable = new ConsoleTable("Module", "Line", "Branch", "Method");
184191
var summary = new CoverageSummary();
185-
int numModules = result.Modules.Count;
186192

187193
var linePercentCalculation = summary.CalculateLineCoverage(result.Modules);
188194
var branchPercentCalculation = summary.CalculateBranchCoverage(result.Modules);

0 commit comments

Comments
 (0)