Skip to content

Commit

Permalink
🪲 [Fix]: Issues with changing collection on Pester + PSSA (#42)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
MariusStorhaug authored Mar 28, 2024
1 parent 886f51f commit 5396998
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.eve

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ on:
- labeled

concurrency:
group: ${{ github.workflow }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/Linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ run-name: "Linter - [${{ github.event.pull_request.title }} #${{ github.event.pu

on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
packages: read
Expand Down
4 changes: 0 additions & 4 deletions scripts/helpers/Test-PSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -167,21 +167,17 @@ function Test-PSModule {
Verbosity = 'Detailed'
}
}
Verbose = $false
}
Write-Verbose 'PesterParams:'
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
Stop-LogGroup
#endregion

#region Run tests
Start-LogGroup 'Run tests'
$verbosepref = $VerbosePreference
$VerbosePreference = 'SilentlyContinue'
$results = Invoke-Pester @pesterParams
$VerbosePreference = $verbosepref
Write-Verbose 'Done'
Stop-LogGroup
#endregion

$results
Expand Down
36 changes: 19 additions & 17 deletions scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,36 @@ Param(
)

BeforeDiscovery {
$rules = @()
$ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity
$rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new()
$ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName
foreach ($ruleObject in $ruleObjects) {
$hashTable = @{}
foreach ($property in $ruleObject.PSObject.Properties) {
$hashTable[$property.Name] = $property.Value
}
$rules += $hashTable
$rules.Add(
[ordered]@{
RuleName = $ruleObject.RuleName
CommonName = $ruleObject.CommonName
Severity = $ruleObject.Severity
Description = $ruleObject.Description
}
)
}
Write-Warning "Discovered [$($rules.Count)] rules"
$relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/')
}

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

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

0 comments on commit 5396998

Please sign in to comment.