From 27a980c1bc0fb424d41803714c3a9041b4a5d830 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 10 Oct 2016 19:34:57 -0400 Subject: Fix symlink test. We attempt to run it on Windows, but I'm getting "access denied" errors when trying to create a file symlink. So we disable the test on Windows. --- tests/tests.rs | 12 ++++++++---- tests/workdir.rs | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 965d37a3..f78feb72 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -542,7 +542,7 @@ sherlock!(symlink_nofollow, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| { wd.remove("sherlock"); wd.create_dir("foo"); wd.create_dir("foo/bar"); - wd.link("foo/baz", "foo/bar/baz"); + wd.link_dir("foo/baz", "foo/bar/baz"); wd.create_dir("foo/baz"); wd.create("foo/baz/sherlock", hay::SHERLOCK); cmd.current_dir(wd.path().join("foo/bar")); @@ -555,7 +555,7 @@ sherlock!(symlink_follow, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| { wd.create_dir("foo/bar"); wd.create_dir("foo/baz"); wd.create("foo/baz/sherlock", hay::SHERLOCK); - wd.link("foo/baz", "foo/bar/baz"); + wd.link_dir("foo/baz", "foo/bar/baz"); cmd.arg("-L"); cmd.current_dir(wd.path().join("foo/bar")); @@ -783,9 +783,13 @@ clean!(regression_131, "test", ".", |wd: WorkDir, mut cmd: Command| { }); // See: https://github.com/BurntSushi/ripgrep/issues/137 +// +// TODO(burntsushi): Figure out why Windows gives "access denied" errors +// when trying to create a file symlink. For now, disable test on Windows. +#[cfg(not(windows))] sherlock!(regression_137, "Sherlock", ".", |wd: WorkDir, mut cmd: Command| { - wd.link("sherlock", "sym1"); - wd.link("sherlock", "sym2"); + wd.link_file("sherlock", "sym1"); + wd.link_file("sherlock", "sym2"); cmd.arg("sym1"); cmd.arg("sym2"); cmd.arg("-j1"); diff --git a/tests/workdir.rs b/tests/workdir.rs index 89b2da1d..6a79daf7 100644 --- a/tests/workdir.rs +++ b/tests/workdir.rs @@ -83,7 +83,7 @@ impl WorkDir { /// Creates a directory symlink to the src with the given target name /// in this directory. #[cfg(not(windows))] - pub fn link, T: AsRef>(&self, src: S, target: T) { + pub fn link_dir, T: AsRef>(&self, src: S, target: T) { use std::os::unix::fs::symlink; let src = self.dir.join(src); let target = self.dir.join(target); @@ -91,8 +91,10 @@ impl WorkDir { nice_err(&target, symlink(&src, &target)); } + /// Creates a directory symlink to the src with the given target name + /// in this directory. #[cfg(windows)] - pub fn link, T: AsRef>(&self, src: S, target: T) { + pub fn link_dir, T: AsRef>(&self, src: S, target: T) { use std::os::windows::fs::symlink_dir; let src = self.dir.join(src); let target = self.dir.join(target); @@ -100,6 +102,32 @@ impl WorkDir { nice_err(&target, symlink_dir(&src, &target)); } + /// Creates a file symlink to the src with the given target name + /// in this directory. + #[cfg(not(windows))] + pub fn link_file, T: AsRef>( + &self, + src: S, + target: T, + ) { + self.link_dir(src, target); + } + + /// Creates a file symlink to the src with the given target name + /// in this directory. + #[cfg(windows)] + pub fn link_file, T: AsRef>( + &self, + src: S, + target: T, + ) { + use std::os::windows::fs::symlink_file; + let src = self.dir.join(src); + let target = self.dir.join(target); + let _ = fs::remove_file(&target); + nice_err(&target, symlink_file(&src, &target)); + } + /// Runs and captures the stdout of the given command. /// /// If the return type could not be created from a string, then this -- cgit v1.2.3