From a10b0246ca1031231dd692402fb7b23a3de0e3d9 Mon Sep 17 00:00:00 2001 From: tharun Date: Thu, 3 Feb 2022 23:40:08 +0530 Subject: [PATCH 1/3] chore(rustfmt): remove executable path from usage string --- src/bin/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 6f5b09fc86a..196de6056b5 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -394,9 +394,8 @@ fn print_usage_to_stdout(opts: &Options, reason: &str) { format!("{}\n\n", reason) }; let msg = format!( - "{}Format Rust code\n\nusage: {} [options] ...", - sep, - env::args_os().next().unwrap().to_string_lossy() + "{}Format Rust code\n\nusage: rustfmt [options] ...", + sep ); println!("{}", opts.usage(&msg)); } From bcccbbb5f70864e55a6f1a84be7609a1dc91f8c6 Mon Sep 17 00:00:00 2001 From: tharun Date: Sat, 5 Feb 2022 00:19:29 +0530 Subject: [PATCH 2/3] add unit test for usage string --- tests/rustfmt/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 8effb1c6fca..49d18d7ebac 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -106,3 +106,13 @@ fn inline_config() { && contains("format_strings = true") ); } + +#[test] +fn rustfmt_help() { + let args = [ + "--help", + ]; + let (stdout, _) = rustfmt(&args); + assert!(stdout.contains(&format!("Format Rust code"))); + assert!(stdout.contains(&format!("usage: rustfmt [options] ..."))); +} From 26787c7b1cc2cb9a12b614e0814f06a81164880d Mon Sep 17 00:00:00 2001 From: tharun Date: Sat, 5 Feb 2022 01:35:58 +0530 Subject: [PATCH 3/3] rename test and check usage text in a single assert --- tests/rustfmt/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs index 49d18d7ebac..6976cc4d346 100644 --- a/tests/rustfmt/main.rs +++ b/tests/rustfmt/main.rs @@ -108,11 +108,10 @@ fn inline_config() { } #[test] -fn rustfmt_help() { +fn rustfmt_usage_text() { let args = [ "--help", ]; let (stdout, _) = rustfmt(&args); - assert!(stdout.contains(&format!("Format Rust code"))); - assert!(stdout.contains(&format!("usage: rustfmt [options] ..."))); + assert!(stdout.contains(&format!("Format Rust code\n\nusage: rustfmt [options] ..."))); }