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 success: bool,
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
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<()> {
|
||||
if try!(fs::metadata(src)).is_dir() {
|
||||
for entry in try!(fs::read_dir(src)) {
|
||||
|
@ -123,6 +133,14 @@ pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_root_path() -> &'static str {
|
||||
if cfg!(windows) {
|
||||
"C:\\"
|
||||
} else {
|
||||
"/"
|
||||
}
|
||||
}
|
||||
|
||||
/// A scoped, temporary file that is removed upon drop.
|
||||
pub struct ScopedFile {
|
||||
path: PathBuf,
|
||||
|
|
|
@ -33,9 +33,7 @@ fn test_canonicalize_existing() {
|
|||
#[test]
|
||||
fn test_canonicalize_missing() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let mut expected = at.root_dir_resolved();
|
||||
expected.push_str("/");
|
||||
expected.push_str(GIBBERISH);
|
||||
let expected = path_concat!(at.root_dir_resolved(), GIBBERISH);
|
||||
|
||||
let out = ucmd.arg("-m")
|
||||
.arg(GIBBERISH)
|
||||
|
@ -49,7 +47,7 @@ fn test_canonicalize_missing() {
|
|||
fn test_long_redirection_to_current_dir() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
// Create a 256-character path to current directory
|
||||
let dir = repeat_str("./", 128);
|
||||
let dir = path_concat!(".", ..128);
|
||||
let out = ucmd.arg("-n")
|
||||
.arg("-m")
|
||||
.arg(dir)
|
||||
|
@ -63,12 +61,12 @@ fn test_long_redirection_to_current_dir() {
|
|||
fn test_long_redirection_to_root() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
// Create a 255-character path to root
|
||||
let dir = repeat_str("../", 85);
|
||||
let dir = path_concat!("..", ..85);
|
||||
let out = ucmd.arg("-n")
|
||||
.arg("-m")
|
||||
.arg(dir)
|
||||
.run()
|
||||
.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() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
// 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;
|
||||
|
||||
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() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
// Create a 255-character path to root
|
||||
let dir = repeat_str("../", 85);
|
||||
let dir = path_concat!("..", ..85);
|
||||
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