Skip to content

Add tests for Test-PSBuildScriptAnalysis (fixes #96)#106

Open
nthbotast wants to merge 1 commit intopsake:mainfrom
nthbotast:feat/test-scriptanalysis-issue-96
Open

Add tests for Test-PSBuildScriptAnalysis (fixes #96)#106
nthbotast wants to merge 1 commit intopsake:mainfrom
nthbotast:feat/test-scriptanalysis-issue-96

Conversation

@nthbotast
Copy link

@nthbotast nthbotast commented Mar 2, 2026

Summary

  • add a dedicated Pester test file for Test-PSBuildScriptAnalysis
  • verify Invoke-ScriptAnalyzer is called with the provided -SettingsPath
  • verify pass/fail behavior at -SeverityThreshold Error
  • fix severity counting by using $_.Severity in the analyzer result filters

Validation

  • Added targeted Pester scenarios requested in Tests: Test-PSBuildScriptAnalysis #96
  • Local execution not run in this environment because PowerShell (pwsh) is unavailable; CI should run the suite on PR

Closes #96

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ps1 with Pester scenarios asserting Invoke-ScriptAnalyzer is invoked with the provided -SettingsPath and that error-threshold behavior throws/doesn’t throw as expected.
  • Fix severity counting in Test-PSBuildScriptAnalysis by filtering on $_.Severity rather 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.

Comment on lines +21 to +26
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
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests: Test-PSBuildScriptAnalysis

2 participants