@@ -134,17 +134,19 @@ private static CodeSummary ParseTestResults(string filename)
134134 var packages = from item in coverage . Descendants ( "package" )
135135 select item ;
136136
137+ int i = 1 ;
137138 foreach ( var item in packages )
138139 {
139140 CodeCoverage packageCoverage = new ( )
140141 {
141- Name = item . Attribute ( "name" ) . Value ,
142- LineRate = double . Parse ( item . Attribute ( "line-rate" ) . Value ) ,
143- BranchRate = double . Parse ( item . Attribute ( "branch-rate" ) . Value ) ,
144- Complexity = int . Parse ( item . Attribute ( "complexity" ) ? . Value ?? "0" )
142+ Name = string . IsNullOrWhiteSpace ( item . Attribute ( "name" ) . Value ) ? $ "Package { i } " : item . Attribute ( "name" ) . Value ,
143+ LineRate = double . Parse ( item . Attribute ( "line-rate" ) ? . Value ?? "0" ) ,
144+ BranchRate = double . Parse ( item . Attribute ( "branch-rate" ) ? . Value ?? "0" ) ,
145+ Complexity = double . Parse ( item . Attribute ( "complexity" ) ? . Value ?? "0" )
145146 } ;
146147 summary . Packages . Add ( packageCoverage ) ;
147148 summary . Complexity += packageCoverage . Complexity ;
149+ i ++ ;
148150 }
149151
150152 return summary ;
@@ -184,12 +186,27 @@ private static string GenerateTextOutput(CodeSummary summary, string badgeUrl)
184186 }
185187
186188 textOutput . AppendLine ( $ "Line Rate = { summary . LineRate * 100 : N0} %, Lines Covered = { summary . LinesCovered } / { summary . LinesValid } ")
187- . AppendLine ( $ "Branch Rate = { summary . BranchRate * 100 : N0} %, Branches Covered = { summary . BranchesCovered } / { summary . BranchesValid } ")
188- . AppendLine ( $ "Complexity = { summary . Complexity } ") ;
189+ . AppendLine ( $ "Branch Rate = { summary . BranchRate * 100 : N0} %, Branches Covered = { summary . BranchesCovered } / { summary . BranchesValid } ") ;
190+
191+ if ( summary . Complexity % 1 == 0 )
192+ {
193+ textOutput . AppendLine ( $ "Complexity = { summary . Complexity } ") ;
194+ }
195+ else
196+ {
197+ textOutput . AppendLine ( $ "Complexity = { summary . Complexity : N4} ") ;
198+ }
189199
190200 foreach ( CodeCoverage package in summary . Packages )
191201 {
192- textOutput . AppendLine ( $ "{ package . Name } : Line Rate = { package . LineRate * 100 : N0} %, Branch Rate = { package . BranchRate * 100 : N0} %, Complexity = { package . Complexity } ") ;
202+ if ( package . Complexity % 1 == 0 )
203+ {
204+ textOutput . AppendLine ( $ "{ package . Name } : Line Rate = { package . LineRate * 100 : N0} %, Branch Rate = { package . BranchRate * 100 : N0} %, Complexity = { package . Complexity } ") ;
205+ }
206+ else
207+ {
208+ textOutput . AppendLine ( $ "{ package . Name } : Line Rate = { package . LineRate * 100 : N0} %, Branch Rate = { package . BranchRate * 100 : N0} %, Complexity = { package . Complexity : N4} ") ;
209+ }
193210 }
194211
195212 return textOutput . ToString ( ) ;
@@ -210,11 +227,27 @@ private static string GenerateMarkdownOutput(CodeSummary summary, string badgeUr
210227
211228 foreach ( CodeCoverage package in summary . Packages )
212229 {
213- markdownOutput . AppendLine ( $ "{ package . Name } | { package . LineRate * 100 : N0} % | { package . BranchRate * 100 : N0} % | { package . Complexity } ") ;
230+ if ( package . Complexity % 1 == 0 )
231+ {
232+ markdownOutput . AppendLine ( $ "{ package . Name } | { package . LineRate * 100 : N0} % | { package . BranchRate * 100 : N0} % | { package . Complexity } ") ;
233+ }
234+ else
235+ {
236+ markdownOutput . AppendLine ( $ "{ package . Name } | { package . LineRate * 100 : N0} % | { package . BranchRate * 100 : N0} % | { package . Complexity : N4} ") ;
237+ }
214238 }
215239
216240 markdownOutput . Append ( $ "**Summary** | **{ summary . LineRate * 100 : N0} %** ({ summary . LinesCovered } / { summary . LinesValid } ) | ")
217- . AppendLine ( $ "**{ summary . BranchRate * 100 : N0} %** ({ summary . BranchesCovered } / { summary . BranchesValid } ) | { summary . Complexity } ") ;
241+ . Append ( $ "**{ summary . BranchRate * 100 : N0} %** ({ summary . BranchesCovered } / { summary . BranchesValid } ) | ") ;
242+
243+ if ( summary . Complexity % 1 == 0 )
244+ {
245+ markdownOutput . AppendLine ( summary . Complexity . ToString ( ) ) ;
246+ }
247+ else
248+ {
249+ markdownOutput . AppendLine ( summary . Complexity . ToString ( "N4" ) ) ;
250+ }
218251
219252 return markdownOutput . ToString ( ) ;
220253 }
0 commit comments