Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gtest should support output stream redirect #1930

Open
ftrofin opened this issue Oct 24, 2018 · 9 comments
Open

gtest should support output stream redirect #1930

ftrofin opened this issue Oct 24, 2018 · 9 comments
Assignees

Comments

@ftrofin
Copy link

ftrofin commented Oct 24, 2018

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.

@gennadiycivil
Copy link
Contributor

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.

@ftrofin
Copy link
Author

ftrofin commented Oct 24, 2018

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.

@gennadiycivil
Copy link
Contributor

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

@gennadiycivil
Copy link
Contributor

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

@DannyVlasenko
Copy link

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?

@ftrofin
Copy link
Author

ftrofin commented Oct 11, 2019

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

@gennadiycivil gennadiycivil reopened this Oct 11, 2019
@milladgit
Copy link

milladgit commented Jan 22, 2020

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?

@asoffer asoffer self-assigned this Sep 15, 2020
@CraigHutchinson
Copy link

Any progress on this? I am running on Android and don't see any output from my application so I currently expect this is my issue as from what I understand printf() goes to dev/nul

@gaspardpetit
Copy link
Contributor

@CraigHutchinson for Android, I have this PR that's been waiting for almost a year: #3864

For the printf case, I attempted a macro solution in 2018 which was closed because macros are evil: #1201 and I tried again with a gtest_printf solution last year but again, no interest to merge since: #3860

LittleFox94 added a commit to LittleFox94/googletest that referenced this issue Oct 29, 2023
Allowing custom gtest_main implementations to instantiate the
XmlUnitTestResultPrinter with either a given file path or any other kind
of std::ostream to write to.

This is useful for e.g. embedded cases where an XML report is still
wanted, but not file system is available, by instantiating with a
std::stringstream and delivering the data via any custom mean.

Related to google#1930
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants