| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d20235b commit 863bfc4
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,8 @@ | |||
| 5 | 5 | #include <string> | |
| 6 | 6 | #include "gtest/gtest.h" | |
| 7 | 7 | #include "node_test_fixture.h" | |
| 8 | + #include <stdio.h> | ||
| 9 | + #include <cstdio> | ||
| 8 | 10 | ||
| 9 | 11 | using node::AtExit; | |
| 10 | 12 | using node::RunAtExit; | |
@@ -66,7 +68,34 @@ TEST_F(EnvironmentTest, EnvironmentWithESMLoader) { | |||
| 66 | 68 | "})()"); | |
| 67 | 69 | } | |
| 68 | 70 | ||
| 71 | + class RedirectStdErr { | ||
| 72 | + public: | ||
| 73 | + explicit RedirectStdErr(const char* filename) : filename_(filename) { | ||
| 74 | + fflush(stderr); | ||
| 75 | + fgetpos(stderr, &pos_); | ||
| 76 | + fd_ = dup(fileno(stderr)); | ||
| 77 | + freopen(filename_, "w", stderr); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + ~RedirectStdErr() { | ||
| 81 | + fflush(stderr); | ||
| 82 | + dup2(fd_, fileno(stderr)); | ||
| 83 | + close(fd_); | ||
| 84 | + remove(filename_); | ||
| 85 | + clearerr(stderr); | ||
| 86 | + fsetpos(stderr, &pos_); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + private: | ||
| 90 | + int fd_; | ||
| 91 | + fpos_t pos_; | ||
| 92 | + const char* filename_; | ||
| 93 | + }; | ||
| 94 | + | ||
| 69 | 95 | TEST_F(EnvironmentTest, EnvironmentWithNoESMLoader) { | |
| 96 | + // The following line will cause stderr to get redirected to avoid the | ||
| 97 | + // error that would otherwise be printed to the console by this test. | ||
| 98 | + RedirectStdErr redirect_scope("environment_test.log"); | ||
| 70 | 99 | const v8::HandleScope handle_scope(isolate_); | |
| 71 | 100 | Argv argv; | |
| 72 | 101 | Env env {handle_scope, argv, node::EnvironmentFlags::kNoRegisterESMLoader}; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments