comipayan / googletest

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

Extended SCOPED_TRACE #207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
SCOPED_TRACE currently only supports a single argument, which is streamed
into an assertion message.

It should be extended to support additional streams; ie. one of either this:

SCOPED_TRACE("foo = " << foo);

Or this:

SCOPED_TRACE("foo = ") << foo;

Ought to work, and be equivalent to this:

std::ostringstream str;
str << "foo = " << foo;
SCOPED_TRACE(str.str());

Related to this, there should be a way to capture and override the line
trace added by SCOPED_TRACE; eg:

void foo(::testing::SomeType trace, xxxxx)
{
  SCOPED_TRACE_AT(trace, "foo");
  .... (EXPECT_*)
}
...
  foo(TRACE_HERE(), xxxx);

Where the file/line trace info is captured on use of TRACE_HERE() and added
to the trace info in the SCOPED_TRACE_AT (so that failures while that is in
scope will report both).

Without this, tests using nested functions with assertions can get quite
ugly to disambiguate.

Original issue reported on code.google.com by uec...@gmail.com on 14 Oct 2009 at 5:36

GoogleCodeExporter commented 9 years ago
@mirality, to stream more than one thing to SCOPED_TRACE, write:

  SCOPED_TRACE(Message() << "foo = " << foo);

I'm not sure SCOPED_TRACE_AT and TRACE_HERE are worth the complexity.  You can 
write:

  void foo(xxxxx) {
    SCOPED_TRACE("foo");
    ...
  }
  ...
    SCOPED_TRACE("bar");
    foo(xxxxx);

Original comment by zhanyong...@gmail.com on 15 Oct 2009 at 5:27

GoogleCodeExporter commented 9 years ago
I think what Miral really needs is a meaningful stack trace with each failure. 
Unfortunately, we don't have it it although we are tracking an issue 99 to 
provide a 
hook for clients to attach one.

Original comment by vladlosev on 20 Oct 2009 at 10:43

GoogleCodeExporter commented 9 years ago

Original comment by vladlosev on 21 Oct 2009 at 6:44

GoogleCodeExporter commented 9 years ago
Automatic stack trace would be nice.  I added such a feature to CppUnit at one 
point, 
although it was Windows- and MSVC-specific.

Original comment by uec...@gmail.com on 21 Oct 2009 at 7:06