|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [Parameter(Mandatory)] |
| 4 | + [string] $WorkingDirectory, |
| 5 | + |
| 6 | + [Parameter(Mandatory)] |
| 7 | + [string] $TestResultPath, |
| 8 | + |
| 9 | + [Parameter(Mandatory)] |
| 10 | + [string] $CodeCoveragePath |
| 11 | +) |
| 12 | + |
| 13 | +function Assert-ReportPath { |
| 14 | + [CmdletBinding()] |
| 15 | + param( |
| 16 | + [Parameter(Mandatory)] |
| 17 | + [string] $Path, |
| 18 | + |
| 19 | + [Parameter(Mandatory)] |
| 20 | + [string] $ReportName, |
| 21 | + |
| 22 | + [Parameter(Mandatory)] |
| 23 | + [string] $ArtifactDirectory |
| 24 | + ) |
| 25 | + |
| 26 | + $resolvedPath = [System.IO.Path]::GetFullPath($Path) |
| 27 | + $resolvedArtifactDirectory = [System.IO.Path]::GetFullPath($ArtifactDirectory).TrimEnd( |
| 28 | + [System.IO.Path]::DirectorySeparatorChar, |
| 29 | + [System.IO.Path]::AltDirectorySeparatorChar |
| 30 | + ) + [System.IO.Path]::DirectorySeparatorChar |
| 31 | + |
| 32 | + if (-not $resolvedPath.StartsWith($resolvedArtifactDirectory, [System.StringComparison]::OrdinalIgnoreCase)) { |
| 33 | + throw "Expected $ReportName report beneath [$resolvedArtifactDirectory], but found [$resolvedPath]." |
| 34 | + } |
| 35 | + |
| 36 | + foreach ($reportPath in @($resolvedPath, [System.IO.Path]::ChangeExtension($resolvedPath, '.json'))) { |
| 37 | + if (-not (Test-Path -Path $reportPath -PathType Leaf)) { |
| 38 | + throw "Expected $ReportName report at [$reportPath]." |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + try { |
| 43 | + $null = [xml](Get-Content -Path $resolvedPath -Raw) |
| 44 | + } catch { |
| 45 | + throw "Expected an XML $ReportName report at [$resolvedPath]." |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +$resolvedWorkingDirectory = [System.IO.Path]::GetFullPath($WorkingDirectory) |
| 50 | +$artifactDirectory = Join-Path -Path $resolvedWorkingDirectory -ChildPath '.PSModule' |
| 51 | + |
| 52 | +Assert-ReportPath -Path (Join-Path -Path $resolvedWorkingDirectory -ChildPath $TestResultPath) ` |
| 53 | + -ReportName 'test result' ` |
| 54 | + -ArtifactDirectory $artifactDirectory |
| 55 | +Assert-ReportPath -Path (Join-Path -Path $resolvedWorkingDirectory -ChildPath $CodeCoveragePath) ` |
| 56 | + -ReportName 'code coverage' ` |
| 57 | + -ArtifactDirectory $artifactDirectory |
| 58 | + |
| 59 | +foreach ($unexpectedDirectory in @('TestResult', 'CodeCoverage', '.temp')) { |
| 60 | + $unexpectedPath = Join-Path -Path $resolvedWorkingDirectory -ChildPath $unexpectedDirectory |
| 61 | + if (Test-Path -Path $unexpectedPath) { |
| 62 | + throw "Did not expect generated action state at [$unexpectedPath]." |
| 63 | + } |
| 64 | +} |
0 commit comments