add workaround for psscript analyzer object reference error
This commit is contained in:
parent
8b45618637
commit
b496eaaa9d
@ -80,6 +80,35 @@ function Invoke-InstallDependencies {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Start-PSScriptAnalyzer {
|
||||||
|
[CmdletBinding()]
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSUseShouldProcessForStateChangingFunctions',
|
||||||
|
'',
|
||||||
|
Justification = 'justification'
|
||||||
|
)]
|
||||||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
|
'PSProvideCommentHelp',
|
||||||
|
'',
|
||||||
|
Justification = 'internal function'
|
||||||
|
)]
|
||||||
|
param ()
|
||||||
|
|
||||||
|
process {
|
||||||
|
$AnalyzerSettings = @{
|
||||||
|
Path = './src/'
|
||||||
|
Recurse = $true
|
||||||
|
Settings = './tools/PSScriptAnalyzerSettings.psd1'
|
||||||
|
ReportSummary = $true
|
||||||
|
ErrorAction = 'Stop'
|
||||||
|
}
|
||||||
|
$AnalyzerResults = Invoke-ScriptAnalyzer @AnalyzerSettings
|
||||||
|
if ( $AnalyzerResults ) {
|
||||||
|
Write-Output -InputObject $AnalyzerSettings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function Invoke-Linter {
|
function Invoke-Linter {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
|
||||||
@ -90,16 +119,20 @@ function Invoke-Linter {
|
|||||||
param ()
|
param ()
|
||||||
|
|
||||||
process {
|
process {
|
||||||
Import-Module -Name PSScriptAnalyzer
|
|
||||||
$AnalyzerSettings = @{
|
|
||||||
Path = './src/'
|
|
||||||
Recurse = $true
|
|
||||||
Settings = './tools/PSScriptAnalyzerSettings.psd1'
|
|
||||||
ReportSummary = $true
|
|
||||||
ErrorAction = 'Stop'
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
$AnalyzerResults = Invoke-ScriptAnalyzer @AnalyzerSettings
|
$AnalyzerResults = Start-PSScriptAnalyzer
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Debug -Message $_.Exception.Message -Debug
|
||||||
|
if ($_.Exception.Message -match 'Object reference not set') {
|
||||||
|
Write-Debug -Message 'ReRun PSScriptAnalyzer' -Debug
|
||||||
|
$AnalyzerResults = Start-PSScriptAnalyzer
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Error -Message 'PSScriptAnalyzer failer'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
if ( $AnalyzerResults ) {
|
if ( $AnalyzerResults ) {
|
||||||
$AnalyzerResults | Sort-Object -Property @(
|
$AnalyzerResults | Sort-Object -Property @(
|
||||||
"ScriptName",
|
"ScriptName",
|
||||||
@ -113,10 +146,6 @@ function Invoke-Linter {
|
|||||||
) -AutoSize | Out-String | Write-Verbose -Verbose
|
) -AutoSize | Out-String | Write-Verbose -Verbose
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
Write-Debug -Message $_.Exception.Message -Debug
|
|
||||||
Write-Error -Message 'PSScriptAnalyzer failer'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +200,12 @@ function Invoke-UnitTest {
|
|||||||
$PesterConf.Filter.ExcludeTag = $ExcludeTag
|
$PesterConf.Filter.ExcludeTag = $ExcludeTag
|
||||||
}
|
}
|
||||||
$TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop'
|
$TestResults = Invoke-Pester -Configuration $PesterConf -ErrorAction 'Stop'
|
||||||
|
|
||||||
|
if ($TestResults.FailedCount -gt 0) {
|
||||||
|
Write-FailureStateFile -StepName 'Pester'
|
||||||
|
throw ('{0} tests failed!' -f $TestResults.FailedCount)
|
||||||
|
}
|
||||||
|
|
||||||
if ($PassThru.IsPresent) {
|
if ($PassThru.IsPresent) {
|
||||||
Write-Output -InputObject $TestResults
|
Write-Output -InputObject $TestResults
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user