|
|
|
@ -58,6 +58,7 @@ namespace ICSharpCode.CodeCoverage
@@ -58,6 +58,7 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
|
|
|
|
|
public string FileID { get; private set; } |
|
|
|
|
public string FileName { get; private set; } |
|
|
|
|
public string FileNameExt { get; private set; } |
|
|
|
|
public bool IsVisited { get; private set; } |
|
|
|
|
public int CyclomaticComplexity { get; private set; } |
|
|
|
|
public decimal SequenceCoverage { get; private set; } |
|
|
|
@ -86,9 +87,14 @@ namespace ICSharpCode.CodeCoverage
@@ -86,9 +87,14 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
|
|
|
|
|
this.FileID = GetFileRef(); |
|
|
|
|
this.FileName = String.Empty; |
|
|
|
|
this.FileNameExt = String.Empty; |
|
|
|
|
if (!String.IsNullOrEmpty(this.FileID)) { |
|
|
|
|
if (results != null) { |
|
|
|
|
this.FileName = results.GetFileName(this.FileID); |
|
|
|
|
try { |
|
|
|
|
this.FileNameExt = Path.GetExtension(this.FileName).ToLowerInvariant(); |
|
|
|
|
} |
|
|
|
|
catch {} |
|
|
|
|
if (cacheFileName != this.FileName) { |
|
|
|
|
cacheFileName = this.FileName; |
|
|
|
|
cacheDocument = GetSource (cacheFileName); |
|
|
|
@ -220,6 +226,7 @@ namespace ICSharpCode.CodeCoverage
@@ -220,6 +226,7 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
// -> this method SP with lowest Line/Column
|
|
|
|
|
void getBodyStartSP() { |
|
|
|
|
if (this.SequencePoints.Count != 0) { |
|
|
|
|
if (this.FileNameExt == ".cs") { |
|
|
|
|
foreach (CodeCoverageSequencePoint sp in this.SequencePoints) { |
|
|
|
|
if (sp.FileID != this.FileID) continue; |
|
|
|
|
if (this.BodyStartSP == null || (sp.Line < this.BodyStartSP.Line) || |
|
|
|
@ -229,6 +236,10 @@ namespace ICSharpCode.CodeCoverage
@@ -229,6 +236,10 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.BodyStartSP = this.SequencePoints.First(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Find method-body last SequencePoint
|
|
|
|
@ -236,6 +247,7 @@ namespace ICSharpCode.CodeCoverage
@@ -236,6 +247,7 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
// and lowest Offset (when duplicated bw ccrewrite)
|
|
|
|
|
void getBodyFinalSP() { |
|
|
|
|
if (this.SequencePoints.Count != 0) { |
|
|
|
|
if (this.FileNameExt == ".cs") { |
|
|
|
|
for (int i = this.SequencePoints.Count-1; i > 0; i--) { |
|
|
|
|
var sp = this.SequencePoints[i]; |
|
|
|
|
if (sp.FileID != this.FileID) continue; |
|
|
|
@ -260,6 +272,10 @@ namespace ICSharpCode.CodeCoverage
@@ -260,6 +272,10 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.BodyFinalSP = this.SequencePoints.Last(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int GetSequencePointsCount() { |
|
|
|
@ -273,6 +289,9 @@ namespace ICSharpCode.CodeCoverage
@@ -273,6 +289,9 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const string @assert = "Assert"; |
|
|
|
|
const string @contract = "Contract"; |
|
|
|
|
|
|
|
|
|
void GetBranchRatio () { |
|
|
|
|
|
|
|
|
|
this.BranchCoverageRatio = null; |
|
|
|
@ -295,8 +314,11 @@ namespace ICSharpCode.CodeCoverage
@@ -295,8 +314,11 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
// SequencePoint is visited and belongs to this method?
|
|
|
|
|
if (sp.VisitCount != 0 && sp.FileID == this.FileID) { |
|
|
|
|
|
|
|
|
|
if (this.FileNameExt == ".cs") { |
|
|
|
|
// Only for C#
|
|
|
|
|
|
|
|
|
|
// Don't want branch coverage of ccrewrite(n)
|
|
|
|
|
// SequencePoint's with offset before and after method body
|
|
|
|
|
// SequencePoint(s) with offset before and after method body
|
|
|
|
|
if (sp.Offset < BodyStartSP.Offset || |
|
|
|
|
sp.Offset > BodyFinalSP.Offset) { |
|
|
|
|
sp.BranchCoverage = true; |
|
|
|
@ -310,17 +332,16 @@ namespace ICSharpCode.CodeCoverage
@@ -310,17 +332,16 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
// ie: static methods start sequence point "{" contains compiler generated branches
|
|
|
|
|
// 3) Exclude Contract class (EnsuresOnThrow/Assert/Assume is inside method body)
|
|
|
|
|
// 4) Exclude NUnit Assert(.Throws) class
|
|
|
|
|
const string assert = "Assert"; |
|
|
|
|
const string contract = "Contract"; |
|
|
|
|
if (sp.Content == "in" || sp.Content == "{" || sp.Content == "}" || |
|
|
|
|
sp.Content.StartsWith(assert + ".", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(assert + " ", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(contract + ".", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(contract + " ", StringComparison.Ordinal) |
|
|
|
|
sp.Content.StartsWith(@assert + ".", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(@assert + " ", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(@contract + ".", StringComparison.Ordinal) || |
|
|
|
|
sp.Content.StartsWith(@contract + " ", StringComparison.Ordinal) |
|
|
|
|
) { |
|
|
|
|
sp.BranchCoverage = true; |
|
|
|
|
continue; // skip
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
totalBranchCount += sp.BranchExitsCount; |
|
|
|
|
totalBranchVisit += sp.BranchExitsVisit; |
|
|
|
|