1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

relpath: refactor tests for #1982

This commit is contained in:
Jan Scheer 2021-04-05 21:48:39 +02:00
parent bd8b129d9a
commit 4dfbbecc26

View file

@ -70,10 +70,10 @@ fn convert_path<'a>(path: &'a str) -> Cow<'a, str> {
#[test] #[test]
fn test_relpath_with_from_no_d() { fn test_relpath_with_from_no_d() {
for test in TESTS.iter() { let scene = TestScenario::new(util_name!());
let scene = TestScenario::new(util_name!()); let at = &scene.fixtures;
let at = &scene.fixtures;
for test in TESTS.iter() {
let from: &str = &convert_path(test.from); let from: &str = &convert_path(test.from);
let to: &str = &convert_path(test.to); let to: &str = &convert_path(test.to);
let expected: &str = &convert_path(test.expected); let expected: &str = &convert_path(test.expected);
@ -92,10 +92,10 @@ fn test_relpath_with_from_no_d() {
#[test] #[test]
fn test_relpath_with_from_with_d() { fn test_relpath_with_from_with_d() {
for test in TESTS.iter() { let scene = TestScenario::new(util_name!());
let scene = TestScenario::new(util_name!()); let at = &scene.fixtures;
let at = &scene.fixtures;
for test in TESTS.iter() {
let from: &str = &convert_path(test.from); let from: &str = &convert_path(test.from);
let to: &str = &convert_path(test.to); let to: &str = &convert_path(test.to);
let pwd = at.as_string(); let pwd = at.as_string();
@ -103,63 +103,75 @@ fn test_relpath_with_from_with_d() {
at.mkdir_all(from); at.mkdir_all(from);
// d is part of subpath -> expect relative path // d is part of subpath -> expect relative path
let mut result = scene let mut result_stdout = scene
.ucmd() .ucmd()
.arg(to) .arg(to)
.arg(from) .arg(from)
.arg(&format!("-d{}", pwd)) .arg(&format!("-d{}", pwd))
.run(); .succeeds()
assert!(result.success); .stdout_move_str();
// relax rules for windows test environment // relax rules for windows test environment
#[cfg(not(windows))] #[cfg(not(windows))]
assert!(Path::new(&result.stdout).is_relative()); assert!(Path::new(&result_stdout).is_relative());
// d is not part of subpath -> expect absolut path // d is not part of subpath -> expect absolut path
result = scene.ucmd().arg(to).arg(from).arg("-dnon_existing").run(); result_stdout = scene
assert!(result.success); .ucmd()
assert!(Path::new(&result.stdout).is_absolute()); .arg(to)
.arg(from)
.arg("-dnon_existing")
.succeeds()
.stdout_move_str();
assert!(Path::new(&result_stdout).is_absolute());
} }
} }
#[test] #[test]
fn test_relpath_no_from_no_d() { fn test_relpath_no_from_no_d() {
for test in TESTS.iter() { let scene = TestScenario::new(util_name!());
let scene = TestScenario::new(util_name!()); let at = &scene.fixtures;
let at = &scene.fixtures;
for test in TESTS.iter() {
let to: &str = &convert_path(test.to); let to: &str = &convert_path(test.to);
at.mkdir_all(to); at.mkdir_all(to);
let result = scene.ucmd().arg(to).run(); let result_stdout = scene.ucmd().arg(to).succeeds().stdout_move_str();
assert!(result.success);
#[cfg(not(windows))] #[cfg(not(windows))]
assert_eq!(result.stdout, format!("{}\n", to)); assert_eq!(result_stdout, format!("{}\n", to));
// relax rules for windows test environment // relax rules for windows test environment
#[cfg(windows)] #[cfg(windows)]
assert!(result.stdout.ends_with(&format!("{}\n", to))); assert!(result_stdout.ends_with(&format!("{}\n", to)));
} }
} }
#[test] #[test]
fn test_relpath_no_from_with_d() { fn test_relpath_no_from_with_d() {
for test in TESTS.iter() { let scene = TestScenario::new(util_name!());
let scene = TestScenario::new(util_name!()); let at = &scene.fixtures;
let at = &scene.fixtures;
for test in TESTS.iter() {
let to: &str = &convert_path(test.to); let to: &str = &convert_path(test.to);
let pwd = at.as_string(); let pwd = at.as_string();
at.mkdir_all(to); at.mkdir_all(to);
// d is part of subpath -> expect relative path // d is part of subpath -> expect relative path
let mut result = scene.ucmd().arg(to).arg(&format!("-d{}", pwd)).run(); let mut result_stdout = scene
assert!(result.success); .ucmd()
.arg(to)
.arg(&format!("-d{}", pwd))
.succeeds()
.stdout_move_str();
// relax rules for windows test environment // relax rules for windows test environment
#[cfg(not(windows))] #[cfg(not(windows))]
assert!(Path::new(&result.stdout).is_relative()); assert!(Path::new(&result_stdout).is_relative());
// d is not part of subpath -> expect absolut path // d is not part of subpath -> expect absolut path
result = scene.ucmd().arg(to).arg("-dnon_existing").run(); result_stdout = scene
assert!(result.success); .ucmd()
assert!(Path::new(&result.stdout).is_absolute()); .arg(to)
.arg("-dnon_existing")
.succeeds()
.stdout_move_str();
assert!(Path::new(&result_stdout).is_absolute());
} }
} }