mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
realpath: refactor tests for #1982
This commit is contained in:
parent
de757cb025
commit
cc30aead22
1 changed files with 50 additions and 48 deletions
|
@ -1,106 +1,108 @@
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_current_directory() {
|
fn test_realpath_current_directory() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let actual = ucmd.arg(".").run().stdout;
|
|
||||||
let expect = at.root_dir_resolved() + "\n";
|
let expect = at.root_dir_resolved() + "\n";
|
||||||
println!("actual: {:?}", actual);
|
ucmd.arg(".").succeeds().stdout_is(expect);
|
||||||
println!("expect: {:?}", expect);
|
|
||||||
assert_eq!(actual, expect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_long_redirection_to_current_dir() {
|
fn test_realpath_long_redirection_to_current_dir() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
// Create a 256-character path to current directory
|
// Create a 256-character path to current directory
|
||||||
let dir = path_concat!(".", ..128);
|
let dir = path_concat!(".", ..128);
|
||||||
let actual = ucmd.arg(dir).run().stdout;
|
|
||||||
let expect = at.root_dir_resolved() + "\n";
|
let expect = at.root_dir_resolved() + "\n";
|
||||||
println!("actual: {:?}", actual);
|
ucmd.arg(dir).succeeds().stdout_is(expect);
|
||||||
println!("expect: {:?}", expect);
|
|
||||||
assert_eq!(actual, expect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_long_redirection_to_root() {
|
fn test_realpath_long_redirection_to_root() {
|
||||||
// Create a 255-character path to root
|
// Create a 255-character path to root
|
||||||
let dir = path_concat!("..", ..85);
|
let dir = path_concat!("..", ..85);
|
||||||
let actual = new_ucmd!().arg(dir).run().stdout;
|
|
||||||
let expect = get_root_path().to_owned() + "\n";
|
let expect = get_root_path().to_owned() + "\n";
|
||||||
println!("actual: {:?}", actual);
|
new_ucmd!().arg(dir).succeeds().stdout_is(expect);
|
||||||
println!("expect: {:?}", expect);
|
|
||||||
assert_eq!(actual, expect);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_and_links() {
|
fn test_realpath_file_and_links() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
at.touch("foo");
|
at.touch("foo");
|
||||||
at.symlink_file("foo", "bar");
|
at.symlink_file("foo", "bar");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("foo").run().stdout;
|
scene.ucmd().arg("foo").succeeds().stdout_contains("foo\n");
|
||||||
println!("actual: {:?}", actual);
|
scene.ucmd().arg("bar").succeeds().stdout_contains("foo\n");
|
||||||
assert!(actual.contains("foo\n"));
|
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("bar").run().stdout;
|
|
||||||
println!("actual: {:?}", actual);
|
|
||||||
assert!(actual.contains("foo\n"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_and_links_zero() {
|
fn test_realpath_file_and_links_zero() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
at.touch("foo");
|
at.touch("foo");
|
||||||
at.symlink_file("foo", "bar");
|
at.symlink_file("foo", "bar");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("foo").arg("-z").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("foo"));
|
.arg("foo")
|
||||||
assert!(!actual.contains("\n"));
|
.arg("-z")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo\u{0}");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("bar").arg("-z").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("foo"));
|
.arg("bar")
|
||||||
assert!(!actual.contains("\n"));
|
.arg("-z")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo\u{0}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_and_links_strip() {
|
fn test_realpath_file_and_links_strip() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
at.touch("foo");
|
at.touch("foo");
|
||||||
at.symlink_file("foo", "bar");
|
at.symlink_file("foo", "bar");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("foo").arg("-s").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("foo\n"));
|
.arg("foo")
|
||||||
|
.arg("-s")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo\n");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("bar").arg("-s").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("bar\n"));
|
.arg("bar")
|
||||||
|
.arg("-s")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("bar\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_and_links_strip_zero() {
|
fn test_realpath_file_and_links_strip_zero() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
let at = &scene.fixtures;
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
at.touch("foo");
|
at.touch("foo");
|
||||||
at.symlink_file("foo", "bar");
|
at.symlink_file("foo", "bar");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("foo").arg("-s").arg("-z").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("foo"));
|
.arg("foo")
|
||||||
assert!(!actual.contains("\n"));
|
.arg("-s")
|
||||||
|
.arg("-z")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("foo\u{0}");
|
||||||
|
|
||||||
let actual = scene.ucmd().arg("bar").arg("-s").arg("-z").run().stdout;
|
scene
|
||||||
println!("actual: {:?}", actual);
|
.ucmd()
|
||||||
assert!(actual.contains("bar"));
|
.arg("bar")
|
||||||
assert!(!actual.contains("\n"));
|
.arg("-s")
|
||||||
|
.arg("-z")
|
||||||
|
.succeeds()
|
||||||
|
.stdout_contains("bar\u{0}");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue