Custom formatting of std::string
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
I have some tests that use `std::string`s with various non-ascii chars.
If one of the tests fail, it would be very convenient to output the string contents in eg. hex format instead of letting catch print the output as a normal `std::string`.
For good reasons it is not possible to specialize the `<<` operator for strings and it doesn't seem to be possible to override the default `StringMaker` implementation - at least not for a specific test case/executable.
Of course there are ways around this, but all I can think of is not very elegant and I really like the simplicity and elegance of catch2 so I'm wondering if there's some way of handling that case?
If not, I was wondering if it was something that could be implemented somehow? I could imagine there could be other cases where a user would like to have a "standard type" formatted differently?
Thanks a lot and thanks a lot for this great framework!
Contributor guide
Research direction
Start by reading Catch2's StringMaker implementation and the existing customization behavior for std::string. Investigate how formatting can be scoped to a specific test or executable, then define a focused API and tests covering non-ASCII strings and hexadecimal output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100