Skip to content

Commit

Permalink
Merge pull request uutils#3671 from niyaznigmatullin/fix_realpath_test
Browse files Browse the repository at this point in the history
test_realpath: fixed test to be the one that was supposed to be
  • Loading branch information
sylvestre committed Jul 6, 2022
2 parents 38f5a47 + 4e936d2 commit 43a5b8c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
26 changes: 24 additions & 2 deletions tests/by-util/test_realpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn test_realpath_when_symlink_is_absolute_and_enoent() {
at.mkdir("dir1");
at.symlink_file("dir2/bar", "dir1/foo1");
at.symlink_file("/dir2/bar", "dir1/foo2");
at.relative_symlink_file("dir2/baz", at.plus("dir1/foo3").to_str().unwrap());
at.relative_symlink_file("../dir2/baz", "dir1/foo3");

#[cfg(unix)]
ucmd.arg("dir1/foo1")
Expand All @@ -228,7 +228,7 @@ fn test_realpath_when_symlink_is_absolute_and_enoent() {
.run()
.stdout_contains("/dir2/bar\n")
.stdout_contains("/dir2/baz\n")
.stderr_is("realpath: dir1/foo2: No such file or directory");
.stderr_is("realpath: dir1/foo2: No such file or directory\n");

#[cfg(windows)]
ucmd.arg("dir1/foo1")
Expand All @@ -239,3 +239,25 @@ fn test_realpath_when_symlink_is_absolute_and_enoent() {
.stdout_contains("\\dir2\\baz\n")
.stderr_is("realpath: dir1/foo2: No such file or directory");
}

#[test]
#[ignore = "issue #3669"]
fn test_realpath_when_symlink_part_is_missing() {
let (at, mut ucmd) = at_and_ucmd!();

at.mkdir("dir2");
at.touch("dir2/bar");

at.mkdir("dir1");
at.relative_symlink_file("../dir2/bar", "dir1/foo1");
at.relative_symlink_file("dir2/bar", "dir1/foo2");
at.relative_symlink_file("../dir2/baz", "dir1/foo3");
at.symlink_file("dir3/bar", "dir1/foo4");

ucmd.args(&["dir1/foo1", "dir1/foo2", "dir1/foo3", "dir1/foo4"])
.run()
.stdout_contains(at.plus_as_string("dir2/bar") + "\n")
.stdout_contains(at.plus_as_string("dir2/baz") + "\n")
.stderr_contains("realpath: dir1/foo2: No such file or directory\n")
.stderr_contains("realpath: dir1/foo4: No such file or directory\n");
}
15 changes: 13 additions & 2 deletions tests/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,11 @@ impl AtPath {
}

pub fn relative_symlink_file(&self, original: &str, link: &str) {
log_info("symlink", &format!("{},{}", original, link));
symlink_file(original, link).unwrap();
log_info(
"symlink",
&format!("{},{}", original, &self.plus_as_string(link)),
);
symlink_file(original, &self.plus(link)).unwrap();
}

pub fn symlink_dir(&self, original: &str, link: &str) {
Expand All @@ -718,6 +721,14 @@ impl AtPath {
symlink_dir(&self.plus(original), &self.plus(link)).unwrap();
}

pub fn relative_symlink_dir(&self, original: &str, link: &str) {
log_info(
"symlink",
&format!("{},{}", original, &self.plus_as_string(link)),
);
symlink_dir(original, &self.plus(link)).unwrap();
}

pub fn is_symlink(&self, path: &str) -> bool {
log_info("is_symlink", self.plus_as_string(path));
match fs::symlink_metadata(&self.plus(path)) {
Expand Down

0 comments on commit 43a5b8c

Please sign in to comment.