mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
0e04f959c2
This adds the 'Physical Mode' and 'Logical Mode' switches to realpath, which control when symlinks are resolved.
141 lines
3 KiB
Rust
141 lines
3 KiB
Rust
use crate::common::util::*;
|
|
|
|
#[test]
|
|
fn test_realpath_current_directory() {
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
let expect = at.root_dir_resolved() + "\n";
|
|
ucmd.arg(".").succeeds().stdout_is(expect);
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_long_redirection_to_current_dir() {
|
|
let (at, mut ucmd) = at_and_ucmd!();
|
|
// Create a 256-character path to current directory
|
|
let dir = path_concat!(".", ..128);
|
|
let expect = at.root_dir_resolved() + "\n";
|
|
ucmd.arg(dir).succeeds().stdout_is(expect);
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_long_redirection_to_root() {
|
|
// Create a 255-character path to root
|
|
let dir = path_concat!("..", ..85);
|
|
let expect = get_root_path().to_owned() + "\n";
|
|
new_ucmd!().arg(dir).succeeds().stdout_is(expect);
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_file_and_links() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.touch("foo");
|
|
at.symlink_file("foo", "bar");
|
|
|
|
scene.ucmd().arg("foo").succeeds().stdout_contains("foo\n");
|
|
scene.ucmd().arg("bar").succeeds().stdout_contains("foo\n");
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_file_and_links_zero() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.touch("foo");
|
|
at.symlink_file("foo", "bar");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("foo")
|
|
.arg("-z")
|
|
.succeeds()
|
|
.stdout_contains("foo\u{0}");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("bar")
|
|
.arg("-z")
|
|
.succeeds()
|
|
.stdout_contains("foo\u{0}");
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_file_and_links_strip() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.touch("foo");
|
|
at.symlink_file("foo", "bar");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("foo")
|
|
.arg("-s")
|
|
.succeeds()
|
|
.stdout_contains("foo\n");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("bar")
|
|
.arg("-s")
|
|
.succeeds()
|
|
.stdout_contains("bar\n");
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_file_and_links_strip_zero() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.touch("foo");
|
|
at.symlink_file("foo", "bar");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("foo")
|
|
.arg("-s")
|
|
.arg("-z")
|
|
.succeeds()
|
|
.stdout_contains("foo\u{0}");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("bar")
|
|
.arg("-s")
|
|
.arg("-z")
|
|
.succeeds()
|
|
.stdout_contains("bar\u{0}");
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_physical_mode() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.mkdir("dir1");
|
|
at.mkdir_all("dir2/bar");
|
|
at.symlink_dir("dir2/bar", "dir1/foo");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("dir1/foo/..")
|
|
.succeeds()
|
|
.stdout_contains("dir2\n");
|
|
}
|
|
|
|
#[test]
|
|
fn test_realpath_logical_mode() {
|
|
let scene = TestScenario::new(util_name!());
|
|
let at = &scene.fixtures;
|
|
|
|
at.mkdir("dir1");
|
|
at.mkdir("dir2");
|
|
at.symlink_dir("dir2", "dir1/foo");
|
|
|
|
scene
|
|
.ucmd()
|
|
.arg("-L")
|
|
.arg("dir1/foo/..")
|
|
.succeeds()
|
|
.stdout_contains("dir1\n");
|
|
}
|