summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzwPapEr <zw.paper@gmail.com>2019-12-07 11:22:00 +0800
committerAbin Simon <abinsimon10@gmail.com>2020-01-11 14:17:44 +0530
commitda2e2081e3b242ad69ae41d2663e7b60e261a022 (patch)
tree40212c257cfa12d79a837d55f4044e4ac9bc805d
parent0ebb39d60cc498cf92c09e8b3fa46316873941b6 (diff)
test: :art: fix clippy style and tests, add an inode test
inode: :hammer: only get inode on unix, return 0 for windows
-rw-r--r--src/meta/inode.rs6
-rw-r--r--tests/integration.rs53
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<ExitStatus> {
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
@@ -20,12 +20,33 @@ fn test_list_empty_directory() {
}
#[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 {