Skip to content

Commit

Permalink
Skip PSScriptAnalyzer where it may be unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed May 5, 2018
1 parent ccaf0d6 commit 2a5307b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
26 changes: 14 additions & 12 deletions test/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ If (-Not($nuget)) {
}
Write-Host " - NuGet version: $($nuget.Version.ToString())"

$psScriptAnalyzer = Get-Module -Name PSScriptAnalyzer
If (-Not($psScriptAnalyzer)) {
$psScriptAnalyzer = Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }
If ($psScriptAnalyzer -is [array]) {
$psScriptAnalyzer = $psScriptAnalyzer[0]
}
If (-Not($psScriptAnalyzer)) {
Write-Host ' - installing PSScriptAnalyzer'
Install-Module -Name PSScriptAnalyzer -Force
$psScriptAnalyzer = Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }
}
If ($PSVersionTable.PSEdition -ne 'Core') {
$psScriptAnalyzer = Get-Module -Name PSScriptAnalyzer
If (-Not($psScriptAnalyzer)) {
$psScriptAnalyzer = Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }
If ($psScriptAnalyzer -is [array]) {
$psScriptAnalyzer = $psScriptAnalyzer[0]
}
If (-Not($psScriptAnalyzer)) {
Write-Host ' - installing PSScriptAnalyzer'
Install-Module -Name PSScriptAnalyzer -Force
$psScriptAnalyzer = Get-Module -ListAvailable | Where-Object { $_.Name -eq 'PSScriptAnalyzer' }
}
}
Write-Host " - PSScriptAnalyzer version: $($psScriptAnalyzer.Version.ToString())"
}
Write-Host " - PSScriptAnalyzer version: $($psScriptAnalyzer.Version.ToString())"

$pester = Get-Module -Name Pester | Where-Object { $_.Version -ge '4.3' }
If (-Not($pester)) {
Expand Down
14 changes: 8 additions & 6 deletions test/tests/Syntax.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ Describe 'Syntax' {
$errors.Count | Should Be 0
}

It -Name '<file> should pass PSScriptAnalyzer' -TestCases $testCases {
param($file)
$problems = @(Invoke-ScriptAnalyzer -Path $file.FullName -ExcludeRule PSUseShouldProcessForStateChangingFunctions -Severity Warning, Error)
If ($problems) {
$problems | Format-Table | Out-String | Write-Host
If ($PSVersionTable.PSEdition -ne 'Core') {
It -Name '<file> should pass PSScriptAnalyzer' -TestCases $testCases {
param($file)
$problems = @(Invoke-ScriptAnalyzer -Path $file.FullName -ExcludeRule PSUseShouldProcessForStateChangingFunctions -Severity Warning, Error)
If ($problems) {
$problems | Format-Table | Out-String | Write-Host
}
@($problems).Count | Should Be 0
}
@($problems).Count | Should Be 0
}
}

0 comments on commit 2a5307b

Please sign in to comment.