From f155f11fc385a26c81fd1310f8b6792239271d82 Mon Sep 17 00:00:00 2001 From: Dragan Date: Tue, 28 Jan 2014 13:49:47 +0100 Subject: [PATCH] CodeCoverage: Exclude ccrewrite(n) sequence points After ccrewrite ContractClass/ContractClassFor sequence point(s) from another file/class/method is inserted into this method sequence points --- .../Project/Src/CodeCoverageMethodElement.cs | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs b/src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs index 4e7c92adea..b696d1a88e 100644 --- a/src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs +++ b/src/AddIns/Analysis/CodeCoverage/Project/Src/CodeCoverageMethodElement.cs @@ -121,6 +121,46 @@ namespace ICSharpCode.CodeCoverage sps.Add(sp); } + + if (sps.Count > 2) { + + // After ccrewrite ContractClass/ContractClassFor + // sequence point(s) from another file/class/method + // is inserted into this method sequence points + // + // To remove alien sequence points, all points + // before and after method brackets {} are removed + + CodeCoverageSequencePoint startSP = getBodyStartSP(sps); + if (Object.ReferenceEquals(null, startSP)) { return sps; } + CodeCoverageSequencePoint finalSP = getBodyFinalSP(sps); + if (Object.ReferenceEquals(null, finalSP)) { return sps; } + + List selected = new List(); + foreach (var point in sps) { + if ( + (point.Line > startSP.Line || (point.Line == startSP.Line && point.Column >= startSP.Column)) && + (point.Line < finalSP.Line || (point.Line == finalSP.Line && point.Column < finalSP.Column)) + ) { + selected.Add (point); + } + // After ccrewrite ContractClass/ContractClassFor + // duplicate method end-sequence-point (}) is added + // + // Add(point) and Break on first (duplicate) finalSP + // Note: IL.Offset of second duplicate finalSP will + // extend branch coverage outside method-end "}", + // and that can lead to wrong branch coverage report! + if (point.Line == finalSP.Line && point.Column == finalSP.Column) { + selected.Add (point); + break; + } + } + + sps = selected; + sps.OrderBy(item => item.Line).OrderBy(item => item.Column); + + } return sps; } @@ -153,15 +193,18 @@ namespace ICSharpCode.CodeCoverage } // Find method-body start SequencePoint "{" - public static CodeCoverageSequencePoint getBodyStartSP(IEnumerable sps) { + public static CodeCoverageSequencePoint getBodyStartSP(IEnumerable sPoints) { CodeCoverageSequencePoint startSeqPoint = null; - foreach (CodeCoverageSequencePoint sp in sps) { - if ( sp.Content == "{") { - startSeqPoint = sp; + bool startFound = false; + foreach (CodeCoverageSequencePoint sPoint in sPoints) { + if ( sPoint.Content == "{") { + if (startSeqPoint == null) startSeqPoint = sPoint; + startFound = true; break; } + startSeqPoint = sPoint; } - return startSeqPoint; + return startFound == true? startSeqPoint : null; } // Find method-body final SequencePoint "}"