|
| 1 | +BeforeAll { |
| 2 | + $script:repairCoverageScriptPath = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..' 'scripts' 'build' 'ci' 'Repair-CodeSceneJaCoCoCoverage.ps1')).Path |
| 3 | + |
| 4 | + function Invoke-RepairCodeSceneJaCoCoCoverageTestScript { |
| 5 | + [CmdletBinding()] |
| 6 | + param( |
| 7 | + [Parameter(Mandatory)][string]$RunnerContent |
| 8 | + ) |
| 9 | + |
| 10 | + $runnerPath = Join-Path $TestDrive 'Run-RepairCodeSceneJaCoCoCoverage.ps1' |
| 11 | + $content = @" |
| 12 | +$RunnerContent |
| 13 | +
|
| 14 | +if (`$null -ne `$LASTEXITCODE) { |
| 15 | + exit `$LASTEXITCODE |
| 16 | +} |
| 17 | +
|
| 18 | +if (`$?) { |
| 19 | + exit 0 |
| 20 | +} |
| 21 | +
|
| 22 | +exit 1 |
| 23 | +"@ |
| 24 | + Set-Content -LiteralPath $runnerPath -Value $content -Encoding utf8 |
| 25 | + |
| 26 | + $output = & pwsh -NoLogo -NoProfile -File $runnerPath 2>&1 |
| 27 | + return [pscustomobject]@{ |
| 28 | + ExitCode = $LASTEXITCODE |
| 29 | + Output = @($output) |
| 30 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +Describe 'Repair-CodeSceneJaCoCoCoverage' { |
| 35 | + It 'normalizes class and sourcefile names to bare filenames' { |
| 36 | + $coveragePath = Join-Path $TestDrive 'coverage.xml' |
| 37 | + Set-Content -LiteralPath $coveragePath -Encoding utf8 -Value @' |
| 38 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 39 | +<report name="Pester"> |
| 40 | + <package name="src/private/build"> |
| 41 | + <class name="src/private/build/Foo" sourcefilename="private/build/Foo.ps1" /> |
| 42 | + <sourcefile name="private/build/Foo.ps1" /> |
| 43 | + </package> |
| 44 | +</report> |
| 45 | +'@ |
| 46 | + |
| 47 | + $runnerContent = "& '$script:repairCoverageScriptPath' -Path '$coveragePath'" |
| 48 | + $result = Invoke-RepairCodeSceneJaCoCoCoverageTestScript -RunnerContent $runnerContent |
| 49 | + |
| 50 | + $result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine) |
| 51 | + [xml]$rewritten = Get-Content -LiteralPath $coveragePath -Raw |
| 52 | + $rewritten.SelectSingleNode('//class[@sourcefilename]').GetAttribute('sourcefilename') | Should -Be 'Foo.ps1' |
| 53 | + $rewritten.SelectSingleNode('//sourcefile[@name]').GetAttribute('name') | Should -Be 'Foo.ps1' |
| 54 | + } |
| 55 | + |
| 56 | + It 'leaves already normalized filenames unchanged' { |
| 57 | + $coveragePath = Join-Path $TestDrive 'coverage-already-normalized.xml' |
| 58 | + Set-Content -LiteralPath $coveragePath -Encoding utf8 -Value @' |
| 59 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 60 | +<report name="Pester"> |
| 61 | + <package name="src/private/build"> |
| 62 | + <class name="src/private/build/Foo" sourcefilename="Foo.ps1" /> |
| 63 | + <sourcefile name="Foo.ps1" /> |
| 64 | + </package> |
| 65 | +</report> |
| 66 | +'@ |
| 67 | + |
| 68 | + $runnerContent = "& '$script:repairCoverageScriptPath' -Path '$coveragePath'" |
| 69 | + $result = Invoke-RepairCodeSceneJaCoCoCoverageTestScript -RunnerContent $runnerContent |
| 70 | + |
| 71 | + $result.ExitCode | Should -Be 0 -Because ($result.Output -join [Environment]::NewLine) |
| 72 | + [xml]$rewritten = Get-Content -LiteralPath $coveragePath -Raw |
| 73 | + $rewritten.SelectSingleNode('//class[@sourcefilename]').GetAttribute('sourcefilename') | Should -Be 'Foo.ps1' |
| 74 | + $rewritten.SelectSingleNode('//sourcefile[@name]').GetAttribute('name') | Should -Be 'Foo.ps1' |
| 75 | + } |
| 76 | +} |
0 commit comments