Skip to content

Commit 87422ab

Browse files
committed
Consolidate the 3 dangling symlink test functions
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.
1 parent 55c635a commit 87422ab

File tree

1 file changed

+18
-59
lines changed

1 file changed

+18
-59
lines changed

gix-worktree-state/tests/state/checkout.rs

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -303,67 +303,26 @@ fn dangling_symlinks_can_be_created() -> crate::Result {
303303
return Ok(());
304304
}
305305

306-
let (_source_tree, destination, _index, outcome) =
307-
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink", None)?;
308-
let worktree_files = dir_structure(&destination);
309-
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);
310-
311-
assert_eq!(worktree_files_stripped, paths(["dangling"]));
312-
let symlink_path = &worktree_files[0];
313-
assert!(symlink_path
314-
.symlink_metadata()
315-
.expect("dangling symlink is on disk")
316-
.is_symlink());
317-
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("non-existing-target"));
318-
assert!(outcome.collisions.is_empty());
319-
Ok(())
320-
}
321-
322-
#[test]
323-
fn dangling_symlink_to_windows_invalid_target_can_be_created() -> crate::Result {
324-
let opts = opts_from_probe();
325-
if !opts.fs.symlink {
326-
eprintln!("Skipping dangling symlink test on filesystem that doesn't support it");
327-
return Ok(());
328-
}
329-
330-
let (_source_tree, destination, _index, outcome) =
331-
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink_to_windows_invalid", None)?;
332-
let worktree_files = dir_structure(&destination);
333-
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);
334-
335-
assert_eq!(worktree_files_stripped, paths(["dangling-qmarks-symlink"]));
336-
let symlink_path = &worktree_files[0];
337-
assert!(symlink_path
338-
.symlink_metadata()
339-
.expect("dangling symlink is on disk")
340-
.is_symlink());
341-
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("???"));
342-
assert!(outcome.collisions.is_empty());
343-
Ok(())
344-
}
345-
346-
#[test]
347-
fn dangling_symlink_to_windows_reserved_target_can_be_created() -> crate::Result {
348-
let opts = opts_from_probe();
349-
if !opts.fs.symlink {
350-
eprintln!("Skipping dangling symlink test on filesystem that doesn't support it");
351-
return Ok(());
306+
for (fixture, symlink_name, target_name) in [
307+
("make_dangling_symlink", "dangling", "non-existing-target"),
308+
("make_dangling_symlink_to_windows_invalid", "dangling-qmarks-symlink", "???"),
309+
("make_dangling_symlink_to_windows_reserved", "dangling-con-symlink", "CON"),
310+
] {
311+
let (_source_tree, destination, _index, outcome) =
312+
checkout_index_in_tmp_dir(opts.clone(), fixture, None)?;
313+
let worktree_files = dir_structure(&destination);
314+
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);
315+
316+
assert_eq!(worktree_files_stripped, paths([symlink_name]));
317+
let symlink_path = &worktree_files[0];
318+
assert!(symlink_path
319+
.symlink_metadata()
320+
.expect("dangling symlink is on disk")
321+
.is_symlink());
322+
assert_eq!(std::fs::read_link(symlink_path)?, Path::new(target_name));
323+
assert!(outcome.collisions.is_empty());
352324
}
353325

354-
let (_source_tree, destination, _index, outcome) =
355-
checkout_index_in_tmp_dir(opts.clone(), "make_dangling_symlink_to_windows_reserved", None)?;
356-
let worktree_files = dir_structure(&destination);
357-
let worktree_files_stripped = stripped_prefix(&destination, &worktree_files);
358-
359-
assert_eq!(worktree_files_stripped, paths(["dangling-con-symlink"]));
360-
let symlink_path = &worktree_files[0];
361-
assert!(symlink_path
362-
.symlink_metadata()
363-
.expect("dangling symlink is on disk")
364-
.is_symlink());
365-
assert_eq!(std::fs::read_link(symlink_path)?, Path::new("CON"));
366-
assert!(outcome.collisions.is_empty());
367326
Ok(())
368327
}
369328

0 commit comments

Comments
 (0)