mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
tests/{readlink, realpath}: fix tests on Windows
I fixed the tests that assumed paths used a Unix directory separator.
This commit is contained in:
parent
c954b01aa3
commit
1fecba3226
3 changed files with 34 additions and 18 deletions
|
@ -49,6 +49,25 @@ macro_rules! assert_no_error(
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! path_concat {
|
||||||
|
($e:expr, ..$n:expr) => {{
|
||||||
|
let n = $n;
|
||||||
|
let mut pb = std::path::PathBuf::new();
|
||||||
|
for _ in 0..n {
|
||||||
|
pb.push($e);
|
||||||
|
}
|
||||||
|
pb.to_str().unwrap().to_owned()
|
||||||
|
}};
|
||||||
|
($($e:expr),*) => {{
|
||||||
|
let mut pb = std::path::PathBuf::new();
|
||||||
|
$(
|
||||||
|
pb.push($e);
|
||||||
|
)*
|
||||||
|
pb.to_str().unwrap().to_owned()
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CmdResult {
|
pub struct CmdResult {
|
||||||
pub success: bool,
|
pub success: bool,
|
||||||
pub stdout: String,
|
pub stdout: String,
|
||||||
|
@ -97,15 +116,6 @@ pub fn log_info<T: AsRef<str>, U: AsRef<str>>(msg: T, par: U) {
|
||||||
println!("{}: {}", msg.as_ref(), par.as_ref());
|
println!("{}: {}", msg.as_ref(), par.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn repeat_str(s: &str, n: u32) -> String {
|
|
||||||
let mut repeated = String::new();
|
|
||||||
for _ in 0..n {
|
|
||||||
repeated.push_str(s);
|
|
||||||
}
|
|
||||||
repeated
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> {
|
pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> {
|
||||||
if try!(fs::metadata(src)).is_dir() {
|
if try!(fs::metadata(src)).is_dir() {
|
||||||
for entry in try!(fs::read_dir(src)) {
|
for entry in try!(fs::read_dir(src)) {
|
||||||
|
@ -123,6 +133,14 @@ pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_root_path() -> &'static str {
|
||||||
|
if cfg!(windows) {
|
||||||
|
"C:\\"
|
||||||
|
} else {
|
||||||
|
"/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A scoped, temporary file that is removed upon drop.
|
/// A scoped, temporary file that is removed upon drop.
|
||||||
pub struct ScopedFile {
|
pub struct ScopedFile {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
|
|
|
@ -33,9 +33,7 @@ fn test_canonicalize_existing() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_canonicalize_missing() {
|
fn test_canonicalize_missing() {
|
||||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||||
let mut expected = at.root_dir_resolved();
|
let expected = path_concat!(at.root_dir_resolved(), GIBBERISH);
|
||||||
expected.push_str("/");
|
|
||||||
expected.push_str(GIBBERISH);
|
|
||||||
|
|
||||||
let out = ucmd.arg("-m")
|
let out = ucmd.arg("-m")
|
||||||
.arg(GIBBERISH)
|
.arg(GIBBERISH)
|
||||||
|
@ -49,7 +47,7 @@ fn test_canonicalize_missing() {
|
||||||
fn test_long_redirection_to_current_dir() {
|
fn test_long_redirection_to_current_dir() {
|
||||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||||
// Create a 256-character path to current directory
|
// Create a 256-character path to current directory
|
||||||
let dir = repeat_str("./", 128);
|
let dir = path_concat!(".", ..128);
|
||||||
let out = ucmd.arg("-n")
|
let out = ucmd.arg("-n")
|
||||||
.arg("-m")
|
.arg("-m")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
|
@ -63,12 +61,12 @@ fn test_long_redirection_to_current_dir() {
|
||||||
fn test_long_redirection_to_root() {
|
fn test_long_redirection_to_root() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||||
// Create a 255-character path to root
|
// Create a 255-character path to root
|
||||||
let dir = repeat_str("../", 85);
|
let dir = path_concat!("..", ..85);
|
||||||
let out = ucmd.arg("-n")
|
let out = ucmd.arg("-n")
|
||||||
.arg("-m")
|
.arg("-m")
|
||||||
.arg(dir)
|
.arg(dir)
|
||||||
.run()
|
.run()
|
||||||
.stdout;
|
.stdout;
|
||||||
|
|
||||||
assert_eq!(out, "/");
|
assert_eq!(out, get_root_path());
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn test_current_directory() {
|
||||||
fn test_long_redirection_to_current_dir() {
|
fn test_long_redirection_to_current_dir() {
|
||||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||||
// Create a 256-character path to current directory
|
// Create a 256-character path to current directory
|
||||||
let dir = repeat_str("./", 128);
|
let dir = path_concat!(".", ..128);
|
||||||
let out = ucmd.arg(dir).run().stdout;
|
let out = ucmd.arg(dir).run().stdout;
|
||||||
|
|
||||||
assert_eq!(out.trim_right(), at.root_dir_resolved());
|
assert_eq!(out.trim_right(), at.root_dir_resolved());
|
||||||
|
@ -27,8 +27,8 @@ fn test_long_redirection_to_current_dir() {
|
||||||
fn test_long_redirection_to_root() {
|
fn test_long_redirection_to_root() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||||
// Create a 255-character path to root
|
// Create a 255-character path to root
|
||||||
let dir = repeat_str("../", 85);
|
let dir = path_concat!("..", ..85);
|
||||||
let out = ucmd.arg(dir).run().stdout;
|
let out = ucmd.arg(dir).run().stdout;
|
||||||
|
|
||||||
assert_eq!(out.trim_right(), "/");
|
assert_eq!(out.trim_right(), get_root_path());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue