|
25 | 25 | #include <unistd.h>
|
26 | 26 | #endif
|
27 | 27 |
|
28 |
| -// Object for capturing stderr |
| 28 | +/** |
| 29 | + * @class StreamRedirectRAII |
| 30 | + * @brief A RAII class to redirect a stream to a stringstream. |
| 31 | + * |
| 32 | + * This class redirects the output of a given std::ostream to a std::stringstream. |
| 33 | + * The original stream is restored when the object is destroyed. |
| 34 | + */ |
29 | 35 | class StreamRedirectRAII {
|
30 |
| - public: |
31 |
| - StreamRedirectRAII(std::ostream& stream) : old_stream_buff(stream.rdbuf()), stream_to_redirect(stream) { |
32 |
| - stream_to_redirect.rdbuf(ss.rdbuf()); |
33 |
| - } |
| 36 | +public: |
| 37 | + /** |
| 38 | + * @brief Constructor that starts redirecting the given stream. |
| 39 | + * @param stream The stream to redirect. |
| 40 | + */ |
| 41 | + StreamRedirectRAII(std::ostream& stream) : old_stream_buff(stream.rdbuf()), stream_to_redirect(stream) { |
| 42 | + stream_to_redirect.rdbuf(ss.rdbuf()); |
| 43 | + } |
34 | 44 |
|
35 |
| - ~StreamRedirectRAII() { |
36 |
| - stream_to_redirect.rdbuf(old_stream_buff); |
37 |
| - } |
| 45 | + /** |
| 46 | + * @brief Destructor that restores the original stream. |
| 47 | + */ |
| 48 | + ~StreamRedirectRAII() { |
| 49 | + stream_to_redirect.rdbuf(old_stream_buff); |
| 50 | + } |
38 | 51 |
|
39 |
| - std::string getCaptured() { |
40 |
| - return ss.str(); |
41 |
| - } |
| 52 | + /** |
| 53 | + * @brief Get the output that was written to the stream. |
| 54 | + * @return A string containing the output that was written to the stream. |
| 55 | + */ |
| 56 | + std::string getCaptured() { |
| 57 | + return ss.str(); |
| 58 | + } |
42 | 59 |
|
43 |
| - private: |
44 |
| - std::streambuf* old_stream_buff; |
45 |
| - std::ostream& stream_to_redirect; |
46 |
| - std::stringstream ss; |
| 60 | +private: |
| 61 | + std::streambuf* old_stream_buff; ///< The original buffer of the stream. |
| 62 | + std::ostream& stream_to_redirect; ///< The stream that is being redirected. |
| 63 | + std::stringstream ss; ///< The stringstream that the stream is redirected to. |
47 | 64 | };
|
48 | 65 |
|
49 | 66 | TEST_SUITE("execute_request")
|
@@ -695,7 +712,7 @@ TEST_SUITE("xmagics_apply"){
|
695 | 712 | }
|
696 | 713 |
|
697 | 714 | TEST_CASE("cell magic with empty cell body") {
|
698 |
| - |
| 715 | + |
699 | 716 | xcpp::xmagics_manager manager;
|
700 | 717 |
|
701 | 718 | StreamRedirectRAII redirect(std::cerr);
|
|
0 commit comments