@@ -46,7 +46,7 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
46
46
{
47
47
bool coverageChecked = false ;
48
48
string reportFilePath = "" ;
49
- foreach ( string coverageFile in Directory . GetFiles ( _testProjectPath , "coverage.json" , SearchOption . AllDirectories ) )
49
+ foreach ( string coverageFile in Directory . GetFiles ( GetReportPath ( standardOutput ) , "coverage.json" , SearchOption . AllDirectories ) )
50
50
{
51
51
Classes ? document = JsonConvert . DeserializeObject < Modules > ( File . ReadAllText ( coverageFile ) ) ? . Document ( "DeepThought.cs" ) ;
52
52
if ( document != null )
@@ -65,7 +65,7 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
65
65
if ( checkDeterministicReport )
66
66
{
67
67
// Verify deterministic report
68
- foreach ( string coverageFile in Directory . GetFiles ( _testProjectPath , "coverage.cobertura.xml" , SearchOption . AllDirectories ) )
68
+ foreach ( string coverageFile in Directory . GetFiles ( GetReportPath ( standardOutput ) , "coverage.cobertura.xml" , SearchOption . AllDirectories ) )
69
69
{
70
70
Assert . Contains ( "/_/test/coverlet.integration.determisticbuild/DeepThought.cs" , File . ReadAllText ( coverageFile ) ) ;
71
71
File . Delete ( coverageFile ) ;
@@ -149,7 +149,7 @@ public void Collectors()
149
149
Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
150
150
151
151
string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , deterministicReport : true ) ;
152
- Assert . True ( DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out standardError ) , standardOutput ) ;
152
+ bool result = DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out standardError ) ;
153
153
if ( ! string . IsNullOrEmpty ( standardError ) )
154
154
{
155
155
_output . WriteLine ( standardError ) ;
@@ -158,6 +158,7 @@ public void Collectors()
158
158
{
159
159
_output . WriteLine ( standardOutput ) ;
160
160
}
161
+ Assert . True ( result ) ;
161
162
Assert . Contains ( "Passed!" , standardOutput ) ;
162
163
AssertCoverage ( standardOutput ) ;
163
164
@@ -175,42 +176,57 @@ public void Collectors()
175
176
176
177
[ Fact ]
177
178
public void Collectors_SourceLink ( )
178
- {
179
- CreateDeterministicTestPropsFile ( ) ;
180
- DotnetCli ( $ "build -c { _buildConfiguration } /p:DeterministicSourcePaths=true", out string standardOutput , out string standardError , _testProjectPath ) ;
181
- Assert . Contains ( "Build succeeded." , standardOutput ) ;
182
- string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , GetAssemblyBuildConfiguration ( ) . ToString ( ) , _testProjectTfm ! , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
183
- Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
184
- Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
185
- Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
186
-
187
- string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , sourceLink : true ) ;
188
- Assert . True ( DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out standardError ) , standardOutput ) ;
189
- if ( ! string . IsNullOrEmpty ( standardError ) )
190
- {
191
- _output . WriteLine ( standardError ) ;
192
- }
193
- else
194
- {
195
- _output . WriteLine ( standardOutput ) ;
196
- }
197
- Assert . Contains ( "Passed!" , standardOutput ) ;
198
- AssertCoverage ( standardOutput , checkDeterministicReport : false ) ;
199
- Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "coverage.cobertura.xml" , SearchOption . AllDirectories ) . Single ( ) ) ) ;
200
-
201
- // Check out/in process collectors injection
202
- string dataCollectorLogContent = File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.datacollector.*.txt" ) . Single ( ) ) ;
203
- Assert . Contains ( "[coverlet]Initializing CoverletCoverageDataCollector with configuration:" , dataCollectorLogContent ) ;
204
- Assert . Contains ( "[coverlet]Initialize CoverletInProcDataCollector" , File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.host.*.txt" ) . Single ( ) ) ) ;
205
- Assert . Contains ( "[coverlet]Mapping resolved" , dataCollectorLogContent ) ;
179
+ {
180
+ CreateDeterministicTestPropsFile ( ) ;
181
+ DotnetCli ( $ "build -c { _buildConfiguration } /p:DeterministicSourcePaths=true", out string standardOutput , out string standardError , _testProjectPath ) ;
182
+ Assert . Contains ( "Build succeeded." , standardOutput ) ;
183
+ string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , GetAssemblyBuildConfiguration ( ) . ToString ( ) , _testProjectTfm ! , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
184
+ Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
185
+ Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
186
+ Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
187
+
188
+ string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , sourceLink : true ) ;
189
+ bool result = DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out standardError ) ;
190
+ if ( ! string . IsNullOrEmpty ( standardError ) )
191
+ {
192
+ _output . WriteLine ( standardError ) ;
193
+ }
194
+ else
195
+ {
196
+ _output . WriteLine ( standardOutput ) ;
197
+ }
198
+ Assert . True ( result ) ;
199
+ Assert . Contains ( "Passed!" , standardOutput ) ;
200
+ AssertCoverage ( standardOutput , checkDeterministicReport : false ) ;
201
+ Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( Directory . GetFiles ( GetReportPath ( standardOutput ) , "coverage.cobertura.xml" , SearchOption . AllDirectories ) . Single ( ) ) ) ;
202
+
203
+ // Check out/in process collectors injection
204
+ string dataCollectorLogContent = File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.datacollector.*.txt" ) . Single ( ) ) ;
205
+ Assert . Contains ( "[coverlet]Initializing CoverletCoverageDataCollector with configuration:" , dataCollectorLogContent ) ;
206
+ Assert . Contains ( "[coverlet]Initialize CoverletInProcDataCollector" , File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.host.*.txt" ) . Single ( ) ) ) ;
207
+ Assert . Contains ( "[coverlet]Mapping resolved" , dataCollectorLogContent ) ;
208
+
209
+ // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested
210
+ // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath);
211
+ // Assert.False(File.Exists(sourceRootMappingFilePath));
212
+ RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
213
+ }
206
214
207
- // Process exits hang on clean seem that process doesn't close, maybe some msbuild node reuse? btw manually tested
208
- // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath);
209
- // Assert.False(File.Exists(sourceRootMappingFilePath));
210
- RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
211
- }
215
+ private string GetReportPath ( string standardOutput )
216
+ {
217
+ string reportPath = "" ;
218
+ if ( standardOutput . Contains ( "coverage.json" ) )
219
+ {
220
+ #pragma warning disable CS8602 // Dereference of a possibly null reference.
221
+ reportPath = standardOutput . Split ( '\n ' ) . FirstOrDefault ( line => line . Contains ( "coverage.json" ) ) . TrimStart ( ) ;
222
+ #pragma warning restore CS8602 // Dereference of a possibly null reference.
223
+ reportPath = reportPath [ reportPath . IndexOf ( Directory . GetDirectoryRoot ( _testProjectPath ) ) ..] ;
224
+ reportPath = reportPath [ ..reportPath . IndexOf ( "coverage.json" ) ] ;
225
+ }
226
+ return reportPath ;
227
+ }
212
228
213
- public void Dispose ( )
229
+ public void Dispose ( )
214
230
{
215
231
File . Delete ( Path . Combine ( _testProjectPath , PropsFileName ) ) ;
216
232
}
0 commit comments