Skip to content
Myr

test: we should find broken symlink with and without --follow

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Milligan · committed by David Peter · parent 0f2429c · Browse files · 2 files+32 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+32 added−2 removed

  • tests:+32 added−2 removed

2 files+32 added−2 removed

modified:tests/testenv/mod.rs+19 added
160 unmodified lines
161 normalize_line: normalize,162 }163 }164165 /// Create a broken symlink at the given path in the temp_dir.166 pub fn create_broken_symlink<P: AsRef<Path>>(167 &mut self,168 link_path: P,169 ) -> Result<PathBuf, io::Error> {170 let root = self.test_root();171 let broken_symlink_link = root.join(link_path);172 {173 let temp_target_dir = TempDir::new("fd-tests-broken-symlink")?;174 let broken_symlink_target = temp_target_dir.path().join("broken_symlink_target");175 fs::File::create(&broken_symlink_target)?;176 #[cfg(unix)]177 unix::fs::symlink(&broken_symlink_target, &broken_symlink_link)?;178 #[cfg(windows)]179 windows::fs::symlink_file(&broken_symlink_target, &broken_symlink_link)?;180 }181 Ok(broken_symlink_link)182 }183184 /// Get the root directory for the tests.185 pub fn test_root(&self) -> PathBuf {186 self.temp_dir.path().to_path_buf()187 }
75 unmodified lines
modified:tests/tests.rs+13 added-2 removed
596 unmodified lines
597 "",598 );599}600601#[test]602fn test_follow_broken_symlink() {603 let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);604 te.create_broken_symlink("broken_symlink")605 .expect("Failed to create broken symlink.");606607 te.assert_output(&["--follow", "--type", "f", "symlink"], "broken_symlink");608}609610/// Null separator (--print0)611#[test]612fn test_print0() {613 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
272 unmodified lines
886887/// Symlink as search directory888#[test]889fn test_symlink_as_root() {881 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);890 let mut te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);891 te.create_broken_symlink("broken_symlink")892 .expect("Failed to create broken symlink.");893894 // From: http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html895 // The getcwd() function shall place an absolute pathname of the current working directory in896 // the array pointed to by buf, and return buf. The pathname shall contain no components that
12 unmodified lines
909 "symlink",910 &["", parent_parent],911 &format!(912 "{dir}/a.foo913 {dir}/broken_symlink914 {dir}/e1 e2915 {dir}/one916 {dir}/one/b.foo917 {dir}/one/two
83 unmodified lines
1001 abs_path = &abs_path1002 ),1003 );1004}9931005/// Exclude patterns (--exclude)1006#[test]1007fn test_excludes() {1008 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);
447 unmodified lines