@@ -66,7 +66,7 @@ public void Msbuild()
66
66
string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , _buildConfiguration , _testProjectTfm ! , "CoverletSourceRootsMapping" ) ;
67
67
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
68
68
Assert . True ( ! string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) , "Empty CoverletSourceRootsMapping file" ) ;
69
- Assert . Equal ( 2 , File . ReadAllLines ( sourceRootMappingFilePath ) . Length ) ;
69
+ Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
70
70
71
71
DotnetCli ( $ "test -c { _buildConfiguration } --no-build /p:CollectCoverage=true /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput , out _ , _testProjectPath ) ;
72
72
Assert . Contains ( "Test Run Successful." , standardOutput ) ;
@@ -80,6 +80,30 @@ public void Msbuild()
80
80
RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
81
81
}
82
82
83
+ [ Fact ]
84
+ public void Msbuild_SourceLink ( )
85
+ {
86
+ CreateDeterministicTestPropsFile ( ) ;
87
+ DotnetCli ( $ "build -c { _buildConfiguration } /p:DeterministicSourcePaths=true", out string standardOutput , out string _ , _testProjectPath ) ;
88
+ Assert . Contains ( "Build succeeded." , standardOutput ) ;
89
+ string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , _buildConfiguration , _testProjectTfm ! , "CoverletSourceRootsMapping" ) ;
90
+ Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
91
+ Assert . True ( ! string . IsNullOrEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) , "Empty CoverletSourceRootsMapping file" ) ;
92
+ Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
93
+
94
+ DotnetCli ( $ "test -c { _buildConfiguration } --no-build /p:CollectCoverage=true /p:UseSourceLink=true /p:Include=\" [coverletsample.integration.determisticbuild]*DeepThought\" /p:IncludeTestAssembly=true", out standardOutput , out _ , _testProjectPath ) ;
95
+ Assert . Contains ( "Test Run Successful." , standardOutput ) ;
96
+ Assert . Contains ( "| coverletsample.integration.determisticbuild | 100% | 100% | 100% |" , standardOutput ) ;
97
+ Assert . True ( File . Exists ( Path . Combine ( _testProjectPath , "coverage.json" ) ) ) ;
98
+ Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( Path . Combine ( _testProjectPath , "coverage.json" ) ) ) ;
99
+ AssertCoverage ( standardOutput ) ;
100
+
101
+ // Process exits hang on clean seem that process doesn't close, maybe some mbuild node reuse? btw manually tested
102
+ // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath);
103
+ // Assert.False(File.Exists(sourceRootMappingFilePath));
104
+ RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
105
+ }
106
+
83
107
[ Fact ]
84
108
public void Collectors ( )
85
109
{
@@ -89,7 +113,7 @@ public void Collectors()
89
113
string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , GetAssemblyBuildConfiguration ( ) . ToString ( ) , _testProjectTfm ! , "CoverletSourceRootsMapping" ) ;
90
114
Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
91
115
Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
92
- Assert . Equal ( 2 , File . ReadAllLines ( sourceRootMappingFilePath ) . Length ) ;
116
+ Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
93
117
94
118
string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" ) ;
95
119
Assert . True ( DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out _ ) , standardOutput ) ;
@@ -108,6 +132,35 @@ public void Collectors()
108
132
RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
109
133
}
110
134
135
+ [ Fact ]
136
+ public void Collectors_SourceLink ( )
137
+ {
138
+ CreateDeterministicTestPropsFile ( ) ;
139
+ DotnetCli ( $ "build -c { _buildConfiguration } /p:DeterministicSourcePaths=true", out string standardOutput , out string _ , _testProjectPath ) ;
140
+ Assert . Contains ( "Build succeeded." , standardOutput ) ;
141
+ string sourceRootMappingFilePath = Path . Combine ( _testProjectPath , "bin" , GetAssemblyBuildConfiguration ( ) . ToString ( ) , _testProjectTfm ! , "CoverletSourceRootsMapping" ) ;
142
+ Assert . True ( File . Exists ( sourceRootMappingFilePath ) , sourceRootMappingFilePath ) ;
143
+ Assert . NotEmpty ( File . ReadAllText ( sourceRootMappingFilePath ) ) ;
144
+ Assert . Contains ( "=/_/" , File . ReadAllText ( sourceRootMappingFilePath ) ) ;
145
+
146
+ string runSettingsPath = AddCollectorRunsettingsFile ( _testProjectPath , "[coverletsample.integration.determisticbuild]*DeepThought" , sourceLink : true ) ;
147
+ Assert . True ( DotnetCli ( $ "test -c { _buildConfiguration } --no-build \" { _testProjectPath } \" --collect:\" XPlat Code Coverage\" --settings \" { runSettingsPath } \" --diag:{ Path . Combine ( _testProjectPath , "log.txt" ) } ", out standardOutput , out _ ) , standardOutput ) ;
148
+ Assert . Contains ( "Test Run Successful." , standardOutput ) ;
149
+ AssertCoverage ( standardOutput ) ;
150
+ Assert . Contains ( "raw.githubusercontent.com" , File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "coverage.cobertura.xml" , SearchOption . AllDirectories ) . Single ( ) ) ) ;
151
+
152
+ // Check out/in process collectors injection
153
+ string dataCollectorLogContent = File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.datacollector.*.txt" ) . Single ( ) ) ;
154
+ Assert . Contains ( "[coverlet]Initializing CoverletCoverageDataCollector with configuration:" , dataCollectorLogContent ) ;
155
+ Assert . Contains ( "[coverlet]Initialize CoverletInProcDataCollector" , File . ReadAllText ( Directory . GetFiles ( _testProjectPath , "log.host.*.txt" ) . Single ( ) ) ) ;
156
+ Assert . Contains ( "[coverlet]Mapping resolved" , dataCollectorLogContent ) ;
157
+
158
+ // Process exits hang on clean seem that process doesn't close, maybe some mbuild node reuse? btw manually tested
159
+ // DotnetCli("clean", out standardOutput, out standardError, _fixture.TestProjectPath);
160
+ // Assert.False(File.Exists(sourceRootMappingFilePath));
161
+ RunCommand ( "git" , "clean -fdx" , out _ , out _ , _testProjectPath ) ;
162
+ }
163
+
111
164
public void Dispose ( )
112
165
{
113
166
File . Delete ( Path . Combine ( _testProjectPath , PropsFileName ) ) ;
0 commit comments