INFO messages to output?

14,489 views
Skip to first unread message

Michael Ellery

unread,
Apr 28, 2014, 3:26:56 PM4/28/14
to googletes...@googlegroups.com
I'm looking for way to add an informational message to the output from the test framework - to annotate the output, essentially.  Some frameworks have implemented this kind of functionality as a NOTE() or INFO() macro. Does gtest have anything that fits this purpose?  Advice appreciated.

-Mike Ellery

Keith Ray

unread,
Apr 28, 2014, 4:00:27 PM4/28/14
to Michael Ellery, googletes...@googlegroups.com
ASSERT_*(...) << "Additional text".

Most of assertions can print extra text when they fail. Check the header files.

C. Keith Ray
twitter: @ckeithray


On Apr 28, 2014, at 2:26 PM, Michael Ellery <melle...@gmail.com> wrote:

I'm looking for way to add an informational message to the output from the test framework - to annotate the output, essentially.  Some frameworks have implemented this kind of functionality as a NOTE() or INFO() macro. Does gtest have anything that fits this purpose?  Advice appreciated.

-Mike Ellery

--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Ellery

unread,
Apr 28, 2014, 4:09:49 PM4/28/14
to googletes...@googlegroups.com, Michael Ellery

Yes, the message support in assertions is quite handy, but I'm looking for a way to *always* print some diagnostic output, regardless of assertion failure.

Thanks,
Mike

John D

unread,
Apr 28, 2014, 4:19:43 PM4/28/14
to googletes...@googlegroups.com
Does ASSERT(false) count?


BarbaraJoy Jones

unread,
Apr 28, 2014, 4:39:43 PM4/28/14
to John D, Google C++ Testing Framework
That would introduce an artificial failure in every test that used it, which makes it a lot harder to read the test output or use automatic test tools.

It's mostly for the test output to a file (using the same format as stdout).
It also prints any messages streamed to the SUCCEED macro to both that file and stdout.

Samuel Benzaquen

unread,
Apr 28, 2014, 4:44:13 PM4/28/14
to Michael Ellery, googletes...@googlegroups.com
On Mon, Apr 28, 2014 at 4:09 PM, Michael Ellery <melle...@gmail.com> wrote:

Yes, the message support in assertions is quite handy, but I'm looking for a way to *always* print some diagnostic output, regardless of assertion failure.


Thanks,
Mike


On Monday, April 28, 2014 1:00:27 PM UTC-7, keith.ray wrote:
ASSERT_*(...) << "Additional text".

Most of assertions can print extra text when they fail. Check the header files.

C. Keith Ray
twitter: @ckeithray


--

---
You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--


Michael Ellery

unread,
Apr 28, 2014, 4:50:42 PM4/28/14
to googletes...@googlegroups.com, John D



Barbara,

Thanks for that advice - it looks like a custom listener might do the trick for me, although I will need to disable/enable the "always print" aspect of the listener depending on the context of the test (which seems doable)

-Mike

BarbaraJoy Jones

unread,
Apr 28, 2014, 5:04:08 PM4/28/14
to Michael Ellery, Google C++ Testing Framework, John D
I have a command-line option to control whether the listener writes to the file, but it always prints the SUCCEED messages because that's rather important for the way we use that macro in our test code.
It sounds like it would be simpler if you put the enable/disable logic within your tests.

The relevant code from my listener is extremely simple:

void FilePrinter::OnTestPartResult(const TestPartResult& result)
{
    std::string part = FormatTestPartResult(result);
    // calls to SUCCEED() should also go to stdout
    if(result.type() == TestPartResult::kSuccess)
        printf("%s\n", part.c_str());

    logger.writeToFile(part);
}

The FormatTestPartResult method just returns a string containing the same information as the default test output with some extra line breaks and a timestamp. I think that I copied most of it from the gtest code for printing test results.


Reply all
Reply to author
Forward
0 new messages