Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}