Repository navigation
test: run the suites under strict mode - #156
Conversation
ERR-03. 47 unit tests failed with strict mode on: mock bodies read arguments the call had not bound, tests read Mandatory and ValidValues across all of a parameter's attributes, two test names used <...> templates without data, and a few read a property of an empty result or a variable set on one branch only. Mocks read from PesterBoundParameters, two helpers in TestHelpers read the attributes, and Tests/Invoke-Tests.ps1 no longer turns strict mode off around the Pester run. Part of #70
fadwen-ai
left a comment
There was a problem hiding this comment.
Three nits, all in the new helpers in Tests/TestHelpers/TestHelpers.ps1. The rest of the change looks right: the $PesterBoundParameters reads in the mocks, the Get-Variable reads for -ForEach keys a case leaves out, the $script:StubCreated initialisation, and the Win32 empty-credential assertion, which matches Invoke-IslWin32ContentCommand passing -Credential only for another account.
Get-ParameterValidValuefails with a strict-mode error for a parameter the command lacks, which its help and its sibling helper don't lead you to expect.Test-ParameterMandatoryreturns$falsefor an unknown parameter, so aShould-BeFalseassertion passes vacuously after a rename.- STY-07: one blank line before
Test-ParameterMandatory, where the file uses two.
Out of scope: none
🤖 Generated with Claude Code
…elpers Test-ParameterMandatory returned false for an unknown name, so a test that a parameter is optional passed when it was renamed or removed, and Get-ParameterValidValue read Attributes from null under strict mode. Both now end with ParameterNotFound; the input-length test checks that a command has -Path before asking whether it is mandatory.
|
Round 1: 3 fixed, 0 not changed.
The ten files that use the helpers: 183 passed under strict mode on PowerShell 7.6 and 5.1; PSScriptAnalyzer clean. New head 🤖 Generated with Claude Code |
fadwen-ai
left a comment
There was a problem hiding this comment.
Round 2: all three round 1 findings are fixed in f0bc0f1, and I've resolved their threads. Both helpers now end with ParameterNotFound for a parameter the command doesn't have, and their help says so. The input-length test checks ContainsKey('Path') before it asks. The two blank lines are in.
I re-read the whole diff against main. Every caller of the two helpers names a parameter that exists, so the new error can't trip a test that was passing. Under Set-StrictMode -Version Latest the helpers return True for Get-Item -Path and raise ParameterNotFound,Test-ParameterMandatory for an unknown name. The ten files that use them pass on PowerShell 7.6 (183 passed, 0 failed). No new findings.
Out of scope: none
🤖 Generated with Claude Code
Summary
Part of #70 (ERR-03). The module runs under
Set-StrictMode -Version Latest; the suites did not, andTests/Invoke-Tests.ps1turned strict mode off around the Pester run for that reason. With it on, 47 unit tests failed on PowerShell 7.6, all in test code: none points at the module. The validation kit's own failures that #70 counted are gone since #125. This makes the suites pass under strict mode and removes the switch.Changes
$PesterBoundParameters, which gives$nullfor it; Pester makes no variable for an argument that was not bound (Invoke-IslWin32ContentCommand,Test-IslPolicyScript,Get-IslExportReport).Tests/TestHelpers/TestHelpers.ps1gainsTest-ParameterMandatoryandGet-ParameterValidValue, which read theParameterandValidateSetattributes of a parameter only. Ten files read.Attributes.Mandatoryand.Attributes.ValidValuesacross all of a parameter's attributes, and on a command without the parameter, which strict mode refuses; they use the helpers, and the four that did not loadTestHelpers.ps1now do.Repair-IntuneScript.Tests.ps1: the cases that give noArchitectureare read withGet-Variable -ValueOnly -ErrorAction SilentlyContinue, since a key a-ForEachcase leaves out is no variable.<Limit>and<value>without-ForEachdata, which Pester expands as variables; they name the values instead.Test-IntuneScript.Tests.ps1readsRuleNamefrom each finding rather than from a result that can be empty; the two Graph request suites set$script:StubCreatedon both branches; the Win32 test of a run as the current user asserts that no credential was passed.Tests/Invoke-Tests.ps1runs Pester under its own strict mode.CLAUDE.mdsays how a mock and a parameter test are written for it;CHANGELOG.mdhas a Changed entry.Verification
Set-StrictMode -Version Lateston PowerShell 7.6, not elevated: 2,312 passed, 0 failed, 8 skipped before the last three fixes, then those three files 21 of 21../Build/Invoke-Build.ps1with the runner's switch removed: 2,262 passed on PowerShell 7.6 and 2,226 passed (37 skipped) on Windows PowerShell 5.1, no failures; PSScriptAnalyzer clean in 355 files.Notes
PSVersion.Majorreads are the Windows test that VER-07's example uses.