GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: redirect stderr EnvironmentWithNoESMLoader · nodejs/node@064144d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/cctest
    • test_environment.cc
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.