File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class CoverageResultTask : Task
1414 {
1515 private string _filename ;
1616 private string _format ;
17+ private int _threshold ;
1718
1819 [ Required ]
1920 public string Output
@@ -29,6 +30,13 @@ public string OutputFormat
2930 set { _format = value ; }
3031 }
3132
33+ [ Required ]
34+ public int Threshold
35+ {
36+ get { return _threshold ; }
37+ set { _threshold = value ; }
38+ }
39+
3240 public override bool Execute ( )
3341 {
3442 try
@@ -59,15 +67,23 @@ public override bool Execute()
5967
6068 File . WriteAllText ( _filename , result . Format ( reporter ) ) ;
6169
70+ int total = 0 ;
6271 CoverageSummary coverageSummary = new CoverageSummary ( result ) ;
6372 var summary = coverageSummary . CalculateSummary ( ) ;
6473
6574 ConsoleTable table = new ConsoleTable ( "Module" , "Coverage" ) ;
6675 foreach ( var item in summary )
76+ {
6777 table . AddRow ( item . Key , $ "{ item . Value } %") ;
78+ total += item . Value ;
79+ }
6880
6981 Console . WriteLine ( ) ;
7082 table . Write ( Format . Alternative ) ;
83+
84+ int average = total / summary . Count ;
85+ if ( average < _threshold )
86+ return false ;
7187 }
7288 catch ( Exception ex )
7389 {
Original file line number Diff line number Diff line change 33 <PropertyGroup >
44 <CoverletOutputFormat Condition =" $(CoverletOutputFormat) == ''" >json</CoverletOutputFormat >
55 <CoverletOutputDirectory Condition =" $(CoverletOutputDirectory) == ''" >$(MSBuildProjectDirectory)</CoverletOutputDirectory >
6-
6+ < Threshold Condition = " $(Threshold) == '' " >0</ Threshold >
77 <CoverletOutputExtension Condition =" $(CoverletOutputFormat) == 'lcov'" >.info</CoverletOutputExtension >
88 <CoverletOutputExtension Condition =" $(CoverletOutputFormat) == 'opencover'" >.xml</CoverletOutputExtension >
99 <CoverletOutputExtension Condition =" $(CoverletOutputFormat) != 'lcov' and $(CoverletOutputFormat) != 'opencover'" >.json</CoverletOutputExtension >
Original file line number Diff line number Diff line change 1919 <Coverlet .MSbuild.Tasks.CoverageResultTask
2020 Condition =" $(CollectCoverage) == 'true'"
2121 Output =" $(CoverletOutput)"
22- OutputFormat =" $(CoverletOutputFormat)" />
22+ OutputFormat =" $(CoverletOutputFormat)"
23+ Threshold =" $(Threshold)" />
2324 </Target >
2425
2526</Project >
You can’t perform that action at this time.
0 commit comments