-
Notifications
You must be signed in to change notification settings - Fork 102
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
Comments
@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 |
@csoltenborn I have tested your version with my tests and it works and really helps. |
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. |
Avoid Unicode path to project to satisfy the build system
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 ) );
}
}
The text was updated successfully, but these errors were encountered: