From c03c5807e84b285d85190650838c4220b0b9c751 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 9 Nov 2024 12:05:00 -0500 Subject: [PATCH 1/2] test: fix replacing `.exe` only once On non-Windows platform the redacted string became something like below, which was valid but didn't make sense: ``` [EXE]/[EXE]U[EXE]s[EXE]e[EXE]r[EXE]s[EXE]/[EXE]w[EXE]h[EXE]l[EXE]o[EXE]/[EXE]d[EXE]e[EXE]v[EXE]/[EXE]r[EXE]u[EXE]s[EXE]t[EXE]/[EXE]b[EXE]u[EXE]i[EXE]l[EXE]d[EXE]/[EXE]a[EXE]a[EXE]r[EXE]c[EXE]h[EXE]6[EXE]4[EXE]-[EXE]a[EXE]p[EXE]p[EXE]l[EXE]e[EXE]-[EXE]d[EXE]a[EXE]r[EXE]w[EXE]i[EXE]n[EXE]/[EXE]s[EXE]t[EXE]a[EXE]g[EXE]e[EXE]2[EXE]-[EXE]t[EXE]o[EXE]o[EXE]l[EXE]s[EXE]/[EXE]a[EXE]a[EXE]r[EXE]c[EXE]h[EXE]6[EXE]4[EXE]-[EXE]a[EXE]p[EXE]p[EXE]l[EXE]e[EXE]-[EXE]d[EXE]a[EXE]r[EXE]w[EXE]i[EXE]n[EXE]/[EXE]r[EXE]e[EXE]l[EXE]e[EXE]a[EXE]s[EXE]e[EXE]/[EXE]c[EXE]a[EXE]r[EXE]g[EXE]o[EXE] ``` Here we simply remove the extension and append `[EXE]` at the end. --- tests/testsuite/test.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/testsuite/test.rs b/tests/testsuite/test.rs index dd66bfff003..2a357731261 100644 --- a/tests/testsuite/test.rs +++ b/tests/testsuite/test.rs @@ -3888,12 +3888,15 @@ fn cargo_test_env() { .file("src/lib.rs", &src) .build(); - let cargo = cargo_exe() - .canonicalize() - .unwrap() - .to_str() - .unwrap() - .replace(std::env::consts::EXE_SUFFIX, "[EXE]"); + let cargo = format!( + "{}[EXE]", + cargo_exe() + .canonicalize() + .unwrap() + .with_extension("") + .to_str() + .unwrap() + ); p.cargo("test --lib -- --nocapture") .with_stderr_contains(cargo) .with_stdout_data(str![[r#" @@ -3908,10 +3911,7 @@ test env_test ... ok .unwrap() .canonicalize() .unwrap(); - let stderr_rustc = rustc - .to_str() - .unwrap() - .replace(std::env::consts::EXE_SUFFIX, "[EXE]"); + let stderr_rustc = format!("{}[EXE]", rustc.with_extension("").to_str().unwrap()); 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) From 7347918e383953be128ec514e4388848550aefd6 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 9 Nov 2024 12:17:52 -0500 Subject: [PATCH 2/2] test: 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 2a357731261..d96309a6828 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)