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 7395479
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 @@ -20,6 +20,9 @@
#include <gz/math.hh>
#include <gz/utils/Environment.hh>

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

#include "sdf/sdf.hh"

class SDFUpdateFixture
Expand Down Expand Up @@ -566,10 +569,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 +592,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 7395479

Please sign in to comment.