From 33f436797583a080a4c28c4fcd3fc1ea0aa6867b Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 9 Nov 2024 12:17:52 -0500 Subject: [PATCH] fix: redact host target when comparing `CARGO_ENV` path This was found when updating git submodule in rust-lang/rust ``` ---- test::cargo_test_env stdout ---- running `/Users/weihanglo/dev/rust/build/aarch64-apple-darwin/stage2-tools/aarch64-apple-darwin/release/cargo test --lib -- --nocapture` thread 'test::cargo_test_env' panicked at tests/testsuite/test.rs:3904:10: test failed running `/Users/weihanglo/dev/rust/build/aarch64-apple-darwin/stage2-tools/aarch64-apple-darwin/release/cargo test --lib -- --nocapture` error: expected to find: /Users/weihanglo/dev/rust/build/aarch64-apple-darwin/stage2-tools/aarch64-apple-darwin/release/cargo did not find in output: [COMPILING] foo v0.5.0 ([ROOT]/foo) [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s [RUNNING] unittests src/lib.rs (target/debug/deps/foo-[HASH]) /Users/weihanglo/dev/rust/build/[HOST_TARGET]/stage2-tools/[HOST_TARGET]/release/cargo ``` --- tests/testsuite/test.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index 2a3577312616..d96309a68288 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -3870,6 +3870,7 @@ fn doctest_and_registry() { #[cargo_test] fn cargo_test_env() { + let rustc_host = rustc_host(); let src = format!( r#" #![crate_type = "rlib"] @@ -3896,6 +3897,7 @@ fn cargo_test_env() { .with_extension("") .to_str() .unwrap() + .replace(rustc_host, "[HOST_TARGET]") ); p.cargo("test --lib -- --nocapture") .with_stderr_contains(cargo) @@ -3911,7 +3913,14 @@ test env_test ... ok .unwrap() .canonicalize() .unwrap(); - let stderr_rustc = format!("{}[EXE]", rustc.with_extension("").to_str().unwrap()); + let stderr_rustc = format!( + "{}[EXE]", + rustc + .with_extension("") + .to_str() + .unwrap() + .replace(rustc_host, "[HOST_TARGET]") + ); p.cargo("test --lib -- --nocapture") // we use rustc since $CARGO is only used if it points to a path that exists .env(cargo::CARGO_ENV, rustc)