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
Provenance
- Commit
06434f2- Tree
4e10abe- Author
Tom Milligan <tom@reinfer.io>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
0f2429c
2 files changed+32 added−2 removed
modified:tests/testenv/mod.rs+19 added
160 unmodified lines161 normalize_line: normalize,162 }163 }164 165+ /// 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+ }183+184 /// 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 linesmodified:tests/tests.rs+13 added-2 removed
596 unmodified lines597 "",598 );599 }600 601+#[test]602+fn 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.");606+607+ te.assert_output(&["--follow", "--type", "f", "symlink"], "broken_symlink");608+}609+610 /// Null separator (--print0)611 #[test]612 fn test_print0() {613 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);272 unmodified lines886 887 /// Symlink as search directory888 #[test]889 fn 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.");893 894 // 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 that12 unmodified lines909 "symlink",910 &["", parent_parent],911 &format!(912 "{dir}/a.foo913+ {dir}/broken_symlink914 {dir}/e1 e2915 {dir}/one916 {dir}/one/b.foo917 {dir}/one/two83 unmodified lines1001 abs_path = &abs_path1002 ),1003 );1004 }993-1005 /// Exclude patterns (--exclude)1006 #[test]1007 fn test_excludes() {1008 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);447 unmodified lines