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

Sign up
Appearance settings

Commit d89a1a0

Browse files
committed
Preliminary plumbing of stdout/stderr as &dyn ConsoleOut
1 parent ee87a8b commit d89a1a0

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

‎src/tools/compiletest/src/executor.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::sync::{Arc, Mutex, mpsc};
1313
use std::{env, hint, io, mem, panic, thread};
1414

1515
use crate::common::{Config, TestPaths};
16+
use crate::output_capture::{self, ConsoleOut};
1617
use crate::panic_hook;
1718

1819
mod deadline;
@@ -131,14 +132,15 @@ fn run_test_inner(
131132
io::set_output_capture(Some(Arc::clone(buf)));
132133
}
133134

134-
let panic_payload = panic::catch_unwind(move || runnable_test.run()).err();
135+
let stdout = capture.stdout();
136+
let stderr = capture.stderr();
137+
138+
let panic_payload = panic::catch_unwind(move || runnable_test.run(stdout, stderr)).err();
135139

136140
if let Some(panic_buf) = panic_hook::take_capture_buf() {
137141
let panic_buf = panic_buf.lock().unwrap_or_else(|e| e.into_inner());
138-
// For now, forward any captured panic message to (captured) stderr.
139-
// FIXME(Zalathar): Once we have our own output-capture buffer for
140-
// non-panic output, append the panic message to that buffer instead.
141-
eprint!("{panic_buf}");
142+
// Forward any captured panic message to (captured) stderr.
143+
write!(stderr, "{panic_buf}");
142144
}
143145
if matches!(capture, CaptureKind::Old { .. }) {
144146
io::set_output_capture(None);
@@ -185,6 +187,14 @@ impl CaptureKind {
185187
}
186188
}
187189

190+
fn stdout(&self) -> &dyn ConsoleOut {
191+
&output_capture::Stdout
192+
}
193+
194+
fn stderr(&self) -> &dyn ConsoleOut {
195+
&output_capture::Stderr
196+
}
197+
188198
fn into_inner(self) -> Option<Vec<u8>> {
189199
match self {
190200
Self::None => None,
@@ -210,10 +220,12 @@ impl RunnableTest {
210220
Self { config, testpaths, revision }
211221
}
212222

213-
fn run(&self) {
223+
fn run(&self,stdout:&dynConsoleOut,stderr:&dynConsoleOut) {
214224
__rust_begin_short_backtrace(|| {
215225
crate::runtest::run(
216226
Arc::clone(&self.config),
227+
stdout,
228+
stderr,
217229
&self.testpaths,
218230
self.revision.as_deref(),
219231
);

‎src/tools/compiletest/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod directives;
1515
pub mod errors;
1616
mod executor;
1717
mod json;
18+
mod output_capture;
1819
mod panic_hook;
1920
mod raise_fd_limit;
2021
mod read2;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::fmt;
2+
use std::panic::RefUnwindSafe;
3+
4+
pub trait ConsoleOut: fmt::Debug + RefUnwindSafe {
5+
fn write_fmt(&self, args: fmt::Arguments<'_>);
6+
}
7+
8+
#[derive(Debug)]
9+
pub(crate) struct Stdout;
10+
11+
impl ConsoleOut for Stdout {
12+
fn write_fmt(&self, args: fmt::Arguments<'_>) {
13+
print!("{args}");
14+
}
15+
}
16+
17+
#[derive(Debug)]
18+
pub(crate) struct Stderr;
19+
20+
impl ConsoleOut for Stderr {
21+
fn write_fmt(&self, args: fmt::Arguments<'_>) {
22+
eprint!("{args}");
23+
}
24+
}

‎src/tools/compiletest/src/runtest.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::common::{
2323
};
2424
use crate::directives::TestProps;
2525
use crate::errors::{Error, ErrorKind, load_errors};
26+
use crate::output_capture::ConsoleOut;
2627
use crate::read2::{Truncated, read2_abbreviated};
2728
use crate::runtest::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
2829
use crate::util::{Utf8PathBufExt, add_dylib_path, static_regex};
@@ -108,7 +109,13 @@ fn dylib_name(name: &str) -> String {
108109
format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION)
109110
}
110111

111-
pub fn run(config: Arc<Config>, testpaths: &TestPaths, revision: Option<&str>) {
112+
pub fn run(
113+
config: Arc<Config>,
114+
stdout: &dyn ConsoleOut,
115+
stderr: &dyn ConsoleOut,
116+
testpaths: &TestPaths,
117+
revision: Option<&str>,
118+
) {
112119
match &*config.target {
113120
"arm-linux-androideabi"
114121
| "armv7-linux-androideabi"
@@ -143,7 +150,7 @@ pub fn run(config: Arc<Config>, testpaths: &TestPaths, revision: Option<&str>) {
143150
props.incremental_dir = Some(incremental_dir(&config, testpaths, revision));
144151
}
145152

146-
let cx = TestCx { config: &config, props: &props, testpaths, revision };
153+
let cx = TestCx { config: &config, stdout, stderr,props: &props, testpaths, revision };
147154

148155
if let Err(e) = create_dir_all(&cx.output_base_dir()) {
149156
panic!("failed to create output base directory {}: {e}", cx.output_base_dir());
@@ -162,6 +169,8 @@ pub fn run(config: Arc<Config>, testpaths: &TestPaths, revision: Option<&str>) {
162169
revision_props.incremental_dir = props.incremental_dir.clone();
163170
let rev_cx = TestCx {
164171
config: &config,
172+
stdout,
173+
stderr,
165174
props: &revision_props,
166175
testpaths,
167176
revision: Some(revision),
@@ -212,6 +221,8 @@ pub fn compute_stamp_hash(config: &Config) -> String {
212221
#[derive(Copy, Clone, Debug)]
213222
struct TestCx<'test> {
214223
config: &'test Config,
224+
stdout: &'test dyn ConsoleOut,
225+
stderr: &'test dyn ConsoleOut,
215226
props: &'test TestProps,
216227
testpaths: &'test TestPaths,
217228
revision: Option<&'test str>,
@@ -978,6 +989,8 @@ impl<'test> TestCx<'test> {
978989
self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
979990
let aux_cx = TestCx {
980991
config: self.config,
992+
stdout: self.stdout,
993+
stderr: self.stderr,
981994
props: &props_for_aux,
982995
testpaths: &aux_testpaths,
983996
revision: self.revision,
@@ -1343,6 +1356,8 @@ impl<'test> TestCx<'test> {
13431356
let aux_output = TargetLocation::ThisDirectory(aux_dir.clone());
13441357
let aux_cx = TestCx {
13451358
config: self.config,
1359+
stdout: self.stdout,
1360+
stderr: self.stderr,
13461361
props: &aux_props,
13471362
testpaths: &aux_testpaths,
13481363
revision: self.revision,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /