@@ -16,8 +16,8 @@ namespace Coverlet.Integration.Tests
1616 public class DeterministicBuild : BaseTest , IDisposable
1717 {
1818 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 = [ ] ;
2121 private readonly string _testProjectPath = TestUtils . GetTestProjectPath ( s_projectName ) ;
2222 private readonly string _testBinaryPath = TestUtils . GetTestBinaryPath ( s_projectName ) ;
2323 private readonly string _testResultsPath = TestUtils . GetTestResultsPath ( s_projectName ) ;
@@ -26,10 +26,13 @@ public class DeterministicBuild : BaseTest, IDisposable
2626 private readonly ITestOutputHelper _output ;
2727 private readonly Type _type ;
2828 private readonly FieldInfo ? _testMember ;
29+ private readonly string _artifactsPivot ;
2930
3031 public DeterministicBuild ( ITestOutputHelper output )
3132 {
3233 _buildConfiguration = TestUtils . GetAssemblyBuildConfiguration ( ) . ToString ( ) ;
34+ _buildTargetFramework = TestUtils . GetAssemblyTargetFramework ( ) ;
35+ _artifactsPivot = _buildConfiguration + "_" + _buildTargetFramework ;
3336 _output = output ;
3437 _type = output . GetType ( ) ;
3538 _testMember = _type . GetField ( "test" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
@@ -46,8 +49,14 @@ private void CreateDeterministicTestPropsFile()
4649 new XElement ( "PropertyGroup" ,
4750 new XElement ( "coverletMsbuildVersion" , GetPackageVersion ( "*msbuild*.nupkg" ) ) ,
4851 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 ) ;
5160
5261 deterministicTestProps . Save ( Path . Combine ( propsFile ) ) ;
5362 }
@@ -58,7 +67,7 @@ private protected void AssertCoverage(string standardOutput = "", bool checkDete
5867 {
5968 bool coverageChecked = false ;
6069 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 ) )
6271 {
6372 Classes ? document = JsonConvert . DeserializeObject < Modules > ( File . ReadAllText ( coverageFile ) ) ? . Document ( "DeepThought.cs" ) ;
6473 if ( document != null )
@@ -93,7 +102,7 @@ public void Msbuild()
93102 string logFilename = $ "{ TestContext . Current . TestClass ? . TestClassName } .{ TestContext . Current . TestMethod ? . MethodName } .binlog";
94103 CreateDeterministicTestPropsFile ( ) ;
95104
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 ) ;
97106 if ( ! string . IsNullOrEmpty ( buildError ) )
98107 {
99108 _output . WriteLine ( buildError ) ;
@@ -103,13 +112,12 @@ public void Msbuild()
103112 _output . WriteLine ( buildOutput ) ;
104113 }
105114 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" ) ;
107116 Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
108117 Assert . False ( string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ) ;
109118 Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
110119
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";
113121 _output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
114122 int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
115123 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -123,6 +131,7 @@ public void Msbuild()
123131 Assert . Equal ( 0 , result ) ;
124132 Assert . Contains ( "Passed!" , standardOutput ) ;
125133 Assert . Contains ( "| coverletsample.integration.determisticbuild | 100% | 100% | 100% |" , standardOutput ) ;
134+ string testResultFile = Path . Join ( testResultPath , $ "coverage.{ _buildTargetFramework } .json") ;
126135 Assert . True ( File . Exists ( testResultFile ) ) ;
127136 AssertCoverage ( standardOutput ) ;
128137
@@ -136,7 +145,7 @@ public void Msbuild_SourceLink()
136145 string logFilename = $ "{ TestContext . Current . TestClass ? . TestClassName } .{ TestContext . Current . TestMethod ? . MethodName } .binlog";
137146 CreateDeterministicTestPropsFile ( ) ;
138147
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 ) ;
140149 if ( ! string . IsNullOrEmpty ( buildError ) )
141150 {
142151 _output . WriteLine ( buildError ) ;
@@ -146,14 +155,13 @@ public void Msbuild_SourceLink()
146155 _output . WriteLine ( buildOutput ) ;
147156 }
148157 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" ) ;
150159
151160 Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
152161 Assert . False ( string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ) ;
153162 Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
154163
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";
157165 _output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
158166 int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
159167 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -167,6 +175,7 @@ public void Msbuild_SourceLink()
167175 Assert . Equal ( 0 , result ) ;
168176 Assert . Contains ( "Passed!" , standardOutput ) ;
169177 Assert . Contains ( "| coverletsample.integration.determisticbuild | 100% | 100% | 100% |" , standardOutput ) ;
178+ string testResultFile = Path . Join ( testResultPath , $ "coverage.{ _buildTargetFramework } .json") ;
170179 Assert . True ( File . Exists ( testResultFile ) ) ;
171180 Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( testResultFile ) ) ;
172181 AssertCoverage ( standardOutput , checkDeterministicReport : false ) ;
@@ -185,7 +194,7 @@ public void Collectors()
185194 DeleteLogFiles ( testLogFilesPath ) ;
186195 DeleteCoverageFiles ( testResultPath ) ;
187196
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 ) ;
189198 if ( ! string . IsNullOrEmpty ( buildError ) )
190199 {
191200 _output . WriteLine ( buildError ) ;
@@ -195,14 +204,14 @@ public void Collectors()
195204 _output . WriteLine ( buildOutput ) ;
196205 }
197206 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" ) ;
199208
200209 Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
201210 Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
202211 Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
203212
204213 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" ) } ";
206215 _output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
207216 int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
208217 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -240,7 +249,7 @@ public void Collectors_SourceLink()
240249 DeleteLogFiles ( testLogFilesPath ) ;
241250 DeleteCoverageFiles ( testResultPath ) ;
242251
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 ) ;
244253 if ( ! string . IsNullOrEmpty ( buildError ) )
245254 {
246255 _output . WriteLine ( buildError ) ;
@@ -250,14 +259,14 @@ public void Collectors_SourceLink()
250259 _output . WriteLine ( buildOutput ) ;
251260 }
252261 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" ) ;
254263
255264 Assert . True ( File . Exists ( sourceRootMappingFilePath ) , $ "File not found: { sourceRootMappingFilePath } ") ;
256265 Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
257266 Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
258267
259268 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" ) } ";
261270 _output . WriteLine ( $ "Command: dotnet { cmdArgument } ") ;
262271 int result = DotnetCli ( cmdArgument , out string standardOutput , out string standardError , _testProjectPath ) ;
263272 if ( ! string . IsNullOrEmpty ( standardError ) )
@@ -370,11 +379,12 @@ private static void DeleteCoverageFiles(string directory)
370379 private string GetReportPath ( string standardOutput )
371380 {
372381 string reportPath = "" ;
373- if ( standardOutput . Contains ( "coverage.json" ) )
382+ string reportFileName = $ "coverage.{ _buildTargetFramework } .json";
383+ if ( standardOutput . Contains ( reportFileName ) )
374384 {
375- reportPath = standardOutput . Split ( '\n ' ) . FirstOrDefault ( line => line . Contains ( "coverage.json" ) ) ! . TrimStart ( ) ;
385+ reportPath = standardOutput . Split ( '\n ' ) . FirstOrDefault ( line => line . Contains ( reportFileName ) ) ! . TrimStart ( ) ;
376386 reportPath = reportPath [ reportPath . IndexOf ( Directory . GetDirectoryRoot ( _testProjectPath ) ) ..] ;
377- reportPath = reportPath [ ..reportPath . IndexOf ( "coverage.json" ) ] ;
387+ reportPath = reportPath [ ..reportPath . IndexOf ( reportFileName ) ] ;
378388 }
379389 return reportPath ;
380390 }
0 commit comments