From 8a3837ed041ebf11417416d336043ca57d457c06 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:05:04 +0100 Subject: [PATCH 01/23] Test --- .../PSScriptAnalyzer.Tests.ps1 | 66 +++++++++++++------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 203b212b..0c3781da 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -20,34 +20,58 @@ Param( ) BeforeDiscovery { - $rules = @() - $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity - foreach ($ruleObject in $ruleObjects) { - $hashTable = @{} - foreach ($property in $ruleObject.PSObject.Properties) { - $hashTable[$property.Name] = $property.Value + $ruleCollection = @{ + Error = [Collections.Generic.List[hashtable]]::new() + Warning = [Collections.Generic.List[hashtable]]::new() + Information = [Collections.Generic.List[hashtable]]::new() + } + 'Error', 'Warning', 'Information' | ForEach-Object { + $Severity = $_ + Get-ScriptAnalyzerRule -Severity $Severity | Sort-Object -Property Name | ForEach-Object { + $rule = $_ + $ruleCollection[$Severity].Add( + [ordered]@{ + RuleName = $rule.RuleName + CommonName = $rule.CommonName + Description = $rule.Description + } + ) } - $rules += $hashTable } - 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 - Write-Warning "Found [$($testResults.Count)] issues" - } + Context '<_.key>' -ForEach $ruleCollection { + It ' ()' -ForEach $_.Value { - It ' ()' -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:" - } - $issues -join [Environment]::NewLine | Should -BeNullOrEmpty } } + + +# $severity = $_ +# $rules = $ruleCollection[$severity] +# It " rules" -ForEach $rules { +# $ruleName = $_.RuleName +# $commonName = $_.CommonName +# $description = $_.Description +# It " ()" { +# $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -IncludeRule $ruleName +# $testResults | Should -BeNullOrEmpty +# } +# } +# } +# It ' ()' -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:" +# } +# $issues -join [Environment]::NewLine | Should -BeNullOrEmpty +# } +# } From 78d6c371e84f87ac704c68e568775fa8b90e595a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:12:04 +0100 Subject: [PATCH 02/23] test --- .../PSScriptAnalyzer.Tests.ps1 | 71 +++++++------------ 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 0c3781da..fd467268 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -20,58 +20,37 @@ Param( ) BeforeDiscovery { - $ruleCollection = @{ - Error = [Collections.Generic.List[hashtable]]::new() - Warning = [Collections.Generic.List[hashtable]]::new() - Information = [Collections.Generic.List[hashtable]]::new() + $rules = [Collections.Generic.List[hashtable]]::new() + $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity + foreach ($ruleObject in $ruleObjects) { + $rules.Add( + @{ + RuleName = $ruleObject.RuleName + CommonName = $ruleObject.CommonName + Severity = $ruleObject.Severity + Description = $ruleObject.Description + } + ) } - 'Error', 'Warning', 'Information' | ForEach-Object { - $Severity = $_ - Get-ScriptAnalyzerRule -Severity $Severity | Sort-Object -Property Name | ForEach-Object { - $rule = $_ - $ruleCollection[$Severity].Add( - [ordered]@{ - RuleName = $rule.RuleName - CommonName = $rule.CommonName - Description = $rule.Description - } - ) - } - } - + Write-Warning "Discovered [$($rules.Count)] rules" $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') } Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { - Context '<_.key>' -ForEach $ruleCollection { - It ' ()' -ForEach $_.Value { + BeforeAll { + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse + Write-Warning "Found [$($testResults.Count)] issues" + } + It ' ()' -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:" + } + $issues -join [Environment]::NewLine | Should -BeNullOrEmpty } } - - -# $severity = $_ -# $rules = $ruleCollection[$severity] -# It " rules" -ForEach $rules { -# $ruleName = $_.RuleName -# $commonName = $_.CommonName -# $description = $_.Description -# It " ()" { -# $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -IncludeRule $ruleName -# $testResults | Should -BeNullOrEmpty -# } -# } -# } -# It ' ()' -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:" -# } -# $issues -join [Environment]::NewLine | Should -BeNullOrEmpty -# } -# } From 8a2e7c635796d7755b210126e6f9aa2c1b16c9d8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:13:18 +0100 Subject: [PATCH 03/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index fd467268..e05b9284 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -20,11 +20,11 @@ Param( ) BeforeDiscovery { - $rules = [Collections.Generic.List[hashtable]]::new() + $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity foreach ($ruleObject in $ruleObjects) { $rules.Add( - @{ + [ordered]@{ RuleName = $ruleObject.RuleName CommonName = $ruleObject.CommonName Severity = $ruleObject.Severity From 1654f861185cf40382994a858ceb64077620aa47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:17:27 +0100 Subject: [PATCH 04/23] test --- .../PSScriptAnalyzer.Tests.ps1 | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index e05b9284..791ae13e 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -21,7 +21,7 @@ Param( BeforeDiscovery { $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() - $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity + $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity, CommonName foreach ($ruleObject in $ruleObjects) { $rules.Add( [ordered]@{ @@ -42,15 +42,17 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - It ' ()' -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 '' -ForEach ($rules.Severity | Select-Object -Unique) { + It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $Severity) { + $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:" + } + $issues -join [Environment]::NewLine | Should -BeNullOrEmpty } - $issues -join [Environment]::NewLine | Should -BeNullOrEmpty } } From fffbd5965a0fc9b99e827458462248efe2b7e583 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:21:28 +0100 Subject: [PATCH 05/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 791ae13e..2e5e2080 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -42,8 +42,8 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - Context '' -ForEach ($rules.Severity | Select-Object -Unique) { - It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $Severity) { + Context '<_>' -ForEach ($rules.Severity | Select-Object -Unique) { + It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { $issues = @('') $issues += $testResults | Where-Object -Property RuleName -EQ $ruleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') From f2660bb8e570abae318f9f2238c74e4f547d4cd7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:30:48 +0100 Subject: [PATCH 06/23] test --- .../tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 2e5e2080..43e3889f 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -42,17 +42,17 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - Context '<_>' -ForEach ($rules.Severity | Select-Object -Unique) { + Context '<_>' -ForEach 'Error', 'Warning', 'Informational' { It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { - $issues = @('') - $issues += $testResults | Where-Object -Property RuleName -EQ $ruleName | ForEach-Object { + $issues = [Collections.Generic.List[string]]::new() + $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - " - $relativePath`:L$($_.Line):C$($_.Column): $($_.Message)" + $issues.Add(" - $relativePath`:L$($_.Line):C$($_.Column): $($_.Message)") } if ($issues.Count -gt 1) { $issues[0] = "[$($issues.Count - 1)] issues found:" } - $issues -join [Environment]::NewLine | Should -BeNullOrEmpty + $issues -join [Environment]::NewLine | Should -BeNullOrEmpty -Because $Description } } } From 41f6a41da62cc794365f27681b3c13c8b97d3822 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:37:50 +0100 Subject: [PATCH 07/23] Issues --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 43e3889f..e20a7851 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -42,7 +42,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - Context '<_>' -ForEach 'Error', 'Warning', 'Informational' { + Context 'Severity: [<_>]' -ForEach 'Error', 'Warning', 'Information' { It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { From 26558eaa1ef207aa088a36cc26d7ab28c911fb97 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:38:46 +0100 Subject: [PATCH 08/23] Issues --- tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 | 2 +- tests/src/PSModuleTest/public/New-PSModuleTest.ps1 | 9 --------- tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 | 1 + tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 | 3 ++- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 index 0e9aacfe..e9cb7c24 100644 --- a/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 @@ -16,5 +16,5 @@ function Get-PSModuleTest { [Parameter(Mandatory)] [string] $Name ) - Write-Output "Hello, $Name!" + Write-Host "Hello, $Name!" } diff --git a/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 index 7f26215f..ff9f883f 100644 --- a/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 @@ -1,15 +1,6 @@ #Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'} function New-PSModuleTest { - <# - .SYNOPSIS - Performs tests on a module. - - .EXAMPLE - Test-PSModule -Name 'World' - - "Hello, World!" - #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', Justification = 'Reason for suppressing' diff --git a/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 index a87ac117..3897fff7 100644 --- a/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 @@ -18,5 +18,6 @@ [Parameter(Mandatory)] [string] $Name ) + Write-Output "Hello, $Name!" } diff --git a/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 index 26be2b9b..213e4302 100644 --- a/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 @@ -14,5 +14,6 @@ [Parameter(Mandatory)] [string] $Name ) - Write-Output "Hello, $Name!" + + Write-Host "Hello, $Name!" } From 1c77aa7c7a90f73664ed33ca9d11475baa8787de Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:43:29 +0100 Subject: [PATCH 09/23] fix --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index e20a7851..031a4fe4 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -47,7 +47,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - $issues.Add(" - $relativePath`:L$($_.Line):C$($_.Column): $($_.Message)") + $issues.Add(" - $relativePath`:L$($_.Line):C$($_.Column)") } if ($issues.Count -gt 1) { $issues[0] = "[$($issues.Count - 1)] issues found:" From 855bc27eca6550a14ce81b37a9283afd36522e6b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:46:01 +0100 Subject: [PATCH 10/23] Fix --- scripts/helpers/Test-PSModule.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index 725c3071..c97ddc59 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -175,13 +175,11 @@ function Test-PSModule { #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 From 3e6fac43cbef5e177b736017fe0a1ed9677f7de1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:50:33 +0100 Subject: [PATCH 11/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 031a4fe4..46349aa7 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -47,12 +47,9 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') - $issues.Add(" - $relativePath`:L$($_.Line):C$($_.Column)") + $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } - if ($issues.Count -gt 1) { - $issues[0] = "[$($issues.Count - 1)] issues found:" - } - $issues -join [Environment]::NewLine | Should -BeNullOrEmpty -Because $Description + $issues | Should -BeNullOrEmpty -Because $Description } } } From bbc141391228283a60a0c85ffa1e3c96bbd6105a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:53:11 +0100 Subject: [PATCH 12/23] test --- scripts/helpers/Test-PSModule.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index c97ddc59..37cc84e6 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -167,7 +167,6 @@ function Test-PSModule { Verbosity = 'Detailed' } } - Verbose = $false } Write-Verbose 'PesterParams:' Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)" From ce419820cba91f601c77c5e73c195e946dce7a82 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:54:48 +0100 Subject: [PATCH 13/23] fix --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 46349aa7..fc41efcf 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -42,7 +42,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] Write-Warning "Found [$($testResults.Count)] issues" } - Context 'Severity: [<_>]' -ForEach 'Error', 'Warning', 'Information' { + Context 'Severity: <_>' -ForEach 'Error', 'Warning', 'Information' { It ' ()' -ForEach ($rules | Where-Object -Property Severity -EQ $_) { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $RuleName | ForEach-Object { From a796bf58185dd3dcada397acce7e2b721c20a773 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 19:57:41 +0100 Subject: [PATCH 14/23] Fix --- .github/workflows/Action-Test.yml | 4 ++++ .github/workflows/Auto-Release.yml | 3 ++- .github/workflows/Linter.yml | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index cc37fe00..c7316409 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -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: diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index 4734f273..ec157c9d 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -14,7 +14,8 @@ on: - labeled concurrency: - group: ${{ github.workflow }} + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true permissions: contents: write diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index cfd32e6e..0a31f9bf 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -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 From e7e97c575a4cf0751c312489d42754c3d228efef Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:02:40 +0100 Subject: [PATCH 15/23] test --- scripts/helpers/Test-PSModule.ps1 | 1 - scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index 37cc84e6..07a94288 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -178,7 +178,6 @@ function Test-PSModule { $VerbosePreference = 'SilentlyContinue' $results = Invoke-Pester @pesterParams $VerbosePreference = $verbosepref - Write-Verbose 'Done' #endregion $results diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index fc41efcf..7db97ca3 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -49,7 +49,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } - $issues | Should -BeNullOrEmpty -Because $Description + $issues -join '' | Should -BeNullOrEmpty -Because $Description } } } From e6124d04562188a6e018692e04e0669b27c550bc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:07:11 +0100 Subject: [PATCH 16/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 7db97ca3..ab078d54 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -49,7 +49,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } - $issues -join '' | Should -BeNullOrEmpty -Because $Description + $issues -join '' | Should -BeNullOrEmpty # -Because $Description } } } From 4174a29fae9eeba37356f3910e2d65d737d8fcd9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:11:29 +0100 Subject: [PATCH 17/23] test --- scripts/helpers/Test-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index 07a94288..d6070158 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -164,7 +164,7 @@ function Test-PSModule { Output = @{ CIFormat = 'Auto' StackTraceVerbosity = 'None' - Verbosity = 'Detailed' + # Verbosity = 'Detailed' } } } From 0ff8aa42276730a5d137ecf15e521af3a42e4b1d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:14:06 +0100 Subject: [PATCH 18/23] test --- scripts/helpers/Test-PSModule.ps1 | 2 +- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/Test-PSModule.ps1 b/scripts/helpers/Test-PSModule.ps1 index d6070158..07a94288 100644 --- a/scripts/helpers/Test-PSModule.ps1 +++ b/scripts/helpers/Test-PSModule.ps1 @@ -164,7 +164,7 @@ function Test-PSModule { Output = @{ CIFormat = 'Auto' StackTraceVerbosity = 'None' - # Verbosity = 'Detailed' + Verbosity = 'Detailed' } } } diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index ab078d54..4d9bbce1 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -21,7 +21,7 @@ Param( BeforeDiscovery { $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() - $ruleObjects = Get-ScriptAnalyzerRule | Sort-Object -Property Severity, CommonName + $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName foreach ($ruleObject in $ruleObjects) { $rules.Add( [ordered]@{ @@ -38,7 +38,7 @@ BeforeDiscovery { 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" } From 3a6ab25f63978714387d522ef0abb649b7c87ddd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:25:38 +0100 Subject: [PATCH 19/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 4d9bbce1..909457c7 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -47,9 +47,9 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $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.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column) - $($_.SuggestedCorrections.Description)")) } - $issues -join '' | Should -BeNullOrEmpty # -Because $Description + $issues -join '' | Should -BeNullOrEmpty -Because $Description } } } From 635368389e814b4dc864b616cb6d803ca60b45e5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:27:34 +0100 Subject: [PATCH 20/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 909457c7..250ae5d8 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -49,6 +49,7 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column) - $($_.SuggestedCorrections.Description)")) } + $issues -join '' | Should -BeNullOrEmpty -Because $Description } } From fc8c291d4ddc7aa540052d80f744f08d5f562e81 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:30:35 +0100 Subject: [PATCH 21/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 250ae5d8..12a38203 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -47,10 +47,13 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] $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) - $($_.SuggestedCorrections.Description)")) + $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } - $issues -join '' | Should -BeNullOrEmpty -Because $Description } } } + +AfterAll { + $issues +} From 66aff4b6d021f8641fb6a8f6cdcd1afa063182c0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:32:45 +0100 Subject: [PATCH 22/23] test --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 12a38203..2a6039b8 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -53,7 +53,3 @@ Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath] } } } - -AfterAll { - $issues -} From 6b6b6b8d0eac827a2c6d16fae577595f0521da1b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 28 Mar 2024 20:34:06 +0100 Subject: [PATCH 23/23] fix --- tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 | 2 +- tests/src/PSModuleTest/public/New-PSModuleTest.ps1 | 9 +++++++++ tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 | 1 - tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 | 3 +-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 index e9cb7c24..0e9aacfe 100644 --- a/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Get-PSModuleTest.ps1 @@ -16,5 +16,5 @@ function Get-PSModuleTest { [Parameter(Mandatory)] [string] $Name ) - Write-Host "Hello, $Name!" + Write-Output "Hello, $Name!" } diff --git a/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 index ff9f883f..7f26215f 100644 --- a/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/New-PSModuleTest.ps1 @@ -1,6 +1,15 @@ #Requires -Modules @{ModuleName='PSSemVer'; ModuleVersion='1.0'} function New-PSModuleTest { + <# + .SYNOPSIS + Performs tests on a module. + + .EXAMPLE + Test-PSModule -Name 'World' + + "Hello, World!" + #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', Justification = 'Reason for suppressing' diff --git a/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 index 3897fff7..a87ac117 100644 --- a/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Set-PSModuleTest.ps1 @@ -18,6 +18,5 @@ [Parameter(Mandatory)] [string] $Name ) - Write-Output "Hello, $Name!" } diff --git a/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 b/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 index 213e4302..26be2b9b 100644 --- a/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 +++ b/tests/src/PSModuleTest/public/Test-PSModuleTest.ps1 @@ -14,6 +14,5 @@ [Parameter(Mandatory)] [string] $Name ) - - Write-Host "Hello, $Name!" + Write-Output "Hello, $Name!" }