catchorg / catchorg/Catch2

Ability to prefix output of Catch

Open
#1,727 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**Description**
I'm working in a context in which multiple systems log during the process of running catch. As a result, I tend to see output like the following:
```
something can be done
Given: A thing with some items
my system logs
system 1 logs
system 2 logs
more system 1 logs
etc.
When: something is done to the thing
even
more
logging
Then: it is done properly
```
These logs happen sometimes dozens or even hundreds of time between each step of catch, and this occurs for hundreds of tests.

What I would like is the ability to set a prefix of some sort before each line of the catch output so I can get a visual hint in the logging where the catch output is as opposed to other logs, as well as to be able to run a regex to search for or transform it.

As far as I can tell, there is no way to do this properly without modifying the source in every place text is sent to stdout.

**Additional context**
- A good deal of the time, I'm working in Xcode, so trying alternate output forms is not really an option: I'm chained to stdout. And what's more, I *want* the interleaved logging, as it assists in triage.
- My first thought was the obvious one, to strip out the additional logging besides catch, but even with a lot of time spent working through complex regular expressions, it's never quite right: I'm not in control of the other systems that log, nor their style of logging, so capturing the exact form is impossible.
- I tried using `Catch::cout` trickily to insert a prefix before returning `std::cout`, but that didn't work properly, because catch calls `Catch::cout()` periodically to call `rdbuf()` on it, which causes duplicate prefixes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.