File tree Expand file tree Collapse file tree 10 files changed +81
-16
lines changed Expand file tree Collapse file tree 10 files changed +81
-16
lines changed Original file line number Diff line number Diff line change @@ -74,13 +74,23 @@ static int Main(string[] args)
74
74
if ( reporter == null )
75
75
throw new Exception ( $ "Specified output format '{ format } ' is not supported") ;
76
76
77
- var filename = Path . GetFileName ( dOutput ) ;
78
- filename = ( filename == string . Empty ) ? $ "coverage.{ reporter . Extension } " : filename ;
79
- filename = Path . HasExtension ( filename ) ? filename : $ "{ filename } .{ reporter . Extension } ";
80
-
81
- var report = Path . Combine ( directory , filename ) ;
82
- logger . LogInformation ( $ " Generating report '{ report } '") ;
83
- File . WriteAllText ( report , reporter . Report ( result ) ) ;
77
+ if ( reporter . UseConsoleOutput )
78
+ {
79
+ // Output to console
80
+ logger . LogInformation ( " Outputting results to console" ) ;
81
+ logger . LogInformation ( reporter . Report ( result ) ) ;
82
+ }
83
+ else
84
+ {
85
+ // Output to file
86
+ var filename = Path . GetFileName ( dOutput ) ;
87
+ filename = ( filename == string . Empty ) ? $ "coverage.{ reporter . Extension } " : filename ;
88
+ filename = Path . HasExtension ( filename ) ? filename : $ "{ filename } .{ reporter . Extension } ";
89
+
90
+ var report = Path . Combine ( directory , filename ) ;
91
+ logger . LogInformation ( $ " Generating report '{ report } '") ;
92
+ File . WriteAllText ( report , reporter . Report ( result ) ) ;
93
+ }
84
94
}
85
95
86
96
var summary = new CoverageSummary ( ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ namespace Coverlet.Core.Reporters
10
10
{
11
11
public class CoberturaReporter : IReporter
12
12
{
13
+ public bool UseConsoleOutput => false ;
14
+
13
15
public string Format => "cobertura" ;
14
16
15
17
public string Extension => "cobertura.xml" ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ namespace Coverlet.Core.Reporters
2
2
{
3
3
public interface IReporter
4
4
{
5
+ bool UseConsoleOutput { get ; }
5
6
string Format { get ; }
6
7
string Extension { get ; }
7
8
string Report ( CoverageResult result ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ namespace Coverlet.Core.Reporters
4
4
{
5
5
public class JsonReporter : IReporter
6
6
{
7
+ public bool UseConsoleOutput => false ;
8
+
7
9
public string Format => "json" ;
8
10
9
11
public string Extension => "json" ;
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ namespace Coverlet.Core.Reporters
6
6
{
7
7
public class LcovReporter : IReporter
8
8
{
9
+ public bool UseConsoleOutput => false ;
10
+
9
11
public string Format => "lcov" ;
10
12
11
13
public string Extension => "info" ;
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ namespace Coverlet.Core.Reporters
9
9
{
10
10
public class OpenCoverReporter : IReporter
11
11
{
12
+ public bool UseConsoleOutput => false ;
13
+
12
14
public string Format => "opencover" ;
13
15
14
16
public string Extension => "opencover.xml" ;
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Linq ;
3
3
using System . Collections . Generic ;
4
+ using coverlet . core . Reporters ;
4
5
5
6
namespace Coverlet . Core . Reporters
6
7
{
@@ -14,7 +15,8 @@ public ReporterFactory(string format)
14
15
_format = format ;
15
16
_reporters = new IReporter [ ] {
16
17
new JsonReporter ( ) , new LcovReporter ( ) ,
17
- new OpenCoverReporter ( ) , new CoberturaReporter ( )
18
+ new OpenCoverReporter ( ) , new CoberturaReporter ( ) ,
19
+ new TeamCityReporter ( )
18
20
} ;
19
21
}
20
22
Original file line number Diff line number Diff line change
1
+ using Coverlet . Core ;
2
+ using Coverlet . Core . Reporters ;
3
+ using System . Text ;
4
+
5
+ namespace coverlet . core . Reporters
6
+ {
7
+ public class TeamCityReporter : IReporter
8
+ {
9
+ public bool UseConsoleOutput => true ;
10
+
11
+ public string Format => "teamcity" ;
12
+
13
+ public string Extension => null ;
14
+
15
+ public string Report ( CoverageResult result )
16
+ {
17
+ // Calculate coverage
18
+ var summary = new CoverageSummary ( ) ;
19
+ var overallLineCoverage = summary . CalculateLineCoverage ( result . Modules ) ;
20
+ var overallBranchCoverage = summary . CalculateBranchCoverage ( result . Modules ) ;
21
+ var overallMethodCoverage = summary . CalculateMethodCoverage ( result . Modules ) ;
22
+
23
+ // Report coverage
24
+ var stringBuilder = new StringBuilder ( ) ;
25
+ var teamCityServiceMessageWriter = new TeamCityServiceMessageWriter ( s => stringBuilder . AppendLine ( s ) ) ;
26
+ teamCityServiceMessageWriter . OutputLineCoverage ( overallLineCoverage ) ;
27
+ teamCityServiceMessageWriter . OutputBranchCoverage ( overallBranchCoverage ) ;
28
+ teamCityServiceMessageWriter . OutputMethodCoverage ( overallMethodCoverage ) ;
29
+
30
+ // Return a placeholder
31
+ return stringBuilder . ToString ( ) ;
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ public void OutputMethodCoverage(CoverageDetails coverageDetails)
62
62
63
63
private void OutputTeamCityServiceMessage ( string key , object value )
64
64
{
65
- _writer ( $ "##teamcity[buildStatisticValue key='{ key } ' value='{ value } ']") ;
65
+ _writer ? . Invoke ( $ "##teamcity[buildStatisticValue key='{ key } ' value='{ value } ']") ;
66
66
}
67
67
}
68
68
}
Original file line number Diff line number Diff line change @@ -75,13 +75,23 @@ public override bool Execute()
75
75
if ( reporter == null )
76
76
throw new Exception ( $ "Specified output format '{ format } ' is not supported") ;
77
77
78
- var filename = Path . GetFileName ( _output ) ;
79
- filename = ( filename == string . Empty ) ? $ "coverage.{ reporter . Extension } " : filename ;
80
- filename = Path . HasExtension ( filename ) ? filename : $ "{ filename } .{ reporter . Extension } ";
81
-
82
- var report = Path . Combine ( directory , filename ) ;
83
- Console . WriteLine ( $ " Generating report '{ report } '") ;
84
- File . WriteAllText ( report , reporter . Report ( result ) ) ;
78
+ if ( reporter . UseConsoleOutput )
79
+ {
80
+ // Output to console
81
+ Console . WriteLine ( " Outputting results to console" ) ;
82
+ Console . WriteLine ( reporter . Report ( result ) ) ;
83
+ }
84
+ else
85
+ {
86
+ // Output to file
87
+ var filename = Path . GetFileName ( _output ) ;
88
+ filename = ( filename == string . Empty ) ? $ "coverage.{ reporter . Extension } " : filename ;
89
+ filename = Path . HasExtension ( filename ) ? filename : $ "{ filename } .{ reporter . Extension } ";
90
+
91
+ var report = Path . Combine ( directory , filename ) ;
92
+ Console . WriteLine ( $ " Generating report '{ report } '") ;
93
+ File . WriteAllText ( report , reporter . Report ( result ) ) ;
94
+ }
85
95
}
86
96
87
97
var thresholdFailed = false ;
You can’t perform that action at this time.
0 commit comments