Skip to content

Commit 26bd6b5

Browse files
test: Add failing test for cargo add breaking symlinks
1 parent 662213b commit 26bd6b5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/testsuite/cargo_add/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ mod script_bare;
145145
mod script_frontmatter;
146146
mod script_shebang;
147147
mod sorted_table_with_dotted_item;
148+
mod symlink;
148149
mod target;
149150
mod target_cfg;
150151
mod unknown_inherited_feature;

tests/testsuite/cargo_add/symlink.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
assert!(project.root().join("Cargo.toml").is_symlink());
51+
}

0 commit comments

Comments
 (0)