Skip to content

Commit 625bc4d

Browse files
committed
Refactor code to avoid GTest GetCapturedStderr
it's the same approach as in parser_TEST.cc
1 parent 11975da commit 625bc4d

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/SDF_TEST.cc

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ TEST(SDF, Version)
542542
TEST(SDF, EmbeddedSpec)
543543
{
544544
std::string result;
545-
std::string output;
546545

547546
result = sdf::SDF::EmbeddedSpec("actor.sdf", false);
548547
EXPECT_NE(result.find("<!-- Actor -->"), std::string::npos);
@@ -562,21 +561,32 @@ TEST(SDF, EmbeddedSpec)
562561
TEST(SDF, EmbeddedSpecNonExistent)
563562
{
564563
std::string result;
565-
std::string output;
566564

567-
testing::internal::CaptureStderr();
565+
// Capture sdferr output
566+
std::stringstream stderr_buffer;
567+
auto old = std::cerr.rdbuf(stderr_buffer.rdbuf());
568+
569+
#ifdef _WIN32
570+
sdf::Console::Instance()->SetQuiet(false);
571+
#endif
572+
568573
result = sdf::SDF::EmbeddedSpec("unavailable.sdf", false);
569-
output = testing::internal::GetCapturedStderr();
570-
EXPECT_NE(output.find("Unable to find SDF filename"), std::string::npos);
571-
EXPECT_NE(output.find("with version"), std::string::npos);
574+
EXPECT_NE(stderr_buffer.str().find("Unable to find SDF filename"), std::string::npos);
575+
EXPECT_NE(stderr_buffer.str().find("with version"), std::string::npos);
572576
EXPECT_TRUE(result.empty());
573577

574-
output = "";
575-
testing::internal::CaptureStderr();
578+
// clear the contents of the buffer
579+
stderr_buffer.str("");
580+
576581
result = sdf::SDF::EmbeddedSpec("unavailable.sdf", true);
577-
output = testing::internal::GetCapturedStderr();
578-
EXPECT_TRUE(output.empty());
582+
EXPECT_TRUE(stderr_buffer.str().empty());
579583
EXPECT_TRUE(result.empty());
584+
585+
// Revert cerr rdbuf to not interfere with other tests
586+
std::cerr.rdbuf(old);
587+
#ifdef _WIN32
588+
sdf::Console::Instance()->SetQuiet(true);
589+
#endif
580590
}
581591

582592
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)