Skip to content

Commit 269db62

Browse files
committed
Change the logv function into a TestCx method.
When working on a new output-capture system, this will make it easier to obtain a capturing stream from the test context.
1 parent 3d54f19 commit 269db62

File tree

4 files changed

+19
-23
lines changed

4 files changed

+19
-23
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::prelude::*;
77
use std::io::{self, BufReader};
88
use std::process::{Child, Command, ExitStatus, Output, Stdio};
99
use std::sync::Arc;
10-
use std::{env, iter, str};
10+
use std::{env, fmt, iter, str};
1111

1212
use build_helper::fs::remove_and_create_dir_all;
1313
use camino::{Utf8Path, Utf8PathBuf};
@@ -25,7 +25,7 @@ use crate::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
2525
use crate::directives::TestProps;
2626
use crate::errors::{Error, ErrorKind, load_errors};
2727
use crate::read2::{Truncated, read2_abbreviated};
28-
use crate::util::{Utf8PathBufExt, add_dylib_path, logv, static_regex};
28+
use crate::util::{Utf8PathBufExt, add_dylib_path, static_regex};
2929
use crate::{ColorConfig, help, json, stamp_file_path, warning};
3030

3131
mod debugger;
@@ -1459,7 +1459,7 @@ impl<'test> TestCx<'test> {
14591459
) -> ProcRes {
14601460
let cmdline = {
14611461
let cmdline = self.make_cmdline(&command, lib_path);
1462-
logv(self.config, format!("executing {}", cmdline));
1462+
self.logv(format_args!("executing {cmdline}"));
14631463
cmdline
14641464
};
14651465

@@ -2006,6 +2006,18 @@ impl<'test> TestCx<'test> {
20062006
output_base_name(self.config, self.testpaths, self.safe_revision())
20072007
}
20082008

2009+
/// Prints a message to (captured) stdout if `config.verbose` is true.
2010+
/// The message is also logged to `tracing::debug!` regardles of verbosity.
2011+
///
2012+
/// Use `format_args!` as the argument to perform formatting if required.
2013+
fn logv(&self, message: impl fmt::Display) {
2014+
debug!("{message}");
2015+
if self.config.verbose {
2016+
// Note: `./x test ... --verbose --no-capture` is needed to see this print.
2017+
println!("{message}");
2018+
}
2019+
}
2020+
20092021
/// Prefix to print before error messages. Normally just `error`, but also
20102022
/// includes the revision name for tests that use revisions.
20112023
#[must_use]

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use super::debugger::DebuggerCommands;
1010
use super::{Debugger, Emit, ProcRes, TestCx, Truncated, WillExecute};
1111
use crate::common::Config;
1212
use crate::debuggers::{extract_gdb_version, is_android_gdb_target};
13-
use crate::util::logv;
1413

1514
impl TestCx<'_> {
1615
pub(super) fn run_debuginfo_test(&self) {
@@ -234,7 +233,7 @@ impl TestCx<'_> {
234233
gdb.args(debugger_opts);
235234
// FIXME(jieyouxu): don't pass an empty Path
236235
let cmdline = self.make_cmdline(&gdb, Utf8Path::new(""));
237-
logv(self.config, format!("executing {}", cmdline));
236+
self.logv(format_args!("executing {cmdline}"));
238237
cmdline
239238
};
240239

src/tools/compiletest/src/runtest/pretty.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::fs;
22

33
use super::{ProcRes, ReadFrom, TestCx};
4-
use crate::util::logv;
54

65
impl TestCx<'_> {
76
pub(super) fn run_pretty_test(&self) {
87
if self.props.pp_exact.is_some() {
9-
logv(self.config, "testing for exact pretty-printing".to_owned());
8+
self.logv("testing for exact pretty-printing");
109
} else {
11-
logv(self.config, "testing for converging pretty-printing".to_owned());
10+
self.logv("testing for converging pretty-printing");
1211
}
1312

1413
let rounds = match self.props.pp_exact {
@@ -21,10 +20,7 @@ impl TestCx<'_> {
2120

2221
let mut round = 0;
2322
while round < rounds {
24-
logv(
25-
self.config,
26-
format!("pretty-printing round {} revision {:?}", round, self.revision),
27-
);
23+
self.logv(format_args!("pretty-printing round {round} revision {:?}", self.revision));
2824
let read_from =
2925
if round == 0 { ReadFrom::Path } else { ReadFrom::Stdin(srcs[round].to_owned()) };
3026

src/tools/compiletest/src/util.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ use std::env;
22
use std::process::Command;
33

44
use camino::{Utf8Path, Utf8PathBuf};
5-
use tracing::*;
6-
7-
use crate::common::Config;
85

96
#[cfg(test)]
107
mod tests;
@@ -26,14 +23,6 @@ fn path_div() -> &'static str {
2623
";"
2724
}
2825

29-
pub fn logv(config: &Config, s: String) {
30-
debug!("{}", s);
31-
if config.verbose {
32-
// Note: `./x test ... --verbose --no-capture` is needed to see this print.
33-
println!("{}", s);
34-
}
35-
}
36-
3726
pub trait Utf8PathBufExt {
3827
/// Append an extension to the path, even if it already has one.
3928
fn with_extra_extension(&self, extension: &str) -> Utf8PathBuf;

0 commit comments

Comments
 (0)