@@ -49,35 +49,90 @@ public CoverageResult GetCoverageResult()
4949 Documents documents = new Documents ( ) ;
5050 foreach ( var doc in result . Documents )
5151 {
52+ // Construct Line Results
5253 foreach ( var line in doc . Lines )
5354 {
5455 if ( documents . TryGetValue ( doc . Path , out Classes classes ) )
5556 {
5657 if ( classes . TryGetValue ( line . Class , out Methods methods ) )
5758 {
58- if ( methods . TryGetValue ( line . Method , out Lines lines ) )
59+ if ( methods . TryGetValue ( line . Method , out Method method ) )
5960 {
60- documents [ doc . Path ] [ line . Class ] [ line . Method ] . Add ( line . Number , new LineInfo { Hits = line . Hits , IsBranchPoint = line . IsBranchTarget } ) ;
61+ documents [ doc . Path ] [ line . Class ] [ line . Method ] . Lines . Add ( line . Number , new LineInfo { Hits = line . Hits } ) ;
6162 }
6263 else
6364 {
64- documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Lines ( ) ) ;
65- documents [ doc . Path ] [ line . Class ] [ line . Method ] . Add ( line . Number , new LineInfo { Hits = line . Hits , IsBranchPoint = line . IsBranchTarget } ) ;
65+ documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Method ( ) ) ;
66+ documents [ doc . Path ] [ line . Class ] [ line . Method ] . Lines . Add ( line . Number , new LineInfo { Hits = line . Hits } ) ;
6667 }
6768 }
6869 else
6970 {
7071 documents [ doc . Path ] . Add ( line . Class , new Methods ( ) ) ;
71- documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Lines ( ) ) ;
72- documents [ doc . Path ] [ line . Class ] [ line . Method ] . Add ( line . Number , new LineInfo { Hits = line . Hits , IsBranchPoint = line . IsBranchTarget } ) ;
72+ documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Method ( ) ) ;
73+ documents [ doc . Path ] [ line . Class ] [ line . Method ] . Lines . Add ( line . Number , new LineInfo { Hits = line . Hits } ) ;
7374 }
7475 }
7576 else
7677 {
7778 documents . Add ( doc . Path , new Classes ( ) ) ;
7879 documents [ doc . Path ] . Add ( line . Class , new Methods ( ) ) ;
79- documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Lines ( ) ) ;
80- documents [ doc . Path ] [ line . Class ] [ line . Method ] . Add ( line . Number , new LineInfo { Hits = line . Hits , IsBranchPoint = line . IsBranchTarget } ) ;
80+ documents [ doc . Path ] [ line . Class ] . Add ( line . Method , new Method ( ) ) ;
81+ documents [ doc . Path ] [ line . Class ] [ line . Method ] . Lines . Add ( line . Number , new LineInfo { Hits = line . Hits } ) ;
82+ }
83+ }
84+
85+ // Construct Branch Results
86+ foreach ( var branch in doc . Branches )
87+ {
88+ if ( documents . TryGetValue ( doc . Path , out Classes classes ) )
89+ {
90+ if ( classes . TryGetValue ( branch . Class , out Methods methods ) )
91+ {
92+ if ( methods . TryGetValue ( branch . Method , out Method method ) )
93+ {
94+ if ( method . Branches . TryGetValue ( branch . Number , out List < BranchInfo > branchInfo ) )
95+ {
96+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches [ branch . Number ] . Add ( new BranchInfo
97+ { Hits = branch . Hits , Offset = branch . Offset , EndOffset = branch . EndOffset , Path = branch . Path , Ordinal = branch . Ordinal }
98+ ) ;
99+ }
100+ else
101+ {
102+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches . Add ( branch . Number , new List < BranchInfo > ( ) ) ;
103+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches [ branch . Number ] . Add ( new BranchInfo
104+ { Hits = branch . Hits , Offset = branch . Offset , EndOffset = branch . EndOffset , Path = branch . Path , Ordinal = branch . Ordinal }
105+ ) ;
106+ }
107+ }
108+ else
109+ {
110+ documents [ doc . Path ] [ branch . Class ] . Add ( branch . Method , new Method ( ) ) ;
111+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches . Add ( branch . Number , new List < BranchInfo > ( ) ) ;
112+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches [ branch . Number ] . Add ( new BranchInfo
113+ { Hits = branch . Hits , Offset = branch . Offset , EndOffset = branch . EndOffset , Path = branch . Path , Ordinal = branch . Ordinal }
114+ ) ;
115+ }
116+ }
117+ else
118+ {
119+ documents [ doc . Path ] . Add ( branch . Class , new Methods ( ) ) ;
120+ documents [ doc . Path ] [ branch . Class ] . Add ( branch . Method , new Method ( ) ) ;
121+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches . Add ( branch . Number , new List < BranchInfo > ( ) ) ;
122+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches [ branch . Number ] . Add ( new BranchInfo
123+ { Hits = branch . Hits , Offset = branch . Offset , EndOffset = branch . EndOffset , Path = branch . Path , Ordinal = branch . Ordinal }
124+ ) ;
125+ }
126+ }
127+ else
128+ {
129+ documents . Add ( doc . Path , new Classes ( ) ) ;
130+ documents [ doc . Path ] . Add ( branch . Class , new Methods ( ) ) ;
131+ documents [ doc . Path ] [ branch . Class ] . Add ( branch . Method , new Method ( ) ) ;
132+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches . Add ( branch . Number , new List < BranchInfo > ( ) ) ;
133+ documents [ doc . Path ] [ branch . Class ] [ branch . Method ] . Branches [ branch . Number ] . Add ( new BranchInfo
134+ { Hits = branch . Hits , Offset = branch . Offset , EndOffset = branch . EndOffset , Path = branch . Path , Ordinal = branch . Ordinal }
135+ ) ;
81136 }
82137 }
83138 }
@@ -99,28 +154,37 @@ private void CalculateCoverage()
99154 {
100155 if ( ! File . Exists ( result . HitsFilePath ) ) { continue ; }
101156 var lines = InstrumentationHelper . ReadHitsFile ( result . HitsFilePath ) ;
102- foreach ( var line in lines )
157+ foreach ( var row in lines )
103158 {
104- var info = line . Split ( ',' ) ;
159+ var info = row . Split ( ',' ) ;
105160 // Ignore malformed lines
106161 if ( info . Length != 4 )
107162 continue ;
108163
109- var document = result . Documents . FirstOrDefault ( d => d . Path == info [ 0 ] ) ;
164+ bool isBranch = info [ 0 ] == "B" ;
165+
166+ var document = result . Documents . FirstOrDefault ( d => d . Path == info [ 1 ] ) ;
110167 if ( document == null )
111168 continue ;
112169
113- int start = int . Parse ( info [ 1 ] ) ;
114- int end = int . Parse ( info [ 2 ] ) ;
115- bool target = info [ 3 ] == "B" ;
170+ int start = int . Parse ( info [ 2 ] ) ;
116171
117- for ( int j = start ; j <= end ; j ++ )
172+ if ( isBranch )
118173 {
119- var subLine = document . Lines . First ( l => l . Number == j ) ;
120- subLine . Hits = subLine . Hits + 1 ;
121-
122- if ( j == start )
123- subLine . IsBranchTarget = target ;
174+ uint ordinal = uint . Parse ( info [ 3 ] ) ;
175+ var branch = document . Branches . First ( b => b . Number == start && b . Ordinal == ordinal ) ;
176+ if ( branch . Hits != int . MaxValue )
177+ branch . Hits += branch . Hits + 1 ;
178+ }
179+ else
180+ {
181+ int end = int . Parse ( info [ 3 ] ) ;
182+ for ( int j = start ; j <= end ; j ++ )
183+ {
184+ var line = document . Lines . First ( l => l . Number == j ) ;
185+ if ( line . Hits != int . MaxValue )
186+ line . Hits = line . Hits + 1 ;
187+ }
124188 }
125189 }
126190
0 commit comments