Skip to content

Commit 78f98d6

Browse files
committed
add test for cargo_home symlink duplicate load
1 parent a3b26d6 commit 78f98d6

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/testsuite/config.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,3 +2589,67 @@ fn mixed_type_array() {
25892589
}
25902590
);
25912591
}
2592+
2593+
#[cargo_test]
2594+
fn config_symlink_home_duplicate_load_bug() {
2595+
// Test that when CARGO_HOME is accessed via a symlink that points to a directory
2596+
// already in the config search path, the config file is not loaded twice.
2597+
2598+
use cargo_test_support::basic_manifest;
2599+
2600+
#[cfg(unix)]
2601+
use std::os::unix::fs::symlink;
2602+
2603+
#[cfg(windows)]
2604+
use std::os::windows::fs::symlink_dir as symlink;
2605+
2606+
let p = project()
2607+
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
2608+
.file("src/lib.rs", "")
2609+
.build();
2610+
2611+
// Create directory structure a/b/ and symlink c -> a
2612+
let a_dir = p.root().join("a");
2613+
let b_dir = a_dir.join("b");
2614+
let c_symlink = p.root().join("c");
2615+
2616+
fs::create_dir_all(&b_dir).unwrap();
2617+
symlink(&a_dir, &c_symlink).unwrap();
2618+
2619+
// Create config file in a/.cargo/
2620+
let cargo_config_dir = a_dir.join(".cargo");
2621+
fs::create_dir(&cargo_config_dir).unwrap();
2622+
let config_path = cargo_config_dir.join("config.toml");
2623+
fs::write(
2624+
&config_path,
2625+
r#"
2626+
[build]
2627+
rustdocflags = ["--default-theme=dark"]
2628+
"#,
2629+
)
2630+
.unwrap();
2631+
2632+
// Move the project into a/b/
2633+
let project_in_b = b_dir.join("foo");
2634+
fs::create_dir(&project_in_b).unwrap();
2635+
fs::write(
2636+
project_in_b.join("Cargo.toml"),
2637+
&basic_manifest("foo", "0.1.0"),
2638+
)
2639+
.unwrap();
2640+
fs::create_dir(project_in_b.join("src")).unwrap();
2641+
fs::write(project_in_b.join("src/lib.rs"), "").unwrap();
2642+
2643+
// Set CARGO_HOME to ../../c/.cargo (which is really a/.cargo via symlink)
2644+
let cargo_home = c_symlink.join(".cargo");
2645+
2646+
// If config is loaded twice, rustdocflags will be duplicated and cause an error
2647+
p.cargo("doc")
2648+
.cwd(&project_in_b)
2649+
.env("CARGO_HOME", &cargo_home)
2650+
.with_status(101)
2651+
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])")
2652+
.with_stderr_does_not_contain("duplicated key `rustdocflags`")
2653+
.run();
2654+
}
2655+

0 commit comments

Comments
 (0)