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

cout only if -v option is given? #1752

Open
ThePapaG opened this issue Apr 13, 2023 · 2 comments
Open

cout only if -v option is given? #1752

ThePapaG opened this issue Apr 13, 2023 · 2 comments

Comments

@ThePapaG
Copy link

Hi!

I want to have debug printing in my tests so when something fails, there is more context. I would like this to only occur if the -v option has been given when executing. Is there a way to access this executable option so I can implement my own cout that will first check that option?

Thanks.

@basvodde
Copy link
Member

Yes, it is possible, but it isn't super easy at the moment. The reason is that the TestOutput has no getter for the verbose flag (tell, don't ask principle) and there is no direct access to the command line arguments after they have been parsed (as far as I know).

However, it is possible by making your own ConsoleTestOuput and your own TestRunner. The TestRunner createConsoleOutput will create the output (which you can replace with your own) and then the output::verbose is called to set the output to verbose mode.

@basvodde
Copy link
Member

Alternatively, you can use the output->printVeryVerbose instead of the cout. That way the print will be enabled when you pass the -vv option.

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

2 participants