@@ -16,8 +16,8 @@ namespace Coverlet.Integration.Tests
16
16
public class DeterministicBuild : BaseTest , IDisposable
17
17
{
18
18
private static readonly string s_projectName = "coverlet.integration.determisticbuild" ;
19
- // private readonly string _buildTargetFramework;
20
- private string ? _testProjectTfm ;
19
+ private readonly string _buildTargetFramework ;
20
+ private string [ ] _testProjectTfms = [ ] ;
21
21
private readonly string _testProjectPath = TestUtils . GetTestProjectPath ( s_projectName ) ;
22
22
private readonly string _testBinaryPath = TestUtils . GetTestBinaryPath ( s_projectName ) ;
23
23
private readonly string _testResultsPath = TestUtils . GetTestResultsPath ( s_projectName ) ;
@@ -26,10 +26,13 @@ public class DeterministicBuild : BaseTest, IDisposable
26
26
private readonly ITestOutputHelper _output ;
27
27
private readonly Type _type ;
28
28
private readonly FieldInfo ? _testMember ;
29
+ private readonly string _artifactsPivot ;
29
30
30
31
public DeterministicBuild ( ITestOutputHelper output )
31
32
{
32
33
_buildConfiguration = TestUtils . GetAssemblyBuildConfiguration ( ) . ToString ( ) ;
34
+ _buildTargetFramework = TestUtils . GetAssemblyTargetFramework ( ) ;
35
+ _artifactsPivot = _buildConfiguration + "_" + _buildTargetFramework ;
33
36
_output = output ;
34
37
_type = output . GetType ( ) ;
35
38
_testMember = _type . GetField ( "test" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
@@ -46,8 +49,14 @@ private void CreateDeterministicTestPropsFile()
46
49
new XElement ( "PropertyGroup" ,
47
50
new XElement ( "coverletMsbuildVersion" , GetPackageVersion ( "*msbuild*.nupkg" ) ) ,
48
51
new XElement ( "coverletCollectorsVersion" , GetPackageVersion ( "*collector*.nupkg" ) ) ) ) ) ;
49
- _testProjectTfm = XElement . Load ( Path . Combine ( _testProjectPath , "coverlet.integration.determisticbuild.csproj" ) ) ! .
50
- Descendants ( "PropertyGroup" ) ! . Single ( ) . Element ( "TargetFramework" ) ! . Value ;
52
+ _testProjectTfms = XElement . Load ( Path . Combine ( _testProjectPath , "coverlet.integration.determisticbuild.csproj" ) ) !
53
+ . Descendants ( "PropertyGroup" ) !
54
+ . Single ( )
55
+ . Element ( "TargetFrameworks" ) !
56
+ . Value
57
+ . Split ( ';' ) ;
58
+
59
+ Assert . Contains ( _buildTargetFramework , _testProjectTfms ) ;
51
60
52
61
deterministicTestProps . Save ( Path . Combine ( propsFile ) ) ;
53
62
}
@@ -58,7 +67,7 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
58
67
{
59
68
bool coverageChecked = false ;
60
69
string reportFilePath = "" ;
61
- foreach ( string coverageFile in Directory . GetFiles ( GetReportPath ( standardOutput ) , "coverage.json" , SearchOption . AllDirectories ) )
70
+ foreach ( string coverageFile in Directory . GetFiles ( GetReportPath ( standardOutput ) , $ "coverage. { _buildTargetFramework } .json", SearchOption . AllDirectories ) )
62
71
{
63
72
Classes ? document = JsonConvert . DeserializeObject < Modules > ( File . ReadAllText ( coverageFile ) ) ? . Document ( "DeepThought.cs" ) ;
64
73
if ( document != null )
@@ -93,7 +102,7 @@ public void Msbuild()
93
102
string logFilename = $ "{ TestContext . Current . TestClass ? . TestClassName } .{ TestContext . Current . TestMethod ? . MethodName } .binlog";
94
103
CreateDeterministicTestPropsFile ( ) ;
95
104
96
- DotnetCli ( $ "build -c { _buildConfiguration } -bl:build.{ logFilename } /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
105
+ DotnetCli ( $ "build -c { _buildConfiguration } -f { _buildTargetFramework } - bl:build.{ logFilename } /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
97
106
if ( ! string . IsNullOrEmpty ( buildError ) )
98
107
{
99
108
_output . WriteLine ( buildError ) ;
@@ -103,13 +112,12 @@ public void Msbuild()
103
112
_output . WriteLine ( buildOutput ) ;
104
113
}
105
114
Assert . Contains ( "Build succeeded." , buildOutput ) ;
106
- string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _buildConfiguration . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
115
+ string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _artifactsPivot . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
107
116
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
108
117
Assert . False ( string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ) ;
109
118
Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
110
119
111
- string testResultFile = Path . Join ( testResultPath , "coverage.json" ) ;
112
- string cmdArgument = $ "test -c { _buildConfiguration } --no-build /p:CollectCoverage=true /p:CoverletOutput=\" { testResultFile } \" /p:DeterministicReport=true /p:CoverletOutputFormat=\" cobertura%2cjson\" /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true";
120
+ string cmdArgument = $ "test -c { _buildConfiguration } -f { _buildTargetFramework } --no-build /p:CollectCoverage=true /p:CoverletOutput=\" coverage.json\" /p:DeterministicReport=true /p:CoverletOutputFormat=\" cobertura%2cjson\" /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true";
113
121
_output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
114
122
int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
115
123
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -123,6 +131,7 @@ public void Msbuild()
123
131
Assert . Equal ( 0 , result ) ;
124
132
Assert . Contains ( "Passed!" , standardOutput ) ;
125
133
Assert . Contains ( "| coverletsample.integration.determisticbuild | 100% | 100% | 100% |" , standardOutput ) ;
134
+ string testResultFile = Path . Join ( testResultPath , $ "coverage.{ _buildTargetFramework } .json") ;
126
135
Assert . True ( File . Exists ( testResultFile ) ) ;
127
136
AssertCoverage ( standardOutput ) ;
128
137
@@ -136,7 +145,7 @@ public void Msbuild_SourceLink()
136
145
string logFilename = $ "{ TestContext . Current . TestClass ? . TestClassName } .{ TestContext . Current . TestMethod ? . MethodName } .binlog";
137
146
CreateDeterministicTestPropsFile ( ) ;
138
147
139
- DotnetCli ( $ "build -c { _buildConfiguration } -bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
148
+ DotnetCli ( $ "build -c { _buildConfiguration } -f { _buildTargetFramework } - bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
140
149
if ( ! string . IsNullOrEmpty ( buildError ) )
141
150
{
142
151
_output . WriteLine ( buildError ) ;
@@ -146,14 +155,13 @@ public void Msbuild_SourceLink()
146
155
_output . WriteLine ( buildOutput ) ;
147
156
}
148
157
Assert . Contains ( "Build succeeded." , buildOutput ) ;
149
- string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _buildConfiguration . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
158
+ string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _artifactsPivot . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
150
159
151
160
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
152
161
Assert . False ( string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ) ;
153
162
Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
154
163
155
- string testResultFile = Path . Join ( testResultPath , "coverage.json" ) ;
156
- string cmdArgument = $ "test -c { _buildConfiguration } --no-build /p:CollectCoverage=true /p:CoverletOutput=\" { testResultFile } \" /p:CoverletOutputFormat=\" cobertura%2cjson\" /p:UseSourceLink=true /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true";
164
+ string cmdArgument = $ "test -c { _buildConfiguration } -f { _buildTargetFramework } --no-build /p:CollectCoverage=true /p:CoverletOutput=\" coverage.json\" /p:CoverletOutputFormat=\" cobertura%2cjson\" /p:UseSourceLink=true /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true";
157
165
_output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
158
166
int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
159
167
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -167,6 +175,7 @@ public void Msbuild_SourceLink()
167
175
Assert . Equal ( 0 , result ) ;
168
176
Assert . Contains ( "Passed!" , standardOutput ) ;
169
177
Assert . Contains ( "| coverletsample.integration.determisticbuild | 100% | 100% | 100% |" , standardOutput ) ;
178
+ string testResultFile = Path . Join ( testResultPath , $ "coverage.{ _buildTargetFramework } .json") ;
170
179
Assert . True ( File . Exists ( testResultFile ) ) ;
171
180
Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( testResultFile ) ) ;
172
181
AssertCoverage ( standardOutput , checkDeterministicReport : false ) ;
@@ -185,7 +194,7 @@ public void Collectors()
185
194
DeleteLogFiles ( testLogFilesPath ) ;
186
195
DeleteCoverageFiles ( testResultPath ) ;
187
196
188
- DotnetCli ( $ "build -c { _buildConfiguration } -bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
197
+ DotnetCli ( $ "build -c { _buildConfiguration } -f { _buildTargetFramework } - bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
189
198
if ( ! string . IsNullOrEmpty ( buildError ) )
190
199
{
191
200
_output . WriteLine ( buildError ) ;
@@ -195,14 +204,14 @@ public void Collectors()
195
204
_output . WriteLine ( buildOutput ) ;
196
205
}
197
206
Assert . Contains ( "Build succeeded." , buildOutput ) ;
198
- string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _buildConfiguration . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
207
+ string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _artifactsPivot . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
199
208
200
209
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
201
210
Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
202
211
Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
203
212
204
213
string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , deterministicReport : true ) ;
205
- string cmdArgument = $ "test -c { _buildConfiguration } --no-build --collect:\" XPlat Code Coverage\" --results-directory:\" { testResultPath } \" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( testLogFilesPath , "log.txt" ) } ";
214
+ string cmdArgument = $ "test -c { _buildConfiguration } -f { _buildTargetFramework } - -no-build --collect:\" XPlat Code Coverage\" --results-directory:\" { testResultPath } \" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( testLogFilesPath , "log.txt" ) } ";
206
215
_output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
207
216
int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
208
217
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -240,7 +249,7 @@ public void Collectors_SourceLink()
240
249
DeleteLogFiles ( testLogFilesPath ) ;
241
250
DeleteCoverageFiles ( testResultPath ) ;
242
251
243
- DotnetCli ( $ "build -c { _buildConfiguration } -bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
252
+ DotnetCli ( $ "build -c { _buildConfiguration } -f { _buildTargetFramework } - bl:build.{ logFilename } --verbosity normal /p:DeterministicSourcePaths=true", out string buildOutput , out string buildError , _testProjectPath ) ;
244
253
if ( ! string . IsNullOrEmpty ( buildError ) )
245
254
{
246
255
_output . WriteLine ( buildError ) ;
@@ -250,14 +259,14 @@ public void Collectors_SourceLink()
250
259
_output . WriteLine ( buildOutput ) ;
251
260
}
252
261
Assert . Contains ( "Build succeeded." , buildOutput ) ;
253
- string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _buildConfiguration . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
262
+ string sourceRootMappingFilePath = Path . Combine ( _testBinaryPath , _artifactsPivot . ToLowerInvariant ( ) , "CoverletSourceRootsMapping_coverletsample.integration.determisticbuild" ) ;
254
263
255
264
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
256
265
Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
257
266
Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
258
267
259
268
string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , sourceLink : true ) ;
260
- string cmdArgument = $ "test -c { _buildConfiguration } --no-build --collect:\" XPlat Code Coverage\" --results-directory:\" { testResultPath } \" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( testLogFilesPath , "log.txt" ) } ";
269
+ string cmdArgument = $ "test -c { _buildConfiguration } -f { _buildTargetFramework } - -no-build --collect:\" XPlat Code Coverage\" --results-directory:\" { testResultPath } \" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( testLogFilesPath , "log.txt" ) } ";
261
270
_output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
262
271
int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
263
272
if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -370,11 +379,12 @@ private static void DeleteCoverageFiles(string directory)
370
379
private string GetReportPath ( string standardOutput )
371
380
{
372
381
string reportPath = "" ;
373
- if ( standardOutput . Contains ( "coverage.json" ) )
382
+ string reportFileName = $ "coverage.{ _buildTargetFramework } .json";
383
+ if ( standardOutput . Contains ( reportFileName ) )
374
384
{
375
- reportPath = standardOutput . Split ( '\n ' ) . FirstOrDefault ( line => line . Contains ( "coverage.json" ) ) ! . TrimStart ( ) ;
385
+ reportPath = standardOutput . Split ( '\n ' ) . FirstOrDefault ( line => line . Contains ( reportFileName ) ) ! . TrimStart ( ) ;
376
386
reportPath = reportPath [ reportPath . IndexOf ( Directory . GetDirectoryRoot ( _testProjectPath ) ) ..] ;
377
- reportPath = reportPath [ ..reportPath . IndexOf ( "coverage.json" ) ] ;
387
+ reportPath = reportPath [ ..reportPath . IndexOf ( reportFileName ) ] ;
378
388
}
379
389
return reportPath ;
380
390
}
0 commit comments