Skip to content

Commit 93e93b7

Browse files
committed
fix(libtest): Deprecate '--logfile'
rust-lang/testing-devex-team#9 proposed changing the behavior of `--logfile`. The given reasons were: (1) Bazel can't programmatically process stdout. This seems like a limitation in Bazel and we recommend focusing on that. If we look at the wider Rust ecosystem, Rustc and Cargo don't support any such mechanism and the Cargo team rejected having one. Expecting this in libtest when its not supported elsewhere seems too specialized. (2) Tests that leak out non-programmatic output that intermixes with programmatic output. We acknowledge this is a problem to be evaluated but we need to make sure we are stepping back and gathering requirements, rather than assuming `--logfile` will fit the needs. Independent of the motive, regarding using or changing `--logfile` (1) Most ways to do it would be a breaking change, like if we respect any stable `--format`. As suggested above, we could specialize this to new `--format` values but that would be confusing for some values to apply but not others. (2) Other ways of solving this add new features to lib`test` when we are instead wanting to limit the feature set it has to minimize the compatibility surface that has to be maintained and the burden it would put on third party harnesses which are a focus area. Examples include `--format compact` or a `--log-format` flag (3) The existence of `--logfile` dates back quite a ways (rust-lang@5cc050b, rust-lang#2127) and the history gives the impression this more of slipped through rather than being an intended feature (see also rust-lang#82350 (comment)). Deprecation would better match to how it has been treated. By deprecating this, we do not expect custom test harnesses (rust-lang/testing-devex-team#2) to implement this. T-testing-devex held an FCP for deprecating in rust-lang/testing-devex-team#9 though according to [RFC rust-lang#3455](https://rust-lang.github.io/rfcs/3455-t-test.html), this is still subject to final approval from T-libs-api.
1 parent a00df61 commit 93e93b7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

library/test/src/cli.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Module converting command-line arguments into test configuration.
22
33
use std::env;
4-
use std::io::{self, IsTerminal};
4+
use std::io::{self, IsTerminal, Write};
55
use std::path::PathBuf;
66

77
use super::options::{ColorConfig, Options, OutputFormat, RunIgnored};
@@ -58,7 +58,7 @@ fn optgroups() -> getopts::Options {
5858
.optflag("", "bench", "Run benchmarks instead of tests")
5959
.optflag("", "list", "List all tests and benchmarks")
6060
.optflag("h", "help", "Display this message")
61-
.optopt("", "logfile", "Write logs to the specified file", "PATH")
61+
.optopt("", "logfile", "Write logs to the specified file (deprecated)", "PATH")
6262
.optflag(
6363
"",
6464
"nocapture",
@@ -281,6 +281,10 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
281281

282282
let options = Options::new().display_output(matches.opt_present("show-output"));
283283

284+
if logfile.is_some() && !format.is_programmatic() {
285+
let _ = write!(io::stdout(), "warning: `--logfile` is deprecated");
286+
}
287+
284288
let test_opts = TestOpts {
285289
list,
286290
filters,

library/test/src/options.rs

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ pub enum OutputFormat {
3838
Junit,
3939
}
4040

41+
impl OutputFormat {
42+
pub(crate) fn is_programmatic(&self) -> bool {
43+
match self {
44+
Self::Pretty | Self::Terse => true,
45+
Self::Json | Self::Junit => false,
46+
}
47+
}
48+
}
49+
4150
/// Whether ignored test should be run or not
4251
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4352
pub enum RunIgnored {

src/doc/rustc/src/tests/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ Controls the format of the output. Valid options:
268268

269269
Writes the results of the tests to the given file.
270270

271+
This option is deprecated.
272+
271273
#### `--report-time`
272274

273275
⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z

0 commit comments

Comments
 (0)