Skip to content

Commit

Permalink
Use testing::RedirectConsoleStream to capture errors
Browse files Browse the repository at this point in the history
Signed-off-by: Bi0T1N <[email protected]>
  • Loading branch information
Bi0T1N committed Aug 20, 2022
1 parent 218c54a commit 939219a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/SDF_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,15 @@ TEST(SDF, EmbeddedSpecNonExistent)

// Capture sdferr output
std::stringstream stderr_buffer;
auto old = std::cerr.rdbuf(stderr_buffer.rdbuf());

sdf::testing::RedirectConsoleStream redir(
sdf::Console::Instance()->GetMsgStream(), &stderr_buffer);
#ifdef _WIN32
sdf::Console::Instance()->SetQuiet(false);
sdf::testing::ScopeExit revertSetQuiet(
[]
{
sdf::Console::Instance()->SetQuiet(true);
});
#endif

result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false);
Expand All @@ -584,12 +589,6 @@ TEST(SDF, EmbeddedSpecNonExistent)
result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true);
EXPECT_TRUE(stderr_buffer.str().empty());
EXPECT_TRUE(result.empty());

// Revert cerr rdbuf to not interfere with other tests
std::cerr.rdbuf(old);
#ifdef _WIN32
sdf::Console::Instance()->SetQuiet(true);
#endif
}

/////////////////////////////////////////////////
Expand Down

0 comments on commit 939219a

Please sign in to comment.