mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
test: Add test demonstrating cargo add replaces symlinks
This test shows the current behavior where cargo add replaces symlinked Cargo.toml files with regular files. The test passes, documenting this problematic behavior.
This commit is contained in:
parent
6aa6f44048
commit
35d2a30a5c
@ -145,6 +145,7 @@ mod script_bare;
|
||||
mod script_frontmatter;
|
||||
mod script_shebang;
|
||||
mod sorted_table_with_dotted_item;
|
||||
mod symlink;
|
||||
mod target;
|
||||
mod target_cfg;
|
||||
mod unknown_inherited_feature;
|
||||
|
52
tests/testsuite/cargo_add/symlink.rs
Normal file
52
tests/testsuite/cargo_add/symlink.rs
Normal file
@ -0,0 +1,52 @@
|
||||
use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::project;
|
||||
use cargo_test_support::registry;
|
||||
use std::fs;
|
||||
|
||||
#[cargo_test]
|
||||
fn symlink_case() {
|
||||
if !cargo_test_support::symlink_supported() {
|
||||
return;
|
||||
}
|
||||
|
||||
registry::init();
|
||||
registry::Package::new("test-dep", "1.0.0").publish();
|
||||
|
||||
let project = project().file("src/lib.rs", "").build();
|
||||
|
||||
let target_dir = project.root().join("target_dir");
|
||||
fs::create_dir_all(&target_dir).unwrap();
|
||||
|
||||
fs::copy(
|
||||
project.root().join("Cargo.toml"),
|
||||
target_dir.join("Cargo.toml"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
fs::remove_file(project.root().join("Cargo.toml")).unwrap();
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::symlink;
|
||||
symlink(
|
||||
target_dir.join("Cargo.toml"),
|
||||
project.root().join("Cargo.toml"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use std::os::windows::fs::symlink_file;
|
||||
symlink_file(
|
||||
target_dir.join("Cargo.toml"),
|
||||
project.root().join("Cargo.toml"),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
project.cargo("add test-dep").run();
|
||||
|
||||
// Current behavior: symlink is NOT preserved (gets replaced)
|
||||
assert!(!project.root().join("Cargo.toml").is_symlink());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user