Skip to content

Commit a2cafce

Browse files
committed
Add documentation
1 parent c8a0a1d commit a2cafce

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

test/test_interpreter.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,42 @@
2525
#include <unistd.h>
2626
#endif
2727

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+
*/
2935
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+
}
3444

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+
}
3851

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+
}
4259

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.
4764
};
4865

4966
TEST_SUITE("execute_request")
@@ -695,7 +712,7 @@ TEST_SUITE("xmagics_apply"){
695712
}
696713

697714
TEST_CASE("cell magic with empty cell body") {
698-
715+
699716
xcpp::xmagics_manager manager;
700717

701718
StreamRedirectRAII redirect(std::cerr);

0 commit comments

Comments
 (0)