From d0fbb1a0ef805bb7f08e6acef2df6a11df2960e8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 11 Sep 2025 10:31:33 -0500 Subject: [PATCH] refactor(harness): Put things in use-order --- crates/libtest2-harness/src/harness.rs | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/libtest2-harness/src/harness.rs b/crates/libtest2-harness/src/harness.rs index 3a4e325..20cfcff 100644 --- a/crates/libtest2-harness/src/harness.rs +++ b/crates/libtest2-harness/src/harness.rs @@ -146,6 +146,27 @@ mod sealed { pub const ERROR_EXIT_CODE: i32 = 101; +fn expand_args( + args: impl IntoIterator>, +) -> std::io::Result> { + let mut expanded = Vec::new(); + for arg in args { + let arg = arg.into(); + if let Some(argfile) = arg.to_str().and_then(|s| s.strip_prefix("@")) { + expanded.extend(parse_argfile(std::path::Path::new(argfile))?); + } else { + expanded.push(arg); + } + } + Ok(expanded) +} + +fn parse_argfile(path: &std::path::Path) -> std::io::Result> { + // Logic taken from rust-lang/rust's `compiler/rustc_driver_impl/src/args.rs` + let content = std::fs::read_to_string(path)?; + Ok(content.lines().map(|s| s.into()).collect()) +} + fn parse<'p>(parser: &mut cli::Parser<'p>) -> Result> { let mut test_opts = libtest_lexarg::TestOptsBuilder::new(); @@ -204,27 +225,6 @@ fn parse<'p>(parser: &mut cli::Parser<'p>) -> Result>, -) -> std::io::Result> { - let mut expanded = Vec::new(); - for arg in args { - let arg = arg.into(); - if let Some(argfile) = arg.to_str().and_then(|s| s.strip_prefix("@")) { - expanded.extend(parse_argfile(std::path::Path::new(argfile))?); - } else { - expanded.push(arg); - } - } - Ok(expanded) -} - -fn parse_argfile(path: &std::path::Path) -> std::io::Result> { - // Logic taken from rust-lang/rust's `compiler/rustc_driver_impl/src/args.rs` - let content = std::fs::read_to_string(path)?; - Ok(content.lines().map(|s| s.into()).collect()) -} - fn notifier(opts: &libtest_lexarg::TestOpts) -> Box { #[cfg(feature = "color")] let stdout = anstream::stdout();