]> git.proxmox.com Git - cargo.git/commitdiff
test: make tests compatible when force using argfile
authorWeihang Lo <me@weihanglo.tw>
Sun, 10 Apr 2022 13:16:12 +0000 (21:16 +0800)
committerWeihang Lo <me@weihanglo.tw>
Sun, 10 Apr 2022 14:23:20 +0000 (22:23 +0800)
crates/cargo-test-support/src/tools.rs
tests/testsuite/fix.rs
tests/testsuite/rustdocflags.rs

index 9847af2b5b679efcc53cffbae42ecb8fd998a526..7c056b6fa99708cd52e233ecbe4a8a45f88c88b7 100644 (file)
@@ -24,8 +24,17 @@ pub fn echo_wrapper() -> PathBuf {
         .file(
             "src/main.rs",
             r#"
+            use std::fs::read_to_string;
+            use std::path::PathBuf;
             fn main() {
-                let args = std::env::args().collect::<Vec<_>>();
+                // Handle args from `@path` argfile for rustc
+                let args = std::env::args()
+                    .flat_map(|p| if let Some(p) = p.strip_prefix("@") {
+                        read_to_string(p).unwrap().lines().map(String::from).collect()
+                    } else {
+                        vec![p]
+                    })
+                    .collect::<Vec<_>>();
                 eprintln!("WRAPPER CALLED: {}", args[1..].join(" "));
                 let status = std::process::Command::new(&args[1])
                     .args(&args[2..]).status().unwrap();
index fce7ab843e5f3de2588638710a27b44be05ae718..04278b34415ce58bd076b896c50c0a0b43a3dbb6 100644 (file)
@@ -89,8 +89,14 @@ fn broken_fixes_backed_out() {
 
                 fn main() {
                     // Ignore calls to things like --print=file-names and compiling build.rs.
+                    // Also compatible for rustc invocations with `@path` argfile.
                     let is_lib_rs = env::args_os()
                         .map(PathBuf::from)
+                        .flat_map(|p| if let Some(p) = p.to_str().unwrap_or_default().strip_prefix("@") {
+                            fs::read_to_string(p).unwrap().lines().map(PathBuf::from).collect()
+                        } else {
+                            vec![p]
+                        })
                         .any(|l| l == Path::new("src/lib.rs"));
                     if is_lib_rs {
                         let path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
@@ -1319,8 +1325,15 @@ fn fix_to_broken_code() {
                 use std::process::{self, Command};
 
                 fn main() {
+                    // Ignore calls to things like --print=file-names and compiling build.rs.
+                    // Also compatible for rustc invocations with `@path` argfile.
                     let is_lib_rs = env::args_os()
                         .map(PathBuf::from)
+                        .flat_map(|p| if let Some(p) = p.to_str().unwrap_or_default().strip_prefix("@") {
+                            fs::read_to_string(p).unwrap().lines().map(PathBuf::from).collect()
+                        } else {
+                            vec![p]
+                        })
                         .any(|l| l == Path::new("src/lib.rs"));
                     if is_lib_rs {
                         let path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
index b17f83c2fdf06a3c0450d6f1b7ac3dde2dceef32..44175de40c11ae9f7a708dc7950dcbe1384f04e3 100644 (file)
@@ -112,6 +112,7 @@ fn whitespace() {
 
     const SPACED_VERSION: &str = "a\nb\tc\u{00a0}d";
     p.cargo("doc")
+        .env_remove("__CARGO_TEST_FORCE_ARGFILE") // Not applicable for argfile.
         .env(
             "RUSTDOCFLAGS",
             format!("--crate-version {}", SPACED_VERSION),