Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SCOPED_TRACE output for stack trace message #30

Closed
Eistroll opened this issue Feb 26, 2016 · 5 comments
Closed

Handle SCOPED_TRACE output for stack trace message #30

Eistroll opened this issue Feb 26, 2016 · 5 comments
Assignees

Comments

@Eistroll
Copy link

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 ) );
}
}

@csoltenborn
Copy link
Owner

@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 csoltenborn self-assigned this Feb 29, 2016
@csoltenborn
Copy link
Owner

@Eistroll In case you have time for trying out the new functionality, please use this version.

@Eistroll
Copy link
Author

Eistroll commented Mar 8, 2016

@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

@Eistroll Eistroll closed this as completed Mar 8, 2016
@Eistroll
Copy link
Author

Eistroll commented Mar 8, 2016

Sorry, I closed this by accident

@Eistroll Eistroll reopened this Mar 8, 2016
@csoltenborn
Copy link
Owner

@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.

csoltenborn pushed a commit that referenced this issue Oct 21, 2017
Avoid Unicode path to project to satisfy the build system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants