Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 863bfc4

Browse filesBrowse files
danbevdanielleadams
authored andcommitted
test: redirect stderr EnvironmentWithNoESMLoader
This commit adds a suggestion to redirect stderr for EnvironmentTest.EnvironmentWithNoESMLoader. The motivation for this is that currently this tests prints the following error (which is expected): vm:module(0):1 globalThis.importResult = import("") ^ Error: Not supported at vm:module(0):1:1 at SourceTextModule.evaluate (node:internal/vm/module:229:23) at node:embedder_main_12:1:328 at processTicksAndRejections (node:internal/process/task_queues:93:5) It might not be obvious which test caused this error just by looking at the output above and it would be nice if it was not displayed. PR-URL: #36548 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent d20235b commit 863bfc4
Copy full SHA for 863bfc4

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Open diff view settings
Collapse file

‎test/cctest/test_environment.cc‎

Copy file name to clipboardExpand all lines: test/cctest/test_environment.cc
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <string>
66
#include "gtest/gtest.h"
77
#include "node_test_fixture.h"
8+
#include <stdio.h>
9+
#include <cstdio>
810

911
using node::AtExit;
1012
using node::RunAtExit;
@@ -66,7 +68,34 @@ TEST_F(EnvironmentTest, EnvironmentWithESMLoader) {
6668
"})()");
6769
}
6870

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+
6995
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");
7099
const v8::HandleScope handle_scope(isolate_);
71100
Argv argv;
72101
Env env {handle_scope, argv, node::EnvironmentFlags::kNoRegisterESMLoader};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.