Skip to content

Commit

Permalink
test: Add test for issue-14194
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Aug 31, 2024
1 parent 59ecb11 commit 7a59f2e
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,90 @@ fn crate_library_path_env_var() {
setenv_for_removing_empty_component(p.cargo("run")).run();
}

// See https://github.com/rust-lang/cargo/issues/14194
#[cargo_test]
fn issue_14194_deduplicate_library_path_env_var() {
let p = project()
.file(
"src/main.rs",
&format!(
r#"
use std::process::Command;
fn main() {{
println!("{{}}", std::env::var("{}").unwrap_or_default());
let level: i32 = std::env!("LEVEL").to_string().parse().unwrap();
if level == 0 {{
return;
}}
let _ = Command::new(std::env!("CARGO"))
.arg("run")
.env("LEVEL", (level - 1).to_string())
.status()
.unwrap();
}}
"#,
dylib_path_envvar()
),
)
.file(
"build.rs",
&format!(
r#"
fn main() {{
println!("cargo::rerun-if-env-changed={}");
}}
"#,
dylib_path_envvar()
),
)
.build();

setenv_for_removing_empty_component(p.cargo("run"))
.env("LEVEL", 2.to_string())
.with_stdout_data(str![[r#"
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
"#]])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
"#]])
.run();

setenv_for_removing_empty_component(p.cargo("run"))
.env("LEVEL", 2.to_string())
.with_stdout_data(str![[r#"
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:[ROOT]/foo/target/debug/deps:[ROOT]/foo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/workspace/cargo/target/debug/build/curl-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libgit2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/build/libnghttp2-sys-[HASH]/out/i/lib:/root/workspace/cargo/target/debug/build/libsqlite3-sys-[HASH]/out:/root/workspace/cargo/target/debug/build/libssh2-sys-[HASH]/out/build:/root/workspace/cargo/target/debug/deps:/root/workspace/cargo/target/debug:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib/rustlib/[HOST_TARGET]/lib:/root/.rustup/toolchains/nightly-[HOST_TARGET]/lib
"#]])
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo`
"#]])
.run();
}

// Regression test for #4277
#[cargo_test]
fn build_with_fake_libc_not_loading() {
Expand Down

0 comments on commit 7a59f2e

Please sign in to comment.