How to exclude printf messages from Catch reporter

275 Views Asked by At

I am testing a library that monitors USB stick and allows listening to plugin/plugout events. The target system runs a custom Linux version and debugging is a pain on this system

So, for quick analysis of what is going, I very often use printf messages.

For unit testing of the library, I have started using Catch and I generate test reports using JUint reporter.

Problem: If I insert aprintf message for analysis, it gets added to the xml report generated by Catch.

My question: Is there a way to separate printf messages and the report generated by Catch?

Thanks.

UPDATE: I want to avoid writing to a file, because I've had problems with it when there are errors and the program crashes before the file is completely written to.

3

There are 3 best solutions below

3
On BEST ANSWER

There is an another way.

You could print your debug messages to stderr instead of stdout using fprintf like this:

fprintf(stderr, "%d\n", c);

Since Catch's report is written to stdout you can then dismiss your output using redirection, e.g. on Linux systems:

./a.out -r junit 2> /dev/null
1
On

Not really familiar with Catch, but an obvious solution is to print to a non-standard location. So, e.g., fopen a log file and fprintf there instead of to standard output.

Also, quite unrelated to your question, but may help you with your problem, you can use gdbserver to debug on the platform. Just search for "gdbserver remote debugging" for instructions on how to do that.

Edited to add: If you're worried that the file will get truncated in case of a crash, just replace "printf" with a wrapper that also does fflush.

0
On

If you are ok with writing the output to file, there is an easy solution. Use the -o option to change where Catch places its output.

You can either use it as -o report.xml to have the output be placed in a file called report.xml, or you can use a special file called %debug. When passed %debug as the output file, Catch attempts to write to whatever debugging facility it knows for given platform, which is stderr for Android.