1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #893 from knight42/stat

Implement stat
This commit is contained in:
Heather 2016-06-07 16:35:01 +04:00
commit 461a4e72b0
9 changed files with 1614 additions and 0 deletions

98
tests/test_stat.rs Normal file
View file

@ -0,0 +1,98 @@
use common::util::*;
static UTIL_NAME: &'static str = "stat";
use std::process::Command;
#[test]
fn test_invalid_option() {
let (_, mut ucmd) = testing(UTIL_NAME);
ucmd.arg("-w").arg("-q").arg("/");
ucmd.fails();
}
#[test]
#[cfg(target_os = "linux")]
fn test_terse_fs_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-f", "-t", "/proc"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_fs_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-f", "--format=%n %i 0x%t %T", "/dev/shm"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, "/dev/shm 0 0x1021994 tmpfs\n");
}
#[test]
#[cfg(target_os = "linux")]
fn test_terse_normal_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-t", "/"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_normal_format() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["/boot"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_follow_symlink() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["-L", "/dev/cdrom"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_symlink() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["/dev/cdrom"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_char() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["/dev/zero"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_multi_files() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["/dev", "/usr/lib", "/etc/fstab", "/var"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, expected_result(&args));
}
#[test]
#[cfg(target_os = "linux")]
fn test_printf() {
let (_, mut ucmd) = testing(UTIL_NAME);
let args = ["--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n", "/"];
ucmd.args(&args);
assert_eq!(ucmd.run().stdout, "123?\r\"\\\x07\x08\x1B\x0C\x0B /\x12wZJ\n");
}
fn expected_result(args: &[&str]) -> String {
let output = Command::new(UTIL_NAME).args(args).output().unwrap();
String::from_utf8_lossy(&output.stdout).into_owned()
}

View file

@ -21,6 +21,7 @@ mod sieve;
#[cfg(unix)] mod test_stdbuf;
#[cfg(unix)] mod test_touch;
#[cfg(unix)] mod test_unlink;
#[cfg(unix)] mod test_stat;
mod test_base64;
mod test_basename;