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 Oct 5, 2024
1 parent ad074ab commit 4abbeac
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,57 @@ 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() {{
let args: Vec<String> = std::env::args().collect();
if args.len() == 1 {{
return;
}}
let level: i32 = args[1].parse().unwrap();
if level == 0 {{
let lib_path = std::env::var("{}").unwrap();
let paths: Vec<_> = std::env::split_paths(&lib_path).collect();
if paths.len() > 1 {{
// The first path will be prepended to the search path in the next run
let first = &paths[0];
assert!(paths[1..].contains(&first));
}}
return;
}}
let _ = Command::new(std::env!("CARGO"))
.arg("run")
.arg("--")
.arg((level - 1).to_string())
.status()
.unwrap();
}}
"#,
dylib_path_envvar(),
),
)
.build();

setenv_for_removing_empty_component(p.cargo("run -- 1"))
.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[EXE] 1`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/foo[EXE] 0`
"#]])
.run();
}

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

0 comments on commit 4abbeac

Please sign in to comment.