|
|
|
|
@ -92,7 +92,7 @@ namespace ICSharpCode.CodeCoverage
@@ -92,7 +92,7 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
if (results != null) { |
|
|
|
|
this.FileName = results.GetFileName(this.FileID); |
|
|
|
|
try { |
|
|
|
|
this.FileNameExt = Path.GetExtension(this.FileName); |
|
|
|
|
this.FileNameExt = Path.GetExtension(this.FileName).ToLowerInvariant(); |
|
|
|
|
} |
|
|
|
|
catch {} |
|
|
|
|
if (cacheFileName != this.FileName) { |
|
|
|
|
@ -226,6 +226,7 @@ namespace ICSharpCode.CodeCoverage
@@ -226,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) || |
|
|
|
|
@ -235,6 +236,10 @@ namespace ICSharpCode.CodeCoverage
@@ -235,6 +236,10 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.BodyStartSP = this.SequencePoints.First(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Find method-body last SequencePoint
|
|
|
|
|
@ -242,6 +247,7 @@ namespace ICSharpCode.CodeCoverage
@@ -242,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; |
|
|
|
|
@ -266,6 +272,10 @@ namespace ICSharpCode.CodeCoverage
@@ -266,6 +272,10 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.BodyFinalSP = this.SequencePoints.Last(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int GetSequencePointsCount() { |
|
|
|
|
@ -279,6 +289,9 @@ namespace ICSharpCode.CodeCoverage
@@ -279,6 +289,9 @@ namespace ICSharpCode.CodeCoverage
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const string @assert = "Assert"; |
|
|
|
|
const string @contract = "Contract"; |
|
|
|
|
|
|
|
|
|
void GetBranchRatio () { |
|
|
|
|
|
|
|
|
|
this.BranchCoverageRatio = null; |
|
|
|
|
@ -301,16 +314,17 @@ namespace ICSharpCode.CodeCoverage
@@ -301,16 +314,17 @@ 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; |
|
|
|
|
continue; // skip
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.FileNameExt == ".cs") { |
|
|
|
|
// 0) Only for C#
|
|
|
|
|
// 1) Generated "in" code for IEnumerables contains hidden "try/catch/finally" branches that
|
|
|
|
|
// one do not want or cannot cover by test-case because is handled earlier at same method.
|
|
|
|
|
// ie: NullReferenceException in foreach loop is pre-handled at method entry, ie. by Contract.Require(items!=null)
|
|
|
|
|
@ -318,13 +332,11 @@ namespace ICSharpCode.CodeCoverage
@@ -318,13 +332,11 @@ 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
|
|
|
|
|
|