mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
test(ls): add more ls tests
This commit is contained in:
parent
ef25a6874e
commit
2de9abf52b
1 changed files with 211 additions and 9 deletions
|
@ -1,16 +1,211 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
extern crate regex;
|
||||
use self::regex::Regex;
|
||||
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
#[cfg(not(windows))]
|
||||
use self::libc::umask;
|
||||
#[cfg(not(windows))]
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
lazy_static! {
|
||||
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ls() {
|
||||
new_ucmd!().succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ls_i() {
|
||||
fn test_ls_i() {
|
||||
new_ucmd!().arg("-i").succeeds();
|
||||
new_ucmd!().arg("-il").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_a() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.touch(".test-1");
|
||||
|
||||
let result = scene.ucmd().run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
assert!(!result.stdout.contains(".test-1"));
|
||||
assert!(!result.stdout.contains(".."));
|
||||
|
||||
let result = scene.ucmd().arg("-a").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
assert!(result.stdout.contains(".test-1"));
|
||||
assert!(result.stdout.contains(".."));
|
||||
|
||||
let result = scene.ucmd().arg("-A").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
assert!(result.stdout.contains(".test-1"));
|
||||
assert!(!result.stdout.contains(".."));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_long() {
|
||||
#[cfg(not(windows))]
|
||||
let mut last;
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _guard = UMASK_MUTEX.lock();
|
||||
last = unsafe { umask(0) };
|
||||
|
||||
unsafe {
|
||||
umask(0o002);
|
||||
}
|
||||
}
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch(&at.plus_as_string("test-long"));
|
||||
let result = ucmd.arg("-l").arg("test-long").succeeds();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
#[cfg(not(windows))]
|
||||
assert!(result.stdout.contains("-rw-rw-r--"));
|
||||
|
||||
#[cfg(windows)]
|
||||
assert!(result.stdout.contains("---------- 1 somebody somegroup"));
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
unsafe {
|
||||
umask(last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_deref() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let path_regexp = r"(.*)test-long.link -> (.*)test-long(.*)";
|
||||
let re = Regex::new(path_regexp).unwrap();
|
||||
|
||||
at.touch(&at.plus_as_string("test-long"));
|
||||
at.symlink_file("test-long", "test-long.link");
|
||||
assert!(at.is_symlink("test-long.link"));
|
||||
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg("--color=never")
|
||||
.arg("test-long")
|
||||
.arg("test-long.link")
|
||||
.run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
assert!(re.is_match(&result.stdout.trim()));
|
||||
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.arg("-L")
|
||||
.arg("--color=never")
|
||||
.arg("test-long")
|
||||
.arg("test-long.link")
|
||||
.run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
assert!(!re.is_match(&result.stdout.trim()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_order_size() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("test-1");
|
||||
at.append("test-1", "1");
|
||||
|
||||
at.touch("test-2");
|
||||
at.append("test-2", "22");
|
||||
at.touch("test-3");
|
||||
at.append("test-3", "333");
|
||||
at.touch("test-4");
|
||||
at.append("test-4", "4444");
|
||||
|
||||
let result = scene.ucmd().arg("-al").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
|
||||
let result = scene.ucmd().arg("-S").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(result.stdout, "test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
assert_eq!(result.stdout, "test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("-S").arg("-r").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(result.stdout, "test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
assert_eq!(result.stdout, "test-1 test-2 test-3 test-4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_order_creation() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.touch("test-1");
|
||||
at.append("test-1", "1");
|
||||
sleep(Duration::from_millis(500));
|
||||
at.touch("test-2");
|
||||
at.append("test-2", "22");
|
||||
sleep(Duration::from_millis(500));
|
||||
at.touch("test-3");
|
||||
at.append("test-3", "333");
|
||||
sleep(Duration::from_millis(500));
|
||||
at.touch("test-4");
|
||||
at.append("test-4", "4444");
|
||||
|
||||
let result = scene.ucmd().arg("-al").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
|
||||
let result = scene.ucmd().arg("-t").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(result.stdout, "test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
assert_eq!(result.stdout, "test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("-t").arg("-r").run();
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
assert!(result.success);
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(result.stdout, "test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
assert_eq!(result.stdout, "test-1 test-2 test-3 test-4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_non_existing() {
|
||||
new_ucmd!().arg("doesntexist").fails();
|
||||
|
@ -68,16 +263,23 @@ fn test_ls_recursive() {
|
|||
|
||||
println!("stderr = {:?}", result.stderr);
|
||||
println!("stdout = {:?}", result.stdout);
|
||||
if cfg!(target_os = "windows") {
|
||||
assert!(result.stdout.contains("a\\b:\nb"));
|
||||
} else {
|
||||
#[cfg(not(windows))]
|
||||
assert!(result.stdout.contains("a/b:\nb"));
|
||||
}
|
||||
#[cfg(windows)]
|
||||
assert!(result.stdout.contains("a\\b:\nb"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_ls_color() {
|
||||
new_ucmd!().arg("--color").succeeds();
|
||||
new_ucmd!().arg("--color=always").succeeds();
|
||||
new_ucmd!().arg("--color=never").succeeds();
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("a");
|
||||
at.mkdir("z");
|
||||
at.touch(&at.plus_as_string("a/a"));
|
||||
scene.ucmd().arg("--color").succeeds();
|
||||
scene.ucmd().arg("--color=always").succeeds();
|
||||
scene.ucmd().arg("--color=never").succeeds();
|
||||
scene.ucmd().arg("--color").arg("a").succeeds();
|
||||
scene.ucmd().arg("--color=always").arg("a/a").succeeds();
|
||||
scene.ucmd().arg("--color=never").arg("z").succeeds();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue