| 10834 | } |
| 10835 | |
| 10836 | std::string GetCapturedString() { |
| 10837 | if (uncaptured_fd_ != -1) { |
| 10838 | // Restores the original stream. |
| 10839 | fflush(nullptr); |
| 10840 | dup2(uncaptured_fd_, fd_); |
| 10841 | close(uncaptured_fd_); |
| 10842 | uncaptured_fd_ = -1; |
| 10843 | } |
| 10844 | |
| 10845 | FILE* const file = posix::FOpen(filename_.c_str(), "r"); |
| 10846 | if (file == nullptr) { |
| 10847 | GTEST_LOG_(FATAL) << "Failed to open tmp file " << filename_ |
| 10848 | << " for capturing stream."; |
| 10849 | } |
| 10850 | const std::string content = ReadEntireFile(file); |
| 10851 | posix::FClose(file); |
| 10852 | return content; |
| 10853 | } |
| 10854 | |
| 10855 | private: |
| 10856 | const int fd_; // A stream to capture. |
no test coverage detected