coreutils/tests/by-util/test_realpath.rs

109 lines
2.4 KiB
Rust
Raw Normal View History

use crate::common::util::*;
#[test]
2021-04-05 21:55:02 +00:00
fn test_realpath_current_directory() {
let (at, mut ucmd) = at_and_ucmd!();
let expect = at.root_dir_resolved() + "\n";
2021-04-05 21:55:02 +00:00
ucmd.arg(".").succeeds().stdout_is(expect);
}
#[test]
2021-04-05 21:55:02 +00:00
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";
2021-04-05 21:55:02 +00:00
ucmd.arg(dir).succeeds().stdout_is(expect);
}
#[test]
2021-04-05 21:55:02 +00:00
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";
2021-04-05 21:55:02 +00:00
new_ucmd!().arg(dir).succeeds().stdout_is(expect);
}
2021-01-19 11:38:36 +00:00
#[test]
2021-04-05 21:55:02 +00:00
fn test_realpath_file_and_links() {
2021-01-19 11:38:36 +00:00
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");
at.symlink_file("foo", "bar");
2021-04-05 21:55:02 +00:00
scene.ucmd().arg("foo").succeeds().stdout_contains("foo\n");
scene.ucmd().arg("bar").succeeds().stdout_contains("foo\n");
2021-01-19 11:38:36 +00:00
}
#[test]
2021-04-05 21:55:02 +00:00
fn test_realpath_file_and_links_zero() {
2021-01-19 11:38:36 +00:00
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");
at.symlink_file("foo", "bar");
2021-04-05 21:55:02 +00:00
scene
.ucmd()
.arg("foo")
.arg("-z")
.succeeds()
.stdout_contains("foo\u{0}");
scene
.ucmd()
.arg("bar")
.arg("-z")
.succeeds()
.stdout_contains("foo\u{0}");
2021-01-19 11:38:36 +00:00
}
#[test]
2021-04-05 21:55:02 +00:00
fn test_realpath_file_and_links_strip() {
2021-01-19 11:38:36 +00:00
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");
at.symlink_file("foo", "bar");
2021-04-05 21:55:02 +00:00
scene
.ucmd()
.arg("foo")
.arg("-s")
.succeeds()
.stdout_contains("foo\n");
scene
.ucmd()
.arg("bar")
.arg("-s")
.succeeds()
.stdout_contains("bar\n");
2021-01-19 11:38:36 +00:00
}
#[test]
2021-04-05 21:55:02 +00:00
fn test_realpath_file_and_links_strip_zero() {
2021-01-19 11:38:36 +00:00
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");
at.symlink_file("foo", "bar");
2021-04-05 21:55:02 +00:00
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}");
2021-01-19 11:38:36 +00:00
}