2019-10-05 20:08:45 +00:00
|
|
|
extern crate assert_cmd;
|
|
|
|
extern crate predicates;
|
|
|
|
|
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use assert_fs::prelude::*;
|
|
|
|
use predicates::prelude::*;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_runs_okay() {
|
|
|
|
cmd().assert().success();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_list_empty_directory() {
|
|
|
|
cmd()
|
|
|
|
.arg(tempdir().path())
|
|
|
|
.assert()
|
|
|
|
.stdout(predicate::eq(""));
|
|
|
|
}
|
|
|
|
|
2019-12-07 03:22:00 +00:00
|
|
|
#[test]
|
|
|
|
fn test_list_almost_all_empty_directory() {
|
2019-12-12 04:28:50 +00:00
|
|
|
let matched = "";
|
2019-12-07 03:22:00 +00:00
|
|
|
cmd()
|
|
|
|
.arg("--almost-all")
|
|
|
|
.arg(tempdir().path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::eq(matched));
|
2019-12-07 03:22:00 +00:00
|
|
|
|
|
|
|
cmd()
|
|
|
|
.arg("-A")
|
|
|
|
.arg(tempdir().path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::eq(matched));
|
2019-12-07 03:22:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 20:08:45 +00:00
|
|
|
#[test]
|
|
|
|
fn test_list_all_empty_directory() {
|
2019-12-12 04:28:50 +00:00
|
|
|
let matched = "\\.\n\\.\\.\n$";
|
2019-10-05 20:08:45 +00:00
|
|
|
cmd()
|
|
|
|
.arg("--all")
|
|
|
|
.arg(tempdir().path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::str::is_match(matched).unwrap());
|
2019-12-07 03:22:00 +00:00
|
|
|
|
|
|
|
cmd()
|
|
|
|
.arg("-a")
|
|
|
|
.arg(tempdir().path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::str::is_match(matched).unwrap());
|
2019-10-05 20:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_list_populated_directory() {
|
|
|
|
let dir = tempdir();
|
|
|
|
dir.child("one").touch().unwrap();
|
|
|
|
dir.child("two").touch().unwrap();
|
|
|
|
cmd()
|
|
|
|
.arg(dir.path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::str::is_match("one\ntwo\n$").unwrap());
|
2019-12-07 03:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::str::is_match("one\ntwo\n$").unwrap());
|
2019-10-05 20:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_list_all_populated_directory() {
|
|
|
|
let dir = tempdir();
|
|
|
|
dir.child("one").touch().unwrap();
|
|
|
|
dir.child("two").touch().unwrap();
|
|
|
|
cmd()
|
|
|
|
.arg("--all")
|
|
|
|
.arg(dir.path())
|
|
|
|
.assert()
|
2019-12-12 04:28:50 +00:00
|
|
|
.stdout(predicate::str::is_match("\\.\n\\.\\.\none\ntwo\n$").unwrap());
|
2019-12-07 03:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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());
|
2019-10-05 20:08:45 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 04:28:50 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg(windows)]
|
|
|
|
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("- one\n\\- two\n$").unwrap());
|
|
|
|
}
|
|
|
|
|
2019-10-05 20:08:45 +00:00
|
|
|
fn cmd() -> Command {
|
|
|
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tempdir() -> assert_fs::TempDir {
|
|
|
|
assert_fs::TempDir::new().unwrap()
|
|
|
|
}
|