Browse Source

CodeCoverage: Apply C# filter only to .cs files

pull/495/head
Dragan 11 years ago
parent
commit
164af14443
  1. 43
      src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

43
src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs

@ -58,6 +58,7 @@ namespace ICSharpCode.CodeCoverage
public string FileID { get; private set; } public string FileID { get; private set; }
public string FileName { get; private set; } public string FileName { get; private set; }
public string FileNameExt { get; private set; }
public bool IsVisited { get; private set; } public bool IsVisited { get; private set; }
public int CyclomaticComplexity { get; private set; } public int CyclomaticComplexity { get; private set; }
public decimal SequenceCoverage { get; private set; } public decimal SequenceCoverage { get; private set; }
@ -86,9 +87,14 @@ namespace ICSharpCode.CodeCoverage
this.FileID = GetFileRef(); this.FileID = GetFileRef();
this.FileName = String.Empty; this.FileName = String.Empty;
this.FileNameExt = String.Empty;
if (!String.IsNullOrEmpty(this.FileID)) { if (!String.IsNullOrEmpty(this.FileID)) {
if (results != null) { if (results != null) {
this.FileName = results.GetFileName(this.FileID); this.FileName = results.GetFileName(this.FileID);
try {
this.FileNameExt = Path.GetExtension(this.FileName);
}
catch {}
if (cacheFileName != this.FileName) { if (cacheFileName != this.FileName) {
cacheFileName = this.FileName; cacheFileName = this.FileName;
cacheDocument = GetSource (cacheFileName); cacheDocument = GetSource (cacheFileName);
@ -303,23 +309,26 @@ namespace ICSharpCode.CodeCoverage
continue; // skip continue; // skip
} }
// 1) Generated "in" code for IEnumerables contains hidden "try/catch/finally" branches that if (this.FileNameExt == ".cs") {
// one do not want or cannot cover by test-case because is handled earlier at same method. // 0) Only for C#
// ie: NullReferenceException in foreach loop is pre-handled at method entry, ie. by Contract.Require(items!=null) // 1) Generated "in" code for IEnumerables contains hidden "try/catch/finally" branches that
// 2) Branches within sequence points "{" and "}" are not source branches but compiler generated branches // one do not want or cannot cover by test-case because is handled earlier at same method.
// ie: static methods start sequence point "{" contains compiler generated branches // ie: NullReferenceException in foreach loop is pre-handled at method entry, ie. by Contract.Require(items!=null)
// 3) Exclude Contract class (EnsuresOnThrow/Assert/Assume is inside method body) // 2) Branches within sequence points "{" and "}" are not source branches but compiler generated branches
// 4) Exclude NUnit Assert(.Throws) class // ie: static methods start sequence point "{" contains compiler generated branches
const string assert = "Assert"; // 3) Exclude Contract class (EnsuresOnThrow/Assert/Assume is inside method body)
const string contract = "Contract"; // 4) Exclude NUnit Assert(.Throws) class
if (sp.Content == "in" || sp.Content == "{" || sp.Content == "}" || const string assert = "Assert";
sp.Content.StartsWith(assert + ".", StringComparison.Ordinal) || const string contract = "Contract";
sp.Content.StartsWith(assert + " ", StringComparison.Ordinal) || if (sp.Content == "in" || sp.Content == "{" || sp.Content == "}" ||
sp.Content.StartsWith(contract + ".", StringComparison.Ordinal) || sp.Content.StartsWith(assert + ".", StringComparison.Ordinal) ||
sp.Content.StartsWith(contract + " ", StringComparison.Ordinal) sp.Content.StartsWith(assert + " ", StringComparison.Ordinal) ||
) { sp.Content.StartsWith(contract + ".", StringComparison.Ordinal) ||
sp.BranchCoverage = true; sp.Content.StartsWith(contract + " ", StringComparison.Ordinal)
continue; // skip ) {
sp.BranchCoverage = true;
continue; // skip
}
} }
totalBranchCount += sp.BranchExitsCount; totalBranchCount += sp.BranchExitsCount;

Loading…
Cancel
Save