Skip to content

Commit fdbc52e

Browse files
🩹 [Patch]: Update PSScriptAnalyzer test logging for improved path resolution and clarity
1 parent c76fdf7 commit fdbc52e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

‎scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,23 @@ Describe 'PSScriptAnalyzer' {
7272
} else {
7373
$SettingsFilePath
7474
}
75+
$Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path
76+
$relativePath = if ($Path.StartsWith($PSScriptRoot)) {
77+
$Path.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/')
78+
} elseif ($Path.StartsWith($env:GITHUB_WORKSPACE)) {
79+
$Path.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/')
80+
} else {
81+
$Path
82+
}
83+
7584
[pscustomobject]@{
7685
relativeSettingsFilePath = $relativeSettingsFilePath
7786
SettingsFilePath = $SettingsFilePath
7887
PSScriptRoot = $PSScriptRoot
7988
GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE
8089
}
81-
$Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path
82-
LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" {
90+
91+
LogGroup "Invoke-ScriptAnalyzer -Path [$relativePath] -Settings [$relativeSettingsFilePath]" {
8392
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose
8493
}
8594
LogGroup "TestResults [$($testResults.Count)]" {
@@ -97,7 +106,6 @@ Describe 'PSScriptAnalyzer' {
97106
It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } {
98107
$issues = [Collections.Generic.List[string]]::new()
99108
$testResults | Where-Object { $_.RuleName -eq $Rule.RuleName } | ForEach-Object {
100-
$relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/')
101109
$issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)"))
102110
}
103111
$issues -join '' | Should -BeNullOrEmpty -Because $rule.Description

0 commit comments

Comments
 (0)