mcspring / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

improve SCOPED_TRACE to allow stream operators #349

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
it would be nice to be able to write this sort of statements:
SCOPED_TRACE("My object is << MyObject << " and using streams is fun");

it is possible by slightly changing how SCOPED_TRACE is defined, like so:

#define SCOPED_TRACE(message) \
  ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
    __FILE__, __LINE__, ::testing::Message() << message)

Original issue reported on code.google.com by avia...@gmail.com on 29 Dec 2010 at 7:19

GoogleCodeExporter commented 9 years ago
Please use the mailing list instead of the issue tracker for feature requests.  
Thanks.

The proposed syntax is confusing as the macro argument

  "My object is " << MyObject << " and ..."

looks like a C++ expression but actually doesn't parse as one.

You could instead write:

  SCOPED_TRACE(testing::Message() << "My object is " << MyObject << " and ...");

which works already.

We could add support for

  SCOPED_TRACE() << "My object is " << MyObject << " and ...";

though.

Original comment by w...@google.com on 4 Jan 2011 at 8:43