Handle SCOPED_TRACE output for stack trace message
Eistroll opened this issue · comments
If we use SCOPED_TRACE we have an additional line for the scope in the error message.
It would be great if this could be integrated into the StackTrace formatting.
I added some senseless examples just to have some examples:
void checkValues( std::vector const& expectedValues, std::vector const& resultValues )
{
ASSERT_EQ( expectedValues.size(), resultValues.size() );
for ( size_t i=0; i<expectedValues.size(); ++i )
{
SCOPED_TRACE( "Checking index " + std::to_string( i ) );
EXPECT_EQ( expectedValues.at(i), resultValues.at(i) );
}// for
}
TEST( TestMath, ScopedFailures )
{
std::vector expected;
expected.push_back( 1 );
expected.push_back( 2 );
expected.push_back( 3 );
expected.push_back( 4 );
expected.push_back( 5 );
std::vector results;
results.push_back( 1 );
results.push_back( 1 );
results.push_back( 3 );
results.push_back( 3 );
results.push_back( 3 );
checkValues( expected, results );
}
TEST( TestMath, ScopedFailures2 )
{
std::vector expected;
expected.push_back( 1 );
expected.push_back( 2 );
expected.push_back( 3 );
expected.push_back( 4 );
expected.push_back( 5 );
std::vector results;
results.push_back( 1 );
results.push_back( 1 );
results.push_back( 3 );
results.push_back( 3 );
results.push_back( 3 );
std::vector results2;
results2.push_back( 1 );
results2.push_back( 2 );
results2.push_back( 3 );
results2.push_back( 5 );
results2.push_back( 6 );
{
SCOPED_TRACE( "Check first results");
checkValues( expected, results );
}
{
SCOPED_TRACE( "Check second results");
checkValues( expected, results2 );
}
}
::testing::AssertionResult CheckVectors( std::vector const& expectedValues, std::vector const& resultValues )
{
::testing::AssertionResult result = ::testing::AssertionFailure();
bool failure = false;
if ( expectedValues.size() != resultValues.size() ) {
failure = true;
result << "Vector size does not match: " << std::to_string( expectedValues.size() ) << " != " << std::to_string( resultValues.size() );
}
else {
size_t index = 0;
for ( size_t index = 0; index < resultValues.size(); ++index ) {
if( expectedValues.at( index ) != resultValues.at( index ) ){
failure = true;
result << "Index " << std::to_string(index) << ": expected(" << std::to_string( expectedValues.at( index ) ) << ") != given(" << std::to_string( resultValues.at( index ) ) << ")\n";
}
}
}
if ( failure )
return result;
else
return ::testing::AssertionSuccess();
}
TEST( TestMath, ScopedFailure3 )
{
std::vector expected;
expected.push_back( 1 );
expected.push_back( 2 );
expected.push_back( 3 );
expected.push_back( 4 );
expected.push_back( 5 );
std::vector results;
results.push_back( 1 );
results.push_back( 1 );
results.push_back( 3 );
std::vector results2;
results2.push_back( 1 );
results2.push_back( 2 );
results2.push_back( 3 );
results2.push_back( 5 );
results2.push_back( 6 );
{
SCOPED_TRACE( "Check first results" );
EXPECT_TRUE( CheckVectors( expected, results ) );
}
{
SCOPED_TRACE( "Check second results" );
EXPECT_TRUE( CheckVectors( expected, results2 ) );
}
}
@Eistroll Thanks for raising the issue and providing example code! However, I had already started looking into this, so I ended up using my own tests...
Would you mind to give this version another try? In particular, could you check your example tests and the ones of our SampleTest solution, especially the MessageParserTests
tests? Just in case: you need to check out this branch to access the latest version of the SampleTests solution... thanks in advance!
@csoltenborn I have tested your version with my tests and it works and really helps.
Of course it would be great to have the links next to the message but since the test explorer has the stacktrace at the end it is as it is :-)
One thing might be helpful since I get very long messages, when using EXPECT_CALL ... would be to have the line number next to the #?. Otherwise I always have to scroll down to get to the stacktrace entry. So I see directly where I have to go, when I am at the code area already
#1 (343) Message..sfdasdf.fsdfasdfsdfsdfasfddsf
Sorry, I closed this by accident
@Eistroll Great, thanks for your feedback! Sorry if I'm annoying, but please open a new issue for that line number request - we'd like to release what we have in the next days, so I'm closing this issue now.