google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.96k stars 10.17k forks source link

[FR]: Add gtest-spi.h interface for retrieving SCOPED_TRACE() traces #4589

Open caraitto opened 3 months ago

caraitto commented 3 months ago

Does the feature exist in the most recent commit?

Nope: https://github.com/google/googletest/blob/ff233bdd4cac0a0bf6e5cd45bda3406814cb2796/googletest/include/gtest/gtest-spi.h#L1

Why do we need this feature?

gtest-spi.h allows checking for non-fatal failures with EXPECT_NONFATAL_FAILURE() and matching the failure message.

Today, it is even possible to match against SCOPE_TRACE() traces, but it's a bit awkward, since the trace usually looks like this:

Google Test trace:
../../path/to/file.cc:104: 0
../../path/to/file.cc:95: some text
...

Since line numbers are included in the trace (which is useful when debugging tests), if the EXPECT_NONFATAL_FAILURE() substr includes the trace, it will have to include the filenames and line numbers too, but these can change over time. It would be nice to somehow just match against the values without the file names and line numbers (this would be possible if substr could be regular expression, or if it was possible to programmatically retrieve the trace values).

Describe the proposal.

Either

1) Add a variant macro that accepts a regular expression instead of a pure string match, or

2) Add a method (something like https://en.cppreference.com/w/cpp/utility/tuple/get perhaps) that allows retrieving elements of the scoped trace.

Is the feature specific to an operating system, compiler, or build system version?

No