Add tests for Test-PSBuildScriptAnalysis (fixes #96)#106
Add tests for Test-PSBuildScriptAnalysis (fixes #96)#106nthbotast wants to merge 1 commit intopsake:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds targeted Pester coverage for Test-PSBuildScriptAnalysis (per #96) and fixes a bug in how ScriptAnalyzer result severities are counted so pass/fail behavior works correctly at -SeverityThreshold Error.
Changes:
- Add
tests/Test-PSBuildScriptAnalysis.tests.ps1with Pester scenarios assertingInvoke-ScriptAnalyzeris invoked with the provided-SettingsPathand that error-threshold behavior throws/doesn’t throw as expected. - Fix severity counting in
Test-PSBuildScriptAnalysisby filtering on$_.Severityrather than an incorrect variable name.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/Test-PSBuildScriptAnalysis.tests.ps1 | New Pester unit tests covering settings forwarding and error-threshold pass/fail behavior. |
| PowerShellBuild/Public/Test-PSBuildScriptAnalysis.ps1 | Corrects severity filtering to accurately count Error/Warning/Information results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Test-PSBuildScriptAnalysis -Path 'function Test-Me { "ok" }' -SeverityThreshold Error -SettingsPath 'tests/ScriptAnalyzerSettings.psd1' | ||
|
|
||
| Should -Invoke -CommandName Invoke-ScriptAnalyzer -Times 1 -Exactly -ParameterFilter { | ||
| $Path -eq 'function Test-Me { "ok" }' -and | ||
| $Settings -eq 'tests/ScriptAnalyzerSettings.psd1' -and | ||
| $Recurse |
There was a problem hiding this comment.
The tests pass a script source string into -Path, but Test-PSBuildScriptAnalysis (and Invoke-ScriptAnalyzer -Path) are documented/implemented to take a filesystem path (module dir/script file). This makes the tests less representative and could mislead future readers into thinking inline script strings are supported. Consider writing the inline content to a temp file under TestDrive: (or creating a temp dir) and passing that path instead; similarly, construct -SettingsPath via Join-Path $PSScriptRoot ... to avoid depending on the current working directory.
Summary
Test-PSBuildScriptAnalysisInvoke-ScriptAnalyzeris called with the provided-SettingsPath-SeverityThreshold Error$_.Severityin the analyzer result filtersValidation
pwsh) is unavailable; CI should run the suite on PRCloses #96