Skip to content

Remove unused internal functions#2907

Merged
nohwnd merged 4 commits into
pester:mainfrom
nohwnd:remove-unused-internal-functions
Jul 18, 2026
Merged

Remove unused internal functions#2907
nohwnd merged 4 commits into
pester:mainfrom
nohwnd:remove-unused-internal-functions

Conversation

@nohwnd

@nohwnd nohwnd commented Jul 18, 2026

Copy link
Copy Markdown
Member

Draft, and stacked on #2906. It branches off that PR, so until #2906 merges the diff here shows both changes, review this one after that lands and it rebases clean.

While generating a full coverage report I noticed a chunk of the missed lines are not gaps, they are internal functions that nothing calls anymore. This removes 51 of them. Each one has no callers in src or tst (checked case insensitively, ignoring comments and its own definition), and none are exported.

By group:

  • Old v4 assertion messages. The orphaned Should<Name>FailureMessage / NotShould<Name>FailureMessage pairs for BeGreaterThan, BeIn, BeLessThan, BeLike, BeLikeExactly, BeOfType, BeTrueOrFalse, Contain and HaveCount, plus Get-FailureMessage. The operators build the message inline now. Be, Match and FileContentMatch still call theirs so they stay. Exist and Throw also stay, because Should.Tests.ps1 asserts their message functions exist (it builds the names as strings, so a plain grep does not see that use).
  • Unfinished pretty printer in Format.ps1. Format-Object, Format-Hashtable, Format-Dictionary, Get-DisplayProperty. Format-Nicely returns the value as a string and the advanced path is commented out.
  • Orphaned helpers across Mock, RSpec, Runtime, Coverage, Debugging and Utility: Run-Test, Merge-CommandCoverage, Show-ParentList, Add-MockBehavior, FindMock, LastThat, Test-IsClosure, Reset-ConflictingParameters, New-BlockWithoutParameterAliases, New-OneTimeBlockSetup, Set-CurrentBlock, Reset-TestSuiteTimer, New-DiscoveredBlockContainerObject, Get-SessionStateHint, Assert-RunInProgress, and the Pester.Utility dictionary helpers.

Verification

Full test.ps1 run passes (P tests and Pester tests, 2606 passed, 0 failed). Every touched file parses.

Notes for review

  • I removed by AST extent, so the diff is whole functions only.
  • Sort-Property in Format.ps1 is now only reachable from the removed Get-DisplayProperty, so it is dead too, I left it in this pass, easy to drop as a follow up.
  • A couple of things surfaced that are worth a look but out of scope here: PostProcess-RspecTestRun and Remove-RSpecNonPublicProperties are defined with lowercase Rspec but called with RSpec/RSPec, they only work because PowerShell is case insensitive. ConvertTo-PesterResult has no production caller, it is kept because a test uses it as the canary for "internals do not leak to the SUT".

test.ps1 -CC traces the parent process, but the Output and InNewProcess tests
run Pester in a child process through Invoke-InNewProcess and assert on its
output. So the failure rendering, CI format output and discovery messages are
covered by tests, the tracer just never sees them and reports them as missed,
which makes the coverage number lie about what is actually tested.

When -CC is on the parent now points the children at a drop folder and the same
coverage target via PESTER_CC_CHILD_* env vars, which the child process
inherits. Each child traces itself the same way the parent does, dumps the
path + line:column it hit, and the parent merges those into the measure before
the report. Parent and child trace the same files, so a child hit maps onto the
same not yet hit point and we just flip it to Hit (the point is a struct, so
copy, set, write back, same as the tracer does on a live hit).

When -CC is off nothing changes, the child just runs . $ScriptBlock as before.

Output.ps1 goes from 74% to 80%, overall from 85.7% to 86.4%.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread src/functions/Pester.Debugging.ps1 Fixed
These internal functions have no callers left in src or tst (checked case
insensitively, ignoring comments and their own definition), and none are
exported. Grouped:

- Old v4 assertion messages: the orphaned Should<Name>FailureMessage and
  NotShould<Name>FailureMessage pairs for BeGreaterThan, BeIn, BeLessThan,
  BeLike, BeLikeExactly, BeOfType, BeTrueOrFalse, Contain and HaveCount, plus
  Get-FailureMessage. The operators build the message inline now. Be, Match and
  FileContentMatch still call theirs so they stay, and Exist and Throw stay
  because Should.Tests.ps1 asserts their message functions exist.
- Unfinished pretty printer in Format.ps1: Format-Object, Format-Hashtable,
  Format-Dictionary, Get-DisplayProperty. Format-Nicely returns the value as a
  string and the advanced path is commented out.
- Orphaned helpers across Mock, RSpec, Runtime, Coverage, Debugging and Utility
  (Run-Test, Merge-CommandCoverage, Show-ParentList, Add-MockBehavior, FindMock,
  LastThat, Test-IsClosure, Reset-ConflictingParameters,
  New-BlockWithoutParameterAliases, New-OneTimeBlockSetup, Set-CurrentBlock,
  Reset-TestSuiteTimer, New-DiscoveredBlockContainerObject, Get-SessionStateHint,
  Assert-RunInProgress, and the Pester.Utility dictionary helpers).

Full test.ps1 run passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nohwnd
nohwnd force-pushed the remove-unused-internal-functions branch from b5b92cd to a5680b7 Compare July 18, 2026 10:55
@fflaten

fflaten commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Quick reminder that we support [ExcludeFromCodeCoverage()] if we want to keep some of these while fixing CC.

New-OneTimeBlockSetup

Both OneTimeBlockSetup/-Teardown functions + public properties in Pester.Block are dead code AFAIK. EachBlockSetup and EachBlockTeardown are only called by runtime tests also. Any plans for them or should they've been removed in 6.0.0 (should be fine in 6.1.0 as well - very minor breaking change)

Count is not an approved verb and Scopes is plural, PSScriptAnalyzer flags it.
Internal debug helper, only caller is Write-ScriptBlockInvocationHint.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nohwnd

nohwnd commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

Yeah they're dead. The New-*Block* functions are only called from the runtime tests, so the four Pester.Block properties are never set in a real run and the two reads in Invoke-Test are no-ops. Removed all of it in #2908 (stacked on this), the functions, the properties and the reads. Kept the plugin block lifecycle steps (OneTimeBlockSetupStart etc.), those are live. All truly dead so I just deleted them instead of using [ExcludeFromCodeCoverage()].

Comment thread src/functions/Mock.ps1 Outdated
Comment thread src/Pester.Utility.ps1 Outdated
Co-authored-by: Jakub Jareš <me@jakubjares.com>
@nohwnd
nohwnd marked this pull request as ready for review July 18, 2026 20:36
@nohwnd
nohwnd merged commit 336aabd into pester:main Jul 18, 2026
1 of 3 checks passed
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.

3 participants