Capture output stream (stdout/stderr)
- Dominant language
- C++
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
At the moment, we don't have any API that can also capture the output streams (_stdout/stderr_), so even to test our own `xtest` API we have to use the `redirector` API that we have inside of our tests which is not completely efficient. So, what I have decided to do is to implement a [`CapturedStream`](https://github.com/google/googletest/blob/191ca1f3a9262b90a586ae2c2e8c742c3d867801/googletest/src/gtest-port.cc#L1033-L1144) API similar to the one that [googletest](https://github.com/google/googletest/) uses.
__Problems with [`RedirectorContext`](https://github.com/joshiayush/xtest/blob/master/tests/redirector.hh#L47-L91):__
* We have to explicitly pass the type of the stream we want to capture.
* We have to manually replace the stream file with our own context buffer.
* We also have to restore the stream manually.
__What [`googletest`](https://github.com/google/googletest/) have for us:__
* Simplicity; (following example is taken from the [`cjson`](https://github.com/joshiayush/cjson/blob/master/tests/sstream/testPrinters.hh#L59-L61) library).
```C++
testing::internal::CaptureStdout();
PrintSstream(&sstream, FALSE);
std::string stdout_output = testing::internal::GetCapturedStdout();
```
Contributor guide
Assessment
This issue has not been assessed yet.