Skip to content

Commit

Permalink
Fix linter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Oct 25, 2022
1 parent 531ff4b commit bd942fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
13 changes: 7 additions & 6 deletions test/Scoop-00Linting.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
BeforeDiscovery {
$scriptDir = @('bin', 'lib', 'libexec', 'test')
}

Describe 'PSScriptAnalyzer' -Tag 'Linter' {
BeforeDiscovery {
$scriptDir = @('.', 'bin', 'lib', 'libexec', 'test')
}

BeforeAll {
$lintSettings = "$PSScriptRoot\..\PSScriptAnalyzerSettings.psd1"
}

It 'PSScriptAnalyzerSettings.ps1 should exist' {
$lintSettings | Should -Exist
}

Context 'Linting all *.psd1, *.psm1 and *.ps1 files' {
BeforeEach {
$analysis = Invoke-ScriptAnalyzer -Path "$PSScriptRoot\..\$_" -Settings $lintSettings
Expand All @@ -23,8 +24,8 @@ Describe 'PSScriptAnalyzer' -Tag 'Linter' {
'*.ps1' { $type = 'Script' }
'*.psd1' { $type = 'Manifest' }
}
Write-Host -f Yellow " [*] $($result.Severity): $($result.Message)"
Write-Host -f Yellow " $($result.RuleName) in $type`: $directory\$($result.ScriptName):$($result.Line)"
Write-Warning " [*] $($result.Severity): $($result.Message)"
Write-Warning " $($result.RuleName) in $type`: $directory\$($result.ScriptName):$($result.Line)"
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions test/bin/init.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#Requires -Version 5.1
Write-Host "PowerShell: $($PSVersionTable.PSVersion)"
Write-Host 'Check and install testsuite dependencies ...'
Write-Output "PowerShell: $($PSVersionTable.PSVersion)"
Write-Output 'Check and install testsuite dependencies ...'
if (Get-InstalledModule -Name Pester -MinimumVersion 5.2 -MaximumVersion 5.99 -ErrorAction SilentlyContinue) {
Write-Host 'Pester 5 is already installed.'
Write-Output 'Pester 5 is already installed.'
} else {
Write-Host 'Installing Pester 5 ...'
Write-Output 'Installing Pester 5 ...'
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name Pester -MinimumVersion 5.2 -MaximumVersion 5.99 -SkipPublisherCheck
}
if (Get-InstalledModule -Name PSScriptAnalyzer -MinimumVersion 1.17 -ErrorAction SilentlyContinue) {
Write-Host 'PSScriptAnalyzer is already installed.'
Write-Output 'PSScriptAnalyzer is already installed.'
} else {
Write-Host 'Installing PSScriptAnalyzer ...'
Write-Output 'Installing PSScriptAnalyzer ...'
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name PSScriptAnalyzer -SkipPublisherCheck
}
if (Get-InstalledModule -Name BuildHelpers -MinimumVersion 2.0 -ErrorAction SilentlyContinue) {
Write-Host 'BuildHelpers is already installed.'
Write-Output 'BuildHelpers is already installed.'
} else {
Write-Host 'Installing BuildHelpers ...'
Write-Output 'Installing BuildHelpers ...'
Install-Module -Repository PSGallery -Scope CurrentUser -Force -Name BuildHelpers -SkipPublisherCheck
}
6 changes: 3 additions & 3 deletions test/bin/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.2.0' }
#Requires -Modules @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.17.1' }
param(
[String] $TestPath = $(Convert-Path "$PSScriptRoot\..\")
[String] $TestPath = (Convert-Path "$PSScriptRoot\..")
)

$pesterConfig = New-PesterConfiguration -Hashtable @{
Expand All @@ -30,7 +30,7 @@ if ($env:CI -eq $true) {
$commitMessage = $env:BHCommitMessage

# Check if tests are called from the Core itself, if so, adding excludes
if ($TestPath -eq $(Convert-Path "$PSScriptRoot\..\")) {
if ($TestPath -eq (Convert-Path "$PSScriptRoot\..")) {
if ($commitMessage -match '!linter') {
Write-Warning "Skipping code linting per commit flag '!linter'"
$excludes += 'Linter'
Expand Down Expand Up @@ -90,7 +90,7 @@ if ($env:CI -eq $true) {
}

# Display CI environment variables
$buildVariables = ( Get-ChildItem -Path 'Env:' ).Where( { $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR|GITHUB_|RUNNER_|SCOOP_)' } )
$buildVariables = (Get-ChildItem -Path 'Env:').Where({ $_.Name -match '^(?:BH|CI(?:_|$)|APPVEYOR|GITHUB_|RUNNER_|SCOOP_)' })
$details = $buildVariables |
Where-Object -FilterScript { $_.Name -notmatch 'EMAIL' } |
Sort-Object -Property 'Name' |
Expand Down

0 comments on commit bd942fc

Please sign in to comment.