Skip to content

Remove unused internal functions#2907

Draft
nohwnd wants to merge 2 commits into
pester:mainfrom
nohwnd:remove-unused-internal-functions
Draft

Remove unused internal functions#2907
nohwnd wants to merge 2 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>
@@ -1,4 +1,4 @@
function Count-Scopes {
function Count-Scopes {
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
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.

2 participants