Skip to content

Commit

Permalink
Consolidate the 3 dangling symlink test functions
Browse files Browse the repository at this point in the history
This helps to clarify, rather than obscure, their similarities,
including the similarity between the old test case and the new ones
that cover dangling symlinks whose targets are unusually named.

For now, the associated fixtures remain separate.
  • Loading branch information
EliahKagan committed Jun 26, 2024
1 parent 55c635a commit 87422ab
Showing 1 changed file with 18 additions and 59 deletions.
77 changes: 18 additions & 59 deletions gix-worktree-state/tests/state/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,67 +303,26 @@ fn dangling_symlinks_can_be_created() -> crate::Result {
return Ok(());
}

let (_source_tree, destination, _index, outcome) =
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink", None)?;
let worktree_files = dir_structure(&destination);
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);

assert_eq!(worktree_files_stripped, paths(["dangling"]));
let symlink_path = &worktree_files[0];
assert!(symlink_path
.symlink_metadata()
.expect("dangling symlink is on disk")
.is_symlink());
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("non-existing-target"));
assert!(outcome.collisions.is_empty());
Ok(())
}

#[test]
fn dangling_symlink_to_windows_invalid_target_can_be_created() -> crate::Result {
let opts = opts_from_probe();
if !opts.fs.symlink {
eprintln!("Skipping dangling symlink test on filesystem that doesn't support it");
return Ok(());
}

let (_source_tree, destination, _index, outcome) =
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink_to_windows_invalid", None)?;
let worktree_files = dir_structure(&destination);
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);

assert_eq!(worktree_files_stripped, paths(["dangling-qmarks-symlink"]));
let symlink_path = &worktree_files[0];
assert!(symlink_path
.symlink_metadata()
.expect("dangling symlink is on disk")
.is_symlink());
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("???"));
assert!(outcome.collisions.is_empty());
Ok(())
}

#[test]
fn dangling_symlink_to_windows_reserved_target_can_be_created() -> crate::Result {
let opts = opts_from_probe();
if !opts.fs.symlink {
eprintln!("Skipping dangling symlink test on filesystem that doesn't support it");
return Ok(());
for (fixture, symlink_name, target_name) in [
("make_dangling_symlink", "dangling", "non-existing-target"),
("make_dangling_symlink_to_windows_invalid", "dangling-qmarks-symlink", "???"),
("make_dangling_symlink_to_windows_reserved", "dangling-con-symlink", "CON"),
] {
let (_source_tree, destination, _index, outcome) =
checkout_index_in_tmp_dir(opts.clone(), fixture, None)?;
let worktree_files = dir_structure(&destination);
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);

assert_eq!(worktree_files_stripped, paths([symlink_name]));
let symlink_path = &worktree_files[0];
assert!(symlink_path
.symlink_metadata()
.expect("dangling symlink is on disk")
.is_symlink());
assert_eq!(std::fs::read_link(symlink_path)?, Path::new(target_name));
assert!(outcome.collisions.is_empty());
}

let (_source_tree, destination, _index, outcome) =
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink_to_windows_reserved", None)?;
let worktree_files = dir_structure(&destination);
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);

assert_eq!(worktree_files_stripped, paths(["dangling-con-symlink"]));
let symlink_path = &worktree_files[0];
assert!(symlink_path
.symlink_metadata()
.expect("dangling symlink is on disk")
.is_symlink());
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("CON"));
assert!(outcome.collisions.is_empty());
Ok(())
}

Expand Down

0 comments on commit 87422ab

Please sign in to comment.