File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 25
25
#include < unistd.h>
26
26
#endif
27
27
28
+ // Object for capturing stderr
29
+ class StdErrRedirect {
30
+ public:
31
+ StdErrRedirect (std::ostream& new_stream) : old_cerr_buff(std::cerr.rdbuf()), ss(static_cast <std::stringstream&>(new_stream)) {
32
+ std::cerr.rdbuf (ss.rdbuf ());
33
+ }
34
+
35
+ ~StdErrRedirect () {
36
+ std::cerr.rdbuf (old_cerr_buff);
37
+ }
38
+
39
+ std::string getCaptured () {
40
+ return ss.str ();
41
+ }
42
+
43
+ private:
44
+ std::streambuf* old_cerr_buff;
45
+ std::stringstream& ss;
46
+ };
47
+
28
48
TEST_SUITE (" execute_request" )
29
49
{
30
50
TEST_CASE (" stl" )
@@ -677,14 +697,12 @@ TEST_SUITE("xmagics_apply"){
677
697
xcpp::xmagics_manager manager;
678
698
679
699
std::stringstream ss;
680
- auto cerr_buff = std::cerr.rdbuf ();
681
- std::cerr.rdbuf (ss.rdbuf ());
700
+ StdErrRedirect redirect (ss);
682
701
683
- manager.apply (" test" , " line" , " " );
702
+ manager.apply (" test" , " line" , " " );
684
703
685
- std::cerr.rdbuf (cerr_buff);
686
- REQUIRE (ss.str () == " UsageError: %%test is a cell magic, but the cell body is empty.\n "
687
- " If you only intend to display %%test help, please use a double line break to fill in the cell body.\n " );
704
+ REQUIRE (redirect.getCaptured () == " UsageError: %%test is a cell magic, but the cell body is empty.\n "
705
+ " If you only intend to display %%test help, please use a double line break to fill in the cell body.\n " );
688
706
689
707
}
690
708
}
You can’t perform that action at this time.
0 commit comments