2121namespace operations_research {
2222namespace {
2323
24- #ifdef OPERATIONS_RESEARCH_OUTPUT_CAPTURE_SUPPORTED
25-
2624TEST (ScopedStdStreamCaptureTest, CaptureStdout) {
2725 ScopedStdStreamCapture capture (CapturedStream::kStdout );
2826 std::cout << " something" ;
29- EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " something" );
27+ if (ScopedStdStreamCapture::kIsSupported ) {
28+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " something" );
29+ } else {
30+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " " );
31+ }
3032}
3133
3234TEST (ScopedStdStreamCaptureTest, CaptureStderr) {
3335 ScopedStdStreamCapture capture (CapturedStream::kStderr );
3436 std::cerr << " something" ;
35- EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " something" );
37+ if (ScopedStdStreamCapture::kIsSupported ) {
38+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " something" );
39+ } else {
40+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (), " " );
41+ }
3642}
3743
3844TEST (ScopedStdStreamCaptureTest, EarlyExitThenCaptureStdout) {
@@ -43,8 +49,10 @@ TEST(ScopedStdStreamCaptureTest, EarlyExitThenCaptureStdout) {
4349 {
4450 ScopedStdStreamCapture capture (CapturedStream::kStdout );
4551 std::cout << " another thing" ;
46- EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (),
47- " another thing" );
52+ if (ScopedStdStreamCapture::kIsSupported ) {
53+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (),
54+ " another thing" );
55+ }
4856 }
4957}
5058
@@ -56,8 +64,10 @@ TEST(ScopedStdStreamCaptureTest, EarlyExitThenCaptureStderr) {
5664 {
5765 ScopedStdStreamCapture capture (CapturedStream::kStderr );
5866 std::cerr << " another thing" ;
59- EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (),
60- " another thing" );
67+ if (ScopedStdStreamCapture::kIsSupported ) {
68+ EXPECT_EQ (std::move (capture).StopCaptureAndReturnContents (),
69+ " another thing" );
70+ }
6171 }
6272}
6373
@@ -68,8 +78,12 @@ TEST(ScopedStdStreamCaptureTest, CaptureStdoutAndStderr) {
6878 std::cout << " stdout" ;
6979 std::cerr << " stderr" ;
7080
71- EXPECT_EQ (std::move (stdout_capture).StopCaptureAndReturnContents (), " stdout" );
72- EXPECT_EQ (std::move (stderr_capture).StopCaptureAndReturnContents (), " stderr" );
81+ if (ScopedStdStreamCapture::kIsSupported ) {
82+ EXPECT_EQ (std::move (stdout_capture).StopCaptureAndReturnContents (),
83+ " stdout" );
84+ EXPECT_EQ (std::move (stderr_capture).StopCaptureAndReturnContents (),
85+ " stderr" );
86+ }
7387}
7488
7589TEST (ScopedStdStreamCaptureDeathTest, TwoCalls) {
@@ -89,14 +103,5 @@ TEST(ScopedStdStreamCaptureDeathTest, TwoCalls) {
89103 " twice" );
90104}
91105
92- #else // OPERATIONS_RESEARCH_OUTPUT_CAPTURE_SUPPORTED
93-
94- TEST (ScopedStdStreamCaptureTest, NotSupported) {
95- // This unit test is intentionally empty since iOS test fails when zero tests
96- // are executed.
97- }
98-
99- #endif // OPERATIONS_RESEARCH_OUTPUT_CAPTURE_SUPPORTED
100-
101106} // namespace
102107} // namespace operations_research
0 commit comments