Skip to content

Commit 5396998

Browse files
🪲 [Fix]: Issues with changing collection on Pester + PSSA (#42)
## Description - Fixes #41 ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 886f51f commit 5396998

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

.github/workflows/Action-Test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.eve
44

55
on: [pull_request]
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
711
permissions: {}
812

913
jobs:

.github/workflows/Auto-Release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414
- labeled
1515

1616
concurrency:
17-
group: ${{ github.workflow }}
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
1819

1920
permissions:
2021
contents: write

.github/workflows/Linter.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pu
44

55
on: [pull_request]
66

7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
711
permissions:
812
contents: read
913
packages: read

scripts/helpers/Test-PSModule.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,17 @@ function Test-PSModule {
167167
Verbosity = 'Detailed'
168168
}
169169
}
170-
Verbose = $false
171170
}
172171
Write-Verbose 'PesterParams:'
173172
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
174173
Stop-LogGroup
175174
#endregion
176175

177176
#region Run tests
178-
Start-LogGroup 'Run tests'
179177
$verbosepref = $VerbosePreference
180178
$VerbosePreference = 'SilentlyContinue'
181179
$results = Invoke-Pester @pesterParams
182180
$VerbosePreference = $verbosepref
183-
Write-Verbose 'Done'
184-
Stop-LogGroup
185181
#endregion
186182

187183
$results

scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ Param(
2020
)
2121

2222
BeforeDiscovery {
23-
$rules = @()
24-
$ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity
23+
$rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new()
24+
$ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName
2525
foreach ($ruleObject in $ruleObjects) {
26-
$hashTable = @{}
27-
foreach ($property in $ruleObject.PSObject.Properties) {
28-
$hashTable[$property.Name] = $property.Value
29-
}
30-
$rules += $hashTable
26+
$rules.Add(
27+
[ordered]@{
28+
RuleName = $ruleObject.RuleName
29+
CommonName = $ruleObject.CommonName
30+
Severity = $ruleObject.Severity
31+
Description = $ruleObject.Description
32+
}
33+
)
3134
}
3235
Write-Warning "Discovered [$($rules.Count)] rules"
3336
$relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/')
3437
}
3538

3639
Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" {
3740
BeforeAll {
38-
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse
41+
$testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false
3942
Write-Warning "Found [$($testResults.Count)] issues"
4043
}
4144

42-
It '<CommonName> (<RuleName>)' -ForEach $rules {
43-
$issues = @('')
44-
$issues += $testResults | Where-Object -Property RuleName -EQ $ruleName | ForEach-Object {
45-
$relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/')
46-
" - $relativePath`:L$($_.Line):C$($_.Column): $($_.Message)"
47-
}
48-
if ($issues.Count -gt 1) {
49-
$issues[0] = "[$($issues.Count - 1)] issues found:"
45+
Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' {
46+
It '<CommonName> (<RuleName>)' -ForEach ($rules | Where-Object -Property Severity -EQ $_) {
47+
$issues = [Collections.Generic.List[string]]::new()
48+
$testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object {
49+
$relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/')
50+
$issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)"))
51+
}
52+
$issues -join '' | Should -BeNullOrEmpty -Because $Description
5053
}
51-
$issues -join [Environment]::NewLine | Should -BeNullOrEmpty
5254
}
5355
}

0 commit comments

Comments
 (0)