@@ -443,6 +443,26 @@ try {
443443 Assert-Equal 6 $summary.total_branches ' Distinct branch site total branches differ.'
444444 }
445445
446+ Invoke-Test ' does not double count class lines which precede methods' {
447+ $testCase = New-TestCase
448+ $sourceFile = [Security.SecurityElement ]::Escape((Join-Path $testCase.SourceRoot ' Example.cs' ))
449+ $xml = @"
450+ <coverage><packages><package><classes>
451+ <class name="ContainingType" filename="$sourceFile ">
452+ <lines><line number="10" hits="1" branch="True" condition-coverage="50% (1/2)" /></lines>
453+ <methods><method name="Method" signature="()"><lines>
454+ <line number="10" hits="1" branch="True" condition-coverage="50% (1/2)" />
455+ </lines></method></methods>
456+ </class>
457+ </classes></package></packages></coverage>
458+ "@
459+ [void ] (Write-Report $testCase $xml )
460+ Invoke-Summarizer $testCase
461+ $summary = Get-Content - Raw $testCase.JsonOutput | ConvertFrom-Json
462+ Assert-Equal 1 $summary.covered_branches ' Reordered covered branches differ.'
463+ Assert-Equal 2 $summary.total_branches ' Reordered total branches differ.'
464+ }
465+
446466 Invoke-Test ' rejects inconsistent branch coverage' {
447467 $testCase = New-TestCase
448468 $lines = @'
@@ -820,30 +840,41 @@ exit 0
820840 $expectedArtifacts = Join-Path $testCase.Root ' expected.txt'
821841 [IO.File ]::WriteAllLines(
822842 $expectedArtifacts ,
823- @ (' test_output_first ' , ' test_output_second ' ),
843+ @ (' test_output_a ' , ' test_output_B ' ),
824844 [Text.UTF8Encoding ]::new($false )
825845 )
826- $firstArtifact = Join-Path $testCase.ReportDirectory ' coverage_test_output_first '
846+ $firstArtifact = Join-Path $testCase.ReportDirectory ' coverage_test_output_a '
827847 [void ] (New-Item - ItemType Directory - Path $firstArtifact )
828848 [IO.File ]::WriteAllText(
829- (Join-Path $firstArtifact ' test_output_first .cobertura.xml' ),
849+ (Join-Path $firstArtifact ' test_output_a .cobertura.xml' ),
830850 ' <coverage />' ,
831851 [Text.UTF8Encoding ]::new($false )
832852 )
833- Write-ArtifactMetadata $firstArtifact ' test_output_first '
853+ Write-ArtifactMetadata $firstArtifact ' test_output_a '
834854 Assert-Throws `
835855 { Invoke-ArtifactValidator $testCase.ReportDirectory $expectedArtifacts } `
836- ' Missing: coverage_test_output_second '
856+ ' Missing: coverage_test_output_B '
837857
838- $secondArtifact = Join-Path $testCase.ReportDirectory ' coverage_test_output_second '
858+ $secondArtifact = Join-Path $testCase.ReportDirectory ' coverage_test_output_B '
839859 [void ] (New-Item - ItemType Directory - Path $secondArtifact )
840860 [IO.File ]::WriteAllText(
841- (Join-Path $secondArtifact ' test_output_second .cobertura.xml' ),
861+ (Join-Path $secondArtifact ' test_output_B .cobertura.xml' ),
842862 ' <coverage />' ,
843863 [Text.UTF8Encoding ]::new($false )
844864 )
845- Write-ArtifactMetadata $secondArtifact ' test_output_second '
865+ Write-ArtifactMetadata $secondArtifact ' test_output_B '
846866 Invoke-ArtifactValidator $testCase.ReportDirectory $expectedArtifacts | Out-Null
867+ $validationPath = Join-Path $testCase.Root ' validation.json'
868+ $firstManifestSha = (Get-Content - Raw $validationPath | ConvertFrom-Json ).manifest_sha256
869+ $previousCulture = [Threading.Thread ]::CurrentThread.CurrentCulture
870+ try {
871+ [Threading.Thread ]::CurrentThread.CurrentCulture = [Globalization.CultureInfo ]::GetCultureInfo(' tr-TR' )
872+ Invoke-ArtifactValidator $testCase.ReportDirectory $expectedArtifacts | Out-Null
873+ } finally {
874+ [Threading.Thread ]::CurrentThread.CurrentCulture = $previousCulture
875+ }
876+ $secondManifestSha = (Get-Content - Raw $validationPath | ConvertFrom-Json ).manifest_sha256
877+ Assert-Equal $firstManifestSha $secondManifestSha ' Artifact manifest fingerprints must use ordinal ordering.'
847878
848879 $unexpectedArtifact = Join-Path $testCase.ReportDirectory ' coverage_test_output_unexpected'
849880 [void ] (New-Item - ItemType Directory - Path $unexpectedArtifact )
@@ -979,22 +1010,37 @@ exit 0
9791010 $testCase = New-TestCase
9801011 $repository = Join-Path $testCase.Root ' repository'
9811012 [void ] (New-Item - ItemType Directory - Path (Join-Path $repository ' .github/scripts' ) - Force)
982- [IO.File ]::WriteAllText((Join-Path $repository ' .github/scripts/first .ps1' ), ' first' , [Text.UTF8Encoding ]::new($false ))
983- [IO.File ]::WriteAllText((Join-Path $repository ' global.json ' ), ' {} ' , [Text.UTF8Encoding ]::new($false ))
1013+ [IO.File ]::WriteAllText((Join-Path $repository ' .github/scripts/a .ps1' ), ' first' , [Text.UTF8Encoding ]::new($false ))
1014+ [IO.File ]::WriteAllText((Join-Path $repository ' .github/scripts/B.ps1 ' ), ' second ' , [Text.UTF8Encoding ]::new($false ))
9841015 $manifest = Join-Path $testCase.Root ' inputs.txt'
9851016 [IO.File ]::WriteAllLines(
9861017 $manifest ,
987- @ (' global.json ' , ' .github/scripts/first .ps1' ),
1018+ @ (' .github/scripts/a.ps1 ' , ' .github/scripts/B .ps1' ),
9881019 [Text.UTF8Encoding ]::new($false )
9891020 )
9901021 $firstOutput = Join-Path $testCase.Root ' first.json'
1022+ $reorderedOutput = Join-Path $testCase.Root ' reordered.json'
9911023 $secondOutput = Join-Path $testCase.Root ' second.json'
9921024 & $coverageInputFingerprintScriptPath - RepositoryRoot $repository - Manifest $manifest - JsonOutput $firstOutput
993- [IO.File ]::WriteAllText((Join-Path $repository ' .github/scripts/first.ps1' ), ' changed' , [Text.UTF8Encoding ]::new($false ))
1025+ [IO.File ]::WriteAllLines(
1026+ $manifest ,
1027+ @ (' .github/scripts/B.ps1' , ' .github/scripts/a.ps1' ),
1028+ [Text.UTF8Encoding ]::new($false )
1029+ )
1030+ $previousCulture = [Threading.Thread ]::CurrentThread.CurrentCulture
1031+ try {
1032+ [Threading.Thread ]::CurrentThread.CurrentCulture = [Globalization.CultureInfo ]::GetCultureInfo(' tr-TR' )
1033+ & $coverageInputFingerprintScriptPath - RepositoryRoot $repository - Manifest $manifest - JsonOutput $reorderedOutput
1034+ } finally {
1035+ [Threading.Thread ]::CurrentThread.CurrentCulture = $previousCulture
1036+ }
1037+ [IO.File ]::WriteAllText((Join-Path $repository ' .github/scripts/a.ps1' ), ' changed' , [Text.UTF8Encoding ]::new($false ))
9941038 & $coverageInputFingerprintScriptPath - RepositoryRoot $repository - Manifest $manifest - JsonOutput $secondOutput
9951039 $first = Get-Content - Raw $firstOutput | ConvertFrom-Json
1040+ $reordered = Get-Content - Raw $reorderedOutput | ConvertFrom-Json
9961041 $second = Get-Content - Raw $secondOutput | ConvertFrom-Json
9971042 Assert-Equal 2 $first.files ' Coverage input file count differs.'
1043+ Assert-Equal $first.sha256 $reordered.sha256 ' Coverage input fingerprints must use ordinal ordering.'
9981044 Assert-Equal $false ($first.sha256 -eq $second.sha256 ) ' Coverage input changes must change the fingerprint.'
9991045 }
10001046
0 commit comments