@@ -76,6 +76,7 @@ public void ProcessedArgs_ParameterThrow_CmdLineProperties() =>
7676 cmdLineProperties : null ,
7777 EmptyPropertyProvider . Instance ,
7878 EmptyPropertyProvider . Instance ,
79+ buildSettings : null ,
7980 runtime ) )
8081 . Should ( ) . Throw < ArgumentNullException > ( )
8182 . WithParameterName ( "cmdLineProperties" ) ;
@@ -92,6 +93,7 @@ public void ProcessedArgs_ParameterThrow_GlobalFileProperties() =>
9293 EmptyPropertyProvider . Instance ,
9394 globalFileProperties : null ,
9495 EmptyPropertyProvider . Instance ,
96+ buildSettings : null ,
9597 runtime ) )
9698 . Should ( ) . Throw < ArgumentNullException > ( )
9799 . WithParameterName ( "globalFileProperties" ) ;
@@ -108,6 +110,7 @@ public void ProcessedArgs_ParameterThrow_ScannerEnvProperties() =>
108110 EmptyPropertyProvider . Instance ,
109111 EmptyPropertyProvider . Instance ,
110112 scannerEnvProperties : null ,
113+ buildSettings : null ,
111114 runtime ) )
112115 . Should ( ) . Throw < ArgumentNullException > ( )
113116 . WithParameterName ( "scannerEnvProperties" ) ;
@@ -210,8 +213,8 @@ public void ProcessedArgs_HostUrl_SonarCloudUrl_HostUrlSet()
210213 sut . ServerInfo . Should ( ) . NotBeNull ( ) ;
211214 sut . ServerInfo . IsSonarCloud . Should ( ) . BeFalse ( ) ;
212215 sut . ServerInfo . ServerUrl . Should ( ) . Be ( "http://host" ) ;
213- runtime . Logger . Warnings . Should ( ) . BeEmpty ( ) ;
214- runtime . Logger . Errors . Should ( ) . BeEmpty ( ) ;
216+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
217+ . And . HaveNoErrors ( ) ;
215218 sut . IsValid . Should ( ) . BeTrue ( ) ;
216219 }
217220
@@ -223,8 +226,8 @@ public void ProcessedArgs_HostUrl_SonarCloudUrl_SonarCloudUrlSet()
223226 sut . ServerInfo . Should ( ) . NotBeNull ( ) ;
224227 sut . ServerInfo . IsSonarCloud . Should ( ) . BeTrue ( ) ;
225228 sut . ServerInfo . ServerUrl . Should ( ) . Be ( "https://sonarcloud.proxy" ) ;
226- runtime . Logger . Warnings . Should ( ) . BeEmpty ( ) ;
227- runtime . Logger . Errors . Should ( ) . BeEmpty ( ) ;
229+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
230+ . And . HaveNoErrors ( ) ;
228231 sut . IsValid . Should ( ) . BeTrue ( ) ;
229232 }
230233
@@ -278,8 +281,8 @@ public void ProcessedArgs_HostUrl_SonarCloudUrl_HostUrlAndSonarcloudUrlMissing()
278281 sut . ServerInfo . Should ( ) . NotBeNull ( ) ;
279282 sut . ServerInfo . IsSonarCloud . Should ( ) . BeTrue ( ) ;
280283 sut . ServerInfo . ServerUrl . Should ( ) . Be ( "https://sonarcloud.io" ) ;
281- runtime . Logger . Warnings . Should ( ) . BeEmpty ( ) ;
282- runtime . Logger . Errors . Should ( ) . BeEmpty ( ) ;
284+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
285+ . And . HaveNoErrors ( ) ;
283286 sut . IsValid . Should ( ) . BeTrue ( ) ;
284287 }
285288
@@ -311,8 +314,8 @@ public void ProcessedArgs_HostUrl_SonarCloudUrl_HostUrlIsAnySonarCloud(string ho
311314 Region = expectedRegion ,
312315 } ,
313316 } ) ;
314- runtime . Logger . Warnings . Should ( ) . BeEmpty ( ) ;
315- runtime . Logger . Errors . Should ( ) . BeEmpty ( ) ;
317+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
318+ . And . HaveNoErrors ( ) ;
316319 }
317320
318321 [ TestMethod ]
@@ -323,8 +326,8 @@ public void ProcessedArgs_HostUrl_SonarCloudUrl_PropertyAggregation()
323326 new ListPropertiesProvider ( [ new Property ( SonarProperties . SonarcloudUrl , "https://sonarcloud.io" ) ] ) ) ;
324327
325328 sut . ServerInfo . Should ( ) . BeNull ( ) ;
326- runtime . Logger . Warnings . Should ( ) . BeEmpty ( ) ;
327- runtime . Logger . Should ( ) . HaveErrors ( "The arguments 'sonar.host.url' and 'sonar.scanner.sonarcloudUrl' are both set and are different. "
329+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
330+ . And . HaveErrors ( "The arguments 'sonar.host.url' and 'sonar.scanner.sonarcloudUrl' are both set and are different. "
328331 + "Please set either 'sonar.host.url' for SonarQube or 'sonar.scanner.sonarcloudUrl' for SonarCloud." ) ;
329332 sut . IsValid . Should ( ) . BeFalse ( ) ;
330333 }
@@ -360,6 +363,7 @@ public void ProcessedArgs_ErrorAndIsValid(bool invalidKey, bool invalidOrganizat
360363 : EmptyPropertyProvider . Instance ,
361364 globalFileProperties : invalidOrganization ? new ListPropertiesProvider ( [ new Property ( SonarProperties . Organization , "organization" ) ] ) : EmptyPropertyProvider . Instance ,
362365 scannerEnvProperties : new ListPropertiesProvider ( [ new Property ( SonarProperties . UserHome , "NotADirectory" ) ] ) ,
366+ buildSettings : null ,
363367 runtime ) ;
364368 runtime . Logger . Errors . Should ( ) . HaveCount ( errors ) ;
365369 sut . IsValid . Should ( ) . Be ( errors == 0 ) ;
@@ -475,11 +479,43 @@ public void ProcessedArgs_SourcesOrTests_Warning(params Property[] properties)
475479 var sut = CreateDefaultArgs ( new ListPropertiesProvider ( properties ) ) ;
476480
477481 sut . IsValid . Should ( ) . BeTrue ( ) ;
478- runtime . Logger . Errors . Should ( ) . BeEmpty ( ) ;
479- runtime . Logger . Warnings . Should ( ) . ContainSingle ( expectedMessage ) ;
482+ runtime . Logger . Should ( ) . HaveNoErrors ( )
483+ . And . HaveWarningOnce ( expectedMessage ) ;
480484 runtime . Logger . UIWarnings . Should ( ) . ContainSingle ( expectedMessage ) ;
481485 }
482486
487+ [ TestMethod ]
488+ public void ProcessedArgs_TfsLegacy_SetUseCliTrue ( )
489+ {
490+ using var env = new EnvironmentVariableScope ( ) ;
491+ env . SetVariable ( EnvironmentVariables . IsInTeamFoundationBuild , "true" ) ;
492+ env . SetVariable ( EnvironmentVariables . BuildUriLegacy , "legacy build uri" ) ;
493+ var sut = CreateDefaultArgs ( buildSettings : BuildSettings . GetSettingsFromEnvironment ( ) ) ;
494+ sut . IsValid . Should ( ) . BeTrue ( ) ;
495+ #if NETFRAMEWORK
496+ sut . UseSonarScannerCli . Should ( ) . BeTrue ( ) ;
497+ runtime . Logger . Should ( ) . HaveDebugs ( "Falling back to SonarScannerCLI to guarantee TFS Legacy support." ) ;
498+ #else
499+ sut . UseSonarScannerCli . Should ( ) . BeFalse ( ) ;
500+ #endif
501+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
502+ . And . HaveNoErrors ( ) ;
503+ }
504+
505+ [ TestMethod ]
506+ public void ProcessedArgs_TfsLegacy_SkipCodeCoverage_SetUseCliFalse ( )
507+ {
508+ using var env = new EnvironmentVariableScope ( ) ;
509+ env . SetVariable ( EnvironmentVariables . IsInTeamFoundationBuild , "true" ) ;
510+ env . SetVariable ( EnvironmentVariables . BuildUriLegacy , "legacy build uri" ) ;
511+ env . SetVariable ( EnvironmentVariables . SkipLegacyCodeCoverage , "true" ) ;
512+ var sut = CreateDefaultArgs ( buildSettings : BuildSettings . GetSettingsFromEnvironment ( ) ) ;
513+ sut . IsValid . Should ( ) . BeTrue ( ) ;
514+ sut . UseSonarScannerCli . Should ( ) . BeFalse ( ) ;
515+ runtime . Logger . Should ( ) . HaveNoWarnings ( )
516+ . And . HaveNoErrors ( ) ;
517+ }
518+
483519 private static IEnumerable < object [ ] > ProcessedArgs_SourcesOrTests_Warning_DataSource ( ) =>
484520 [
485521 [ new Property ( SonarProperties . Sources , "src" ) ] ,
@@ -490,6 +526,7 @@ [new Property(SonarProperties.Tests, "tests")],
490526 private ProcessedArgs CreateDefaultArgs ( IAnalysisPropertyProvider cmdLineProperties = null ,
491527 IAnalysisPropertyProvider globalFileProperties = null ,
492528 IAnalysisPropertyProvider scannerEnvProperties = null ,
529+ BuildSettings buildSettings = null ,
493530 string key = "key" ,
494531 string organization = "organization" ) =>
495532 new (
@@ -501,6 +538,7 @@ private ProcessedArgs CreateDefaultArgs(IAnalysisPropertyProvider cmdLinePropert
501538 cmdLineProperties : cmdLineProperties ?? EmptyPropertyProvider . Instance ,
502539 globalFileProperties : globalFileProperties ?? EmptyPropertyProvider . Instance ,
503540 scannerEnvProperties : scannerEnvProperties ?? EmptyPropertyProvider . Instance ,
541+ buildSettings : buildSettings ,
504542 runtime ) ;
505543
506544 private static void AssertExpectedValue ( string key , string expectedValue , ProcessedArgs args )
0 commit comments