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 5d71a8a

Browse files
committed
Replace print statements in runtest with write! or writeln!
1 parent d89a1a0 commit 5d71a8a

File tree

9 files changed

+98
-60
lines changed

9 files changed

+98
-60
lines changed

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

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn run(
138138

139139
if config.verbose {
140140
// We're going to be dumping a lot of info. Start on a new line.
141-
print!("\n\n");
141+
write!(stdout,"\n\n");
142142
}
143143
debug!("running {}", testpaths.file);
144144
let mut props = TestProps::from_file(&testpaths.file, revision, &config);
@@ -614,7 +614,8 @@ impl<'test> TestCx<'test> {
614614
);
615615
} else {
616616
for pattern in missing_patterns {
617-
println!(
617+
writeln!(
618+
self.stdout,
618619
"\n{prefix}: error pattern '{pattern}' not found!",
619620
prefix = self.error_prefix()
620621
);
@@ -794,7 +795,8 @@ impl<'test> TestCx<'test> {
794795
};
795796
format!("{file_name}:{line_num}{opt_col_num}")
796797
};
797-
let print_error = |e| println!("{}: {}: {}", line_str(e), e.kind, e.msg.cyan());
798+
let print_error =
799+
|e| writeln!(self.stdout, "{}: {}: {}", line_str(e), e.kind, e.msg.cyan());
798800
let push_suggestion =
799801
|suggestions: &mut Vec<_>, e: &Error, kind, line, msg, color, rank| {
800802
let mut ret = String::new();
@@ -822,7 +824,7 @@ impl<'test> TestCx<'test> {
822824
if let Some(&(_, top_rank)) = suggestions.first() {
823825
for (suggestion, rank) in suggestions {
824826
if rank == top_rank {
825-
println!(" {} {suggestion}", prefix.color(color));
827+
writeln!(self.stdout," {} {suggestion}", prefix.color(color));
826828
}
827829
}
828830
}
@@ -835,7 +837,8 @@ impl<'test> TestCx<'test> {
835837
// - only known line - meh, but suggested
836838
// - others are not worth suggesting
837839
if !unexpected.is_empty() {
838-
println!(
840+
writeln!(
841+
self.stdout,
839842
"\n{prefix}: {n} diagnostics reported in JSON output but not expected in test file",
840843
prefix = self.error_prefix(),
841844
n = unexpected.len(),
@@ -869,7 +872,8 @@ impl<'test> TestCx<'test> {
869872
}
870873
}
871874
if !not_found.is_empty() {
872-
println!(
875+
writeln!(
876+
self.stdout,
873877
"\n{prefix}: {n} diagnostics expected in test file but not reported in JSON output",
874878
prefix = self.error_prefix(),
875879
n = not_found.len(),
@@ -1963,11 +1967,11 @@ impl<'test> TestCx<'test> {
19631967
} else {
19641968
path.file_name().unwrap().into()
19651969
};
1966-
println!("------{proc_name} stdout------------------------------");
1967-
println!("{}", out);
1968-
println!("------{proc_name} stderr------------------------------");
1969-
println!("{}", err);
1970-
println!("------------------------------------------");
1970+
writeln!(self.stdout,"------{proc_name} stdout------------------------------");
1971+
writeln!(self.stdout,"{}", out);
1972+
writeln!(self.stdout,"------{proc_name} stderr------------------------------");
1973+
writeln!(self.stdout,"{}", err);
1974+
writeln!(self.stdout,"------------------------------------------");
19711975
}
19721976

19731977
fn dump_output_file(&self, out: &str, extension: &str) {
@@ -2029,7 +2033,7 @@ impl<'test> TestCx<'test> {
20292033
debug!("{message}");
20302034
if self.config.verbose {
20312035
// Note: `./x test ... --verbose --no-capture` is needed to see this print.
2032-
println!("{message}");
2036+
writeln!(self.stdout,"{message}");
20332037
}
20342038
}
20352039

@@ -2045,7 +2049,7 @@ impl<'test> TestCx<'test> {
20452049

20462050
#[track_caller]
20472051
fn fatal(&self, err: &str) -> ! {
2048-
println!("\n{prefix}: {err}", prefix = self.error_prefix());
2052+
writeln!(self.stdout,"\n{prefix}: {err}", prefix = self.error_prefix());
20492053
error!("fatal error, panic: {:?}", err);
20502054
panic!("fatal error");
20512055
}
@@ -2063,15 +2067,15 @@ impl<'test> TestCx<'test> {
20632067
proc_res: &ProcRes,
20642068
callback_before_unwind: impl FnOnce(),
20652069
) -> ! {
2066-
println!("\n{prefix}: {err}", prefix = self.error_prefix());
2070+
writeln!(self.stdout,"\n{prefix}: {err}", prefix = self.error_prefix());
20672071

20682072
// Some callers want to print additional notes after the main error message.
20692073
if let Some(note) = extra_note {
2070-
println!("{note}");
2074+
writeln!(self.stdout,"{note}");
20712075
}
20722076

20732077
// Print the details and output of the subprocess that caused this test to fail.
2074-
println!("{}", proc_res.format_info());
2078+
writeln!(self.stdout,"{}", proc_res.format_info());
20752079

20762080
// Some callers want print more context or show a custom diff before the unwind occurs.
20772081
callback_before_unwind();
@@ -2141,7 +2145,7 @@ impl<'test> TestCx<'test> {
21412145
if !self.config.has_html_tidy {
21422146
return;
21432147
}
2144-
println!("info: generating a diff against nightly rustdoc");
2148+
writeln!(self.stdout,"info: generating a diff against nightly rustdoc");
21452149

21462150
let suffix =
21472151
self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly");
@@ -2177,7 +2181,7 @@ impl<'test> TestCx<'test> {
21772181

21782182
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths);
21792183
if !proc_res.status.success() {
2180-
eprintln!("failed to run nightly rustdoc");
2184+
writeln!(self.stderr,"failed to run nightly rustdoc");
21812185
return;
21822186
}
21832187

@@ -2222,6 +2226,7 @@ impl<'test> TestCx<'test> {
22222226
let diff_filename = format!("build/tmp/rustdoc-compare-{}.diff", std::process::id());
22232227

22242228
if !write_filtered_diff(
2229+
self,
22252230
&diff_filename,
22262231
out_dir,
22272232
&compare_dir,
@@ -2242,7 +2247,7 @@ impl<'test> TestCx<'test> {
22422247
if let Some(pager) = pager {
22432248
let pager = pager.trim();
22442249
if self.config.verbose {
2245-
eprintln!("using pager {}", pager);
2250+
writeln!(self.stderr,"using pager {}", pager);
22462251
}
22472252
let output = Command::new(pager)
22482253
// disable paging; we want this to be non-interactive
@@ -2253,8 +2258,8 @@ impl<'test> TestCx<'test> {
22532258
.output()
22542259
.unwrap();
22552260
assert!(output.status.success());
2256-
println!("{}", String::from_utf8_lossy(&output.stdout));
2257-
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
2261+
writeln!(self.stdout,"{}", String::from_utf8_lossy(&output.stdout));
2262+
writeln!(self.stderr,"{}", String::from_utf8_lossy(&output.stderr));
22582263
} else {
22592264
warning!("no pager configured, falling back to unified diff");
22602265
help!(
@@ -2269,7 +2274,7 @@ impl<'test> TestCx<'test> {
22692274
match diff.read_until(b'\n', &mut line) {
22702275
Ok(0) => break,
22712276
Ok(_) => {}
2272-
Err(e) => eprintln!("ERROR: {:?}", e),
2277+
Err(e) => writeln!(self.stderr,"ERROR: {:?}", e),
22732278
}
22742279
match String::from_utf8(line.clone()) {
22752280
Ok(line) => {
@@ -2817,11 +2822,11 @@ impl<'test> TestCx<'test> {
28172822
if let Err(err) = fs::write(&actual_path, &actual) {
28182823
self.fatal(&format!("failed to write {stream} to `{actual_path}`: {err}",));
28192824
}
2820-
println!("Saved the actual {stream} to `{actual_path}`");
2825+
writeln!(self.stdout,"Saved the actual {stream} to `{actual_path}`");
28212826

28222827
if !self.config.bless {
28232828
if expected.is_empty() {
2824-
println!("normalized {}:\n{}\n", stream, actual);
2829+
writeln!(self.stdout,"normalized {}:\n{}\n", stream, actual);
28252830
} else {
28262831
self.show_diff(
28272832
stream,
@@ -2845,14 +2850,15 @@ impl<'test> TestCx<'test> {
28452850
if let Err(err) = fs::write(&expected_path, &actual) {
28462851
self.fatal(&format!("failed to write {stream} to `{expected_path}`: {err}"));
28472852
}
2848-
println!(
2853+
writeln!(
2854+
self.stdout,
28492855
"Blessing the {stream} of `{test_name}` as `{expected_path}`",
28502856
test_name = self.testpaths.file
28512857
);
28522858
}
28532859
}
28542860

2855-
println!("\nThe actual {stream} differed from the expected {stream}");
2861+
writeln!(self.stdout,"\nThe actual {stream} differed from the expected {stream}");
28562862

28572863
if self.config.bless { CompareOutcome::Blessed } else { CompareOutcome::Differed }
28582864
}
@@ -2867,7 +2873,7 @@ impl<'test> TestCx<'test> {
28672873
actual: &str,
28682874
actual_unnormalized: &str,
28692875
) {
2870-
eprintln!("diff of {stream}:\n");
2876+
writeln!(self.stderr,"diff of {stream}:\n");
28712877
if let Some(diff_command) = self.config.diff_command.as_deref() {
28722878
let mut args = diff_command.split_whitespace();
28732879
let name = args.next().unwrap();
@@ -2879,11 +2885,11 @@ impl<'test> TestCx<'test> {
28792885
}
28802886
Ok(output) => {
28812887
let output = String::from_utf8_lossy(&output.stdout);
2882-
eprint!("{output}");
2888+
write!(self.stderr,"{output}");
28832889
}
28842890
}
28852891
} else {
2886-
eprint!("{}", write_diff(expected, actual, 3));
2892+
write!(self.stderr,"{}", write_diff(expected, actual, 3));
28872893
}
28882894

28892895
// NOTE: argument order is important, we need `actual` to be on the left so the line number match up when we compare it to `actual_unnormalized` below.
@@ -2921,9 +2927,16 @@ impl<'test> TestCx<'test> {
29212927
&& !mismatches_unnormalized.is_empty()
29222928
&& !mismatches_normalized.is_empty()
29232929
{
2924-
eprintln!("Note: some mismatched output was normalized before being compared");
2930+
writeln!(
2931+
self.stderr,
2932+
"Note: some mismatched output was normalized before being compared"
2933+
);
29252934
// FIXME: respect diff_command
2926-
eprint!("{}", write_diff(&mismatches_unnormalized, &mismatches_normalized, 0));
2935+
write!(
2936+
self.stderr,
2937+
"{}",
2938+
write_diff(&mismatches_unnormalized, &mismatches_normalized, 0)
2939+
);
29272940
}
29282941
}
29292942

@@ -3001,7 +3014,7 @@ impl<'test> TestCx<'test> {
30013014
fs::create_dir_all(&incremental_dir).unwrap();
30023015

30033016
if self.config.verbose {
3004-
println!("init_incremental_test: incremental_dir={incremental_dir}");
3017+
writeln!(self.stdout,"init_incremental_test: incremental_dir={incremental_dir}");
30053018
}
30063019
}
30073020
}

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ impl TestCx<'_> {
6262
if !missing.is_empty() {
6363
missing.sort();
6464

65-
println!("\nThese items should have been contained but were not:\n");
65+
writeln!(self.stdout,"\nThese items should have been contained but were not:\n");
6666

6767
for item in &missing {
68-
println!("{}", item);
68+
writeln!(self.stdout,"{}", item);
6969
}
7070

71-
println!("\n");
71+
writeln!(self.stdout,"\n");
7272
}
7373

7474
if !unexpected.is_empty() {
@@ -78,24 +78,32 @@ impl TestCx<'_> {
7878
sorted
7979
};
8080

81-
println!("\nThese items were contained but should not have been:\n");
81+
writeln!(self.stdout,"\nThese items were contained but should not have been:\n");
8282

8383
for item in sorted {
84-
println!("{}", item);
84+
writeln!(self.stdout,"{}", item);
8585
}
8686

87-
println!("\n");
87+
writeln!(self.stdout,"\n");
8888
}
8989

9090
if !wrong_cgus.is_empty() {
9191
wrong_cgus.sort_by_key(|pair| pair.0.name.clone());
92-
println!("\nThe following items were assigned to wrong codegen units:\n");
92+
writeln!(self.stdout,"\nThe following items were assigned to wrong codegen units:\n");
9393

9494
for &(ref expected_item, ref actual_item) in &wrong_cgus {
95-
println!("{}", expected_item.name);
96-
println!(" expected: {}", codegen_units_to_str(&expected_item.codegen_units));
97-
println!(" actual: {}", codegen_units_to_str(&actual_item.codegen_units));
98-
println!();
95+
writeln!(self.stdout, "{}", expected_item.name);
96+
writeln!(
97+
self.stdout,
98+
" expected: {}",
99+
codegen_units_to_str(&expected_item.codegen_units)
100+
);
101+
writeln!(
102+
self.stdout,
103+
" actual: {}",
104+
codegen_units_to_str(&actual_item.codegen_units)
105+
);
106+
writeln!(self.stdout);
99107
}
100108
}
101109

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::fs::{File, FileType};
33

44
use camino::Utf8Path;
55

6+
use crate::runtest::TestCx;
7+
68
#[derive(Debug, PartialEq)]
79
pub enum DiffLine {
810
Context(String),
@@ -112,6 +114,7 @@ pub(crate) fn write_diff(expected: &str, actual: &str, context_size: usize) -> S
112114
///
113115
/// Returns whether any data was actually written.
114116
pub(crate) fn write_filtered_diff<Filter>(
117+
cx: &TestCx<'_>,
115118
diff_filename: &str,
116119
out_dir: &Utf8Path,
117120
compare_dir: &Utf8Path,
@@ -147,11 +150,11 @@ where
147150
}
148151

149152
if !wrote_data {
150-
println!("note: diff is identical to nightly rustdoc");
153+
writeln!(cx.stdout,"note: diff is identical to nightly rustdoc");
151154
assert!(diff_output.metadata().unwrap().len() == 0);
152155
return false;
153156
} else if verbose {
154-
eprintln!("printing diff:");
157+
writeln!(cx.stderr,"printing diff:");
155158
let mut buf = Vec::new();
156159
diff_output.read_to_end(&mut buf).unwrap();
157160
std::io::stderr().lock().write_all(&mut buf).unwrap();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ impl TestCx<'_> {
66
let proc_res = self.compile_test(WillExecute::No, self.should_emit_metadata(pm));
77

88
if std::env::var("COMPILETEST_VERBOSE_CRASHES").is_ok() {
9-
eprintln!("{}", proc_res.status);
10-
eprintln!("{}", proc_res.stdout);
11-
eprintln!("{}", proc_res.stderr);
12-
eprintln!("{}", proc_res.cmdline);
9+
writeln!(self.stderr,"{}", proc_res.status);
10+
writeln!(self.stderr,"{}", proc_res.stdout);
11+
writeln!(self.stderr,"{}", proc_res.stderr);
12+
writeln!(self.stderr,"{}", proc_res.cmdline);
1313
}
1414

1515
// if a test does not crash, consider it an error

0 commit comments

Comments
(0)

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