From 2d1b733c54ff186e63884dca487bb80b00444045 Mon Sep 17 00:00:00 2001 From: Krish Sapru Date: Sun, 12 Apr 2026 14:51:13 -0400 Subject: [PATCH 1/2] Use rustc's --diagnostic-width flag in UI tests Pass --diagnostic-width=100 to rustc in UI tests to ensure consistent error message line-wrapping regardless of the terminal width of the environment in which the tests are run. The flag is skipped for the 'msrv' toolchain (Rust 1.56.0) since it was only stabilized in Rust 1.70.0. The TERM/COLUMNS environment variables are retained since they can still influence other tools, but a comment is updated to clarify that --diagnostic-width is now the primary and more reliable mechanism. Fixes #3113 --- hermes/tests/ui.rs | 1 + tools/ui-runner/src/main.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/hermes/tests/ui.rs b/hermes/tests/ui.rs index bfdf24d502..8ef5632801 100644 --- a/hermes/tests/ui.rs +++ b/hermes/tests/ui.rs @@ -7,6 +7,7 @@ fn ui() { unsafe { std::env::set_var("HERMES_UI_TEST_MODE", "true") }; let mut config = Config::rustc(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/ui")); + config.program.args.push("--diagnostic-width=100".into()); let args = Args::test().unwrap(); config.with_args(&args); diff --git a/tools/ui-runner/src/main.rs b/tools/ui-runner/src/main.rs index 1f123259af..3b18cb3de8 100644 --- a/tools/ui-runner/src/main.rs +++ b/tools/ui-runner/src/main.rs @@ -119,8 +119,22 @@ fn main() { // Ignoring `RUSTFLAGS` and specifying our own flags here makes these // tests more reproducible. - // FIXME: These seem to have no effect (ie, rustc seems to still discover - // the real terminal width). + // The `--diagnostic-width` flag is the most reliable way to ensure that + // rustc's error messages are wrapped at a consistent width. This avoids + // flakiness in UI tests where the output might otherwise depend on the + // terminal width of the environment in which the tests are run. + // + // However, this flag was only stabilized in Rust 1.70.0 (and was unstable + // starting in 1.62.0), so we only pass it if we're not on our MSRV + // toolchain (which is 1.56.0). + if toolchain_meta_name != "msrv" { + config.program.args.push("--diagnostic-width=100".into()); + } + + // These environment variables are usually respected by CLI tools (including + // rustc) to determine the terminal width. As of this writing, rustc sometimes + // ignores them and discovers the real terminal width anyway; the + // `--diagnostic-width` flag above is more reliable. config.program.envs.push(("TERM".into(), Some("dumb".into()))); config.program.envs.push(("COLUMNS".into(), Some("100".into()))); From 357bc9882f6446291aab86441e8902334423089a Mon Sep 17 00:00:00 2001 From: Krish Sapru Date: Sun, 12 Apr 2026 16:46:55 -0400 Subject: [PATCH 2/2] ci: trigger re-run