Skip to content

Commit 3498cfe

Browse files
test: Add failing test for cargo add breaking symlinks
This test demonstrates that cargo add replaces symlinked Cargo.toml files with regular files, breaking the symlink. The test currently fails as expected.
1 parent bffece8 commit 3498cfe

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/testsuite/cargo_add/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ mod script_bare;
150150
mod script_frontmatter;
151151
mod script_shebang;
152152
mod sorted_table_with_dotted_item;
153+
mod symlink;
153154
mod target;
154155
mod target_cfg;
155156
mod unknown_inherited_feature;

tests/testsuite/cargo_add/symlink.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use cargo_test_support::prelude::*;
2+
use cargo_test_support::project;
3+
use cargo_test_support::registry;
4+
use std::fs;
5+
6+
#[cargo_test]
7+
fn symlink_case() {
8+
if !cargo_test_support::symlink_supported() {
9+
return;
10+
}
11+
12+
registry::init();
13+
registry::Package::new("test-dep", "1.0.0").publish();
14+
15+
let project = project().file("src/lib.rs", "").build();
16+
17+
let target_dir = project.root().join("target_dir");
18+
fs::create_dir_all(&target_dir).unwrap();
19+
20+
fs::copy(
21+
project.root().join("Cargo.toml"),
22+
target_dir.join("Cargo.toml"),
23+
)
24+
.unwrap();
25+
26+
fs::remove_file(project.root().join("Cargo.toml")).unwrap();
27+
28+
#[cfg(unix)]
29+
{
30+
use std::os::unix::fs::symlink;
31+
symlink(
32+
target_dir.join("Cargo.toml"),
33+
project.root().join("Cargo.toml"),
34+
)
35+
.unwrap();
36+
}
37+
38+
#[cfg(windows)]
39+
{
40+
use std::os::windows::fs::symlink_file;
41+
symlink_file(
42+
target_dir.join("Cargo.toml"),
43+
project.root().join("Cargo.toml"),
44+
)
45+
.unwrap();
46+
}
47+
48+
project.cargo("add test-dep").run();
49+
50+
// This will FAIL because cargo add replaces the symlink with a regular file
51+
assert!(project.root().join("Cargo.toml").is_symlink());
52+
}

0 commit comments

Comments
 (0)