diff --git a/src/SDF_TEST.cc b/src/SDF_TEST.cc index 99d3d394f..933b3a1bf 100644 --- a/src/SDF_TEST.cc +++ b/src/SDF_TEST.cc @@ -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); @@ -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 } /////////////////////////////////////////////////