Skip to content

Commit a3a198d

Browse files
Add regression test for analyzer report paths
1 parent 4d633e4 commit a3a198d

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,37 @@ jobs:
121121
Write-Host "Outcome: ${{ steps.action-test.outcome }}"
122122
Write-Host "Conclusion: ${{ steps.action-test.conclusion }}"
123123
124+
ActionTestReportPaths:
125+
name: Action-Test - [Report Paths]
126+
runs-on: ubuntu-latest
127+
steps:
128+
- name: Checkout repo
129+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
130+
with:
131+
persist-credentials: false
132+
133+
- name: Action-Test
134+
uses: ./
135+
id: action-test
136+
with:
137+
Path: src
138+
WorkingDirectory: tests/srcTestRepo
139+
TestResult_Enabled: true
140+
TestResult_OutputFormat: NUnitXml
141+
TestResult_OutputPath: .PSModule/TestResult/PSScriptAnalyzer-TestResult-Report.xml
142+
CodeCoverage_Enabled: true
143+
CodeCoverage_OutputFormat: JaCoCo
144+
CodeCoverage_OutputPath: .PSModule/CodeCoverage/PSScriptAnalyzer-CodeCoverage-Report.xml
145+
CodeCoverage_Path: ../../src/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1
146+
147+
- name: Assert report paths
148+
shell: pwsh
149+
run: |
150+
tests/Assert-ReportPaths.ps1 `
151+
-WorkingDirectory tests/srcTestRepo `
152+
-TestResultPath .PSModule/TestResult/PSScriptAnalyzer-TestResult-Report.xml `
153+
-CodeCoveragePath .PSModule/CodeCoverage/PSScriptAnalyzer-CodeCoverage-Report.xml
154+
124155
ActionTestOutputs:
125156
name: Action-Test - [outputs]
126157
runs-on: ubuntu-latest
@@ -153,6 +184,7 @@ jobs:
153184
- ActionTestSrcCustom
154185
- ActionTestSrcWithManifest
155186
- ActionTestSrcWithManifestDefault
187+
- ActionTestReportPaths
156188
- ActionTestOutputs
157189
if: always()
158190
runs-on: ubuntu-latest

tests/Assert-ReportPaths.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)