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 26, 2022
1 parent a421ed3 commit e8f56ba
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/SDF_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include <gz/utils/Environment.hh>
#include <gz/utils/SuppressWarning.hh>

#include "test_config.hh"
#include "test_utils.hh"

#include "sdf/sdf.hh"

class SDFUpdateFixture
Expand Down Expand Up @@ -587,10 +590,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 @@ -605,12 +613,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 e8f56ba

Please sign in to comment.