Optimize formatting for template strings and numbers#2866
Conversation
| # Limit recursion to simple arrays and hashtable to avoid hangs and complex test names/paths. | ||
| Format-Nicely2 -Value $Value -MaxDepth 1 |
There was a problem hiding this comment.
This will still print a massive multi-line name for something like (Get-Command Invoke-Pester), but at least it doesn't hang. Questions:
- Should we special case
CommandInfoto just return the name like v5? Or let it be so the author will identify a bad practice (not referencing the name property) and fix it. - Should tests names expand arrays/dictionaries etc in general?
- Should tests names allow multi-line at all? Messy console output. Trim or run through
[Pester.Formatter]::EscapeControlChars()?
8e5120e to
b224e8e
Compare
|
|
||
| function Is-DecimalNumber ($Value) { | ||
| $Value -is [float] -or $Value -is [single] -or $Value -is [double] -or $Value -is [decimal] | ||
| $Value -is [Single] -or $Value -is [Double] -or $Value -is [Decimal] |
There was a problem hiding this comment.
Just cosmetic to get consistent naming in code and tests <Type.Name> for both PS 5.1 and 7+
b224e8e to
a510080
Compare
Building on the -MaxDepth budget in this branch, format registered "noisy" types as a short, representative summary instead of walking their whole property tree. A CommandInfo referenced whole in a test name (for example <cmd> instead of <cmd.Name>) otherwise expands into an enormous, deeply nested dump that is so slow to build it looks like Pester has hung (pester#2865). Extend Get-DisplayProperty2 to match by base type (so a single entry covers every subtype, e.g. CommandInfo covers FunctionInfo, CmdletInfo, AliasInfo, ExternalScriptInfo) and register CommandInfo -> Name. Format-Nicely2 now consults the registry before expanding an object, so a registered type renders a compact summary such as FunctionInfo{Name='Invoke-Pester'} in both detailed assertion messages and shallow test-name templates. Any other complex object referenced whole in a name collapses to just its type, so an unknown object can never explode a test name. To tame a new noisy type, add one line to the registry. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Hey @fflaten 👋 I pushed a commit onto this branch to iterate on it — hope that's ok, happy to revert if you'd rather take it a different way. Your The commit finishes the type-map idea that was already sketched in the Anything not in the registry keeps today's behaviour (full expansion in assertion messages), and in a name it just collapses to Added tests for the base-type match, the compact summary, and an RSpec acceptance test for the #2865 repro. Clean build is green; only the unrelated pre-existing |
PR Summary
Restricts template strings to one level of object recursion in formatting to avoid hangs on large complex objects.
To address the issue above, this PR also:
-MaxDepthinstead of increasing-Depthwith hard limit. Easier to restrict something a max 1 level than start at depth 9.Format-Numbers*for integers and not just decimals. Integers was formatted as ValueType, requring-MaxDepth 2for formatting simple arrays.[char]vs[string]etc, but not fixed for now.Fix #2865
PR Checklist
Create Pull Requestto mark it as a draft. PR can be markedReady for reviewwhen it's ready.