Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Format single item arrays as an array

Open fflaten opened this issue 2 years ago • 9 comments

PR Summary

Single item arrays are currently printed as single item without type-specific formatting because Is-Value expands them. Arrays with a single string or bool (more types?) will not be properly formatted.

# Current
> Format-Nicely @('a')
a

# After
> Format-Nicely @('a')                
@('a')

Related #2329

PR Checklist

  • [x] PR has meaningful title
  • [x] Summary describes changes
  • [ ] PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • [x] Tests are added/update (if required)
  • [ ] Documentation is updated/added (if required)

fflaten avatar Mar 28 '23 19:03 fflaten

Submitting as a draft because I'm not sure if this might format items in an unexpected array somewhere because Pester wraps input internally. ~The broken test is fixed by #2329~

Alternative: Do extra checks inside if(Is-Value ...) { } to call Format-Bool, Format-String etc.

Thoughts @nohwnd ?

fflaten avatar Mar 28 '23 19:03 fflaten

I will have a look will need to touch the formatting code for assert as well.

nohwnd avatar Apr 12 '24 19:04 nohwnd