Googletest: gtest should support output stream redirect

Created on 24 Oct 2018  路  7Comments  路  Source: google/googletest

The default reporter (PrettyUnitTestResultPrinter) writes straight to stdout via printf calls. I would like to have an API so I can provide my own std::ostream, like boost Test library: https://www.boost.org/doc/libs/1_68_0/libs/test/doc/html/boost_test/test_output/logging_api/log_ct_output_stream_redirection.html

This is useful when you use gtest as part of a bigger framework and you need to redirect to output somewhere else (or convert it on the fly to a different encoding for example).

If for running the tests I can at least work around the problem by writing an event listener and writing into my own stream, for listing the tests, there is no workaround since ListTestsMatchingFilter is not accessible and the listeners are not invoked for the list tests action.

Most helpful comment

Lack of participation signals lack of interest from the community. Closing

How many people from the community should vote for this issue to make you reopen it?

All 7 comments

Thank you very much for this report. The best way to approach this would be to create a proper PR and submit it for consideration.

Before we even talk about a PR let's have a conversation about how this should be approached. There are many ways in which this can be done but all of them imply lots of changes to the existing code. Here are two that come immediately to mind.

  1. Replace all printf calls with std::cout << ... The advantage of doing this is that it's very easy to redirect cout (much easier than stdout).
  2. Pass in the output stream as a parameter to RunAllTests(). Redirect all output to it.

I'm guessing I'm not the first one thinking about this and there might be already significant effort invested in the design of this feature. Let's discuss and agree on the best approach before spending lots of time to modify the code.

I dont see anyone from the community chiming in here. At the same time this has not been a requirement internally.

Lack of participation signals lack of interest from the community. Closing

Lack of participation signals lack of interest from the community. Closing

How many people from the community should vote for this issue to make you reopen it?

So which approach should we take for this? See the two options I layed out above (or it can be a new one...)

This would be a great feature in the embedded world! In many cases, we need to redirect the textual output to a variable and then return that content back to our desktop system in the near future. I second this.

Any workaround at this point?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markfrazzetto picture markfrazzetto  路  3Comments

pepe82sh picture pepe82sh  路  5Comments

marknelson picture marknelson  路  4Comments

Joebeazelman picture Joebeazelman  路  5Comments

AstralStorm picture AstralStorm  路  4Comments