Why does Google Test not print a stack trace or file name?
Asked Answered
D

1

5

When I use Google Test and Google Mock, with diagnostic level set to "info", I get messages like this:

Uninteresting mock function call - taking default action specified at:
src/pkgtest/test_Foo.cpp:216:
    Function call: GetBar()
          Returns: 4-byte object <00-00 00-00>
Stack trace:

Uninteresting mock function call - taking default action specified at:
src/pkgtest/test_Foo.cpp:126:
    Function call: GetBaz()
          Returns: {}
Stack trace:
unknown file: Failure
C++ exception with description "Uninteresting mock function call - returning default value.
    Function call: CreateGrille(@0x7fff6a557050 { 16-byte object <80-D8 BB-01 00-00 00-00 70-D8 BB-01 00-00 00-00> })
    The mock function has no default action set, and its return type has no default value set." thrown in the test body.

I cannot find anything on the internet about why Google Test/Mock won't print a stack trace, or claims "unknown file". What do I need to do to teach it how to properly dump a stack trace?

(I'm on Linux using g++ 4.9, if that makes a difference.)

Diondione answered 14/6, 2016 at 14:0 Comment(4)
Why not ask library vendor?Synn
Why do you think it should return a stack trace?Polly
@CaptainObvlious Because it says "Stack trace:" with nothing after it. It sort of seems to hint that there should be something there.Diondione
@Synn I will try that.Diondione
D
3

According to Samuel Benzaquen:

gTest doesn't include a stack unwinder. You have to provide your own. You can do this in include/gtest/internal/custom/gtest.h by defining the GTEST_OS_STACK_TRACE_GETTER_ macro to point an implementation of OsStackTraceGetterInterface.

https://groups.google.com/d/msg/googletestframework/WMJuxAE7y-A/3FjexkRpEQAJ

Diondione answered 14/6, 2016 at 15:45 Comment(3)
Any examples of this in use?Easiness
It seems this behavior may now be configured by default. If GTEST_OS_STACK_TRACE_GETTER_ isn't set it defaults to OsStackTraceGetter, which claims to be "a working implementation of the OsStackTraceGetterInterface interface". I wonder if this macro isn't supposed to be used; it's only mentioned in "internal" docs.Instant
But, if it helps, Chromium sets this macro to a custom class, so perhaps OsStackTraceGetter isn't actually sufficient.Instant

© 2022 - 2024 — McMap. All rights reserved.