From da2e2081e3b242ad69ae41d2663e7b60e261a022 Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Sat, 7 Dec 2019 11:22:00 +0800 Subject: test: :art: fix clippy style and tests, add an inode test inode: :hammer: only get inode on unix, return 0 for windows --- src/meta/inode.rs | 6 +++--- tests/integration.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/meta/inode.rs b/src/meta/inode.rs index bf30273..d40edf5 100644 --- a/src/meta/inode.rs +++ b/src/meta/inode.rs @@ -13,12 +13,12 @@ impl<'a> From<&'a Metadata> for INode { let index = meta.ino(); - Self { index: index } + Self { index } } #[cfg(windows)] fn from(_: &Metadata) -> Self { - panic!("Cannot get inode on Windows") + Self { index: 0 } } } @@ -29,6 +29,7 @@ impl INode { } #[cfg(test)] +#[cfg(unix)] mod tests { use super::INode; use std::env; @@ -36,7 +37,6 @@ mod tests { use std::path::Path; use std::process::{Command, ExitStatus}; - #[cfg(unix)] fn cross_platform_touch(path: &Path) -> io::Result { Command::new("touch").arg(&path).status() } diff --git a/tests/integration.rs b/tests/integration.rs index d61487f..96ac61e 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -19,13 +19,34 @@ fn test_list_empty_directory() { .stdout(predicate::eq("")); } +#[test] +fn test_list_almost_all_empty_directory() { + cmd() + .arg("--almost-all") + .arg(tempdir().path()) + .assert() + .stdout(predicate::eq("")); + + cmd() + .arg("-A") + .arg(tempdir().path()) + .assert() + .stdout(predicate::eq("")); +} + #[test] fn test_list_all_empty_directory() { cmd() .arg("--all") .arg(tempdir().path()) .assert() - .stdout(predicate::eq(".\n..\n")); + .stdout(predicate::str::is_match(".* \\.\n.* \\.\\.\n$").unwrap()); + + cmd() + .arg("-a") + .arg(tempdir().path()) + .assert() + .stdout(predicate::str::is_match(".* \\.\n.* \\.\\.\n$").unwrap()); } #[test] @@ -36,7 +57,19 @@ fn test_list_populated_directory() { cmd() .arg(dir.path()) .assert() - .stdout(predicate::eq("one\ntwo\n")); + .stdout(predicate::str::is_match(".* one\n.* two\n$").unwrap()); +} + +#[test] +fn test_list_almost_all_populated_directory() { + let dir = tempdir(); + dir.child("one").touch().unwrap(); + dir.child("two").touch().unwrap(); + cmd() + .arg("--almost-all") + .arg(dir.path()) + .assert() + .stdout(predicate::str::is_match(".* one\n.* two\n$").unwrap()); } #[test] @@ -48,7 +81,21 @@ fn test_list_all_populated_directory() { .arg("--all") .arg(dir.path()) .assert() - .stdout(predicate::eq(".\n..\none\ntwo\n")); + .stdout(predicate::str::is_match(".* \\.\n.* \\.\\.\n.* one\n.* two\n$").unwrap()); +} + +#[test] +#[cfg(unix)] +fn test_list_inode_populated_directory() { + let dir = tempdir(); + dir.child("one").touch().unwrap(); + dir.child("two").touch().unwrap(); + cmd() + .arg("--blocks") + .arg("inode,name") + .arg(dir.path()) + .assert() + .stdout(predicate::str::is_match("\\d+ one\n\\d+ two\n$").unwrap()); } fn cmd() -> Command { -- cgit v1.2.3