mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
rewrite tests for cargo compat, decoupled directory, output handling
This commit is contained in:
parent
b20b2cca19
commit
a21c54e2cd
165 changed files with 4315 additions and 3538 deletions
62
tests/base64.rs
Normal file
62
tests/base64.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "base64";
|
||||
|
||||
#[test]
|
||||
fn test_encode() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = "hello, world!";
|
||||
let result = ucmd.run_piped_stdin(input.as_bytes());
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, "aGVsbG8sIHdvcmxkIQ==\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decode() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==";
|
||||
let result = ucmd.arg("-d").run_piped_stdin(input.as_bytes());
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, "hello, world!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_garbage() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
let result = ucmd.arg("-d").run_piped_stdin(input.as_bytes());
|
||||
|
||||
assert!(!result.success);
|
||||
assert_eq!(result.stderr,
|
||||
"base64: error: invalid character (Invalid character '0' at position 20)\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0";
|
||||
let result = ucmd.arg("-d").arg("-i").run_piped_stdin(input.as_bytes());
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, "hello, world!");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wrap() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
let result = ucmd.arg("-w").arg("20").run_piped_stdin(input.as_bytes());
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout,
|
||||
"VGhlIHF1aWNrIGJyb3du\nIGZveCBqdW1wcyBvdmVy\nIHRoZSBsYXp5IGRvZy4=\n");
|
||||
}
|
44
tests/basename.rs
Normal file
44
tests/basename.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "basename";
|
||||
|
||||
#[test]
|
||||
fn test_directory() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
|
||||
ucmd.arg(dir);
|
||||
|
||||
assert_eq!(ucmd.run().stdout.trim_right(), "omega");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_file() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "/etc/passwd";
|
||||
ucmd.arg(file);
|
||||
|
||||
assert_eq!(ucmd.run().stdout.trim_right(), "passwd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_suffix() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let path = "/usr/local/bin/reallylongexecutable.exe";
|
||||
ucmd.arg(path)
|
||||
.arg(".exe");
|
||||
|
||||
assert_eq!(ucmd.run().stdout.trim_right(), "reallylongexecutable");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dont_remove_suffix() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let path = "/foo/bar/baz";
|
||||
ucmd.arg(path)
|
||||
.arg("baz");
|
||||
|
||||
assert_eq!(ucmd.run().stdout.trim_right(), "baz");
|
||||
}
|
49
tests/cat.rs
Normal file
49
tests/cat.rs
Normal file
|
@ -0,0 +1,49 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cat";
|
||||
|
||||
#[test]
|
||||
fn test_output_multi_files_print_all_chars() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
ucmd.arg("alpha.txt")
|
||||
.arg("256.txt")
|
||||
.arg("-A")
|
||||
.arg("-n");
|
||||
|
||||
assert_eq!(ucmd.run().stdout,
|
||||
" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \
|
||||
5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \
|
||||
7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ \
|
||||
!\"#$%&\'()*+,-./0123456789:;\
|
||||
<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?M-^@M-^AM-^\
|
||||
BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^KM-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^V\
|
||||
M-^WM-^XM-^YM-^ZM-^[M-^\\M-^]M-^^M-^_M- \
|
||||
M-!M-\"M-#M-$M-%M-&M-\'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:\
|
||||
M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-U\
|
||||
M-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-\
|
||||
pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_squeeze() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("-A")
|
||||
.run_piped_stdin("\x00\x01\x02".as_bytes())
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, "^@^A^B");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("-b")
|
||||
.arg("-")
|
||||
.run_piped_stdin("\na\nb\n\n\nc".as_bytes())
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, "\n 1\ta\n 2\tb\n\n\n 3\tc");
|
||||
}
|
39
tests/cksum.rs
Normal file
39
tests/cksum.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cksum";
|
||||
|
||||
#[test]
|
||||
fn test_single_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.arg("lorem_ipsum.txt").run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, at.read("single_file.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_files() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.arg("lorem_ipsum.txt")
|
||||
.arg("alice_in_wonderland.txt")
|
||||
.run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, at.read("multiple_files.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = at.read("lorem_ipsum.txt");
|
||||
let result = ucmd.run_piped_stdin(input);
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(result.stdout, at.read("stdin.expected"));
|
||||
}
|
2
tests/common/mod.rs
Normal file
2
tests/common/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
#[macro_use]
|
||||
pub mod util;
|
354
tests/common/util.rs
Normal file
354
tests/common/util.rs
Normal file
|
@ -0,0 +1,354 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
extern crate tempdir;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::io::{Read, Write, Result};
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::symlink as symlink_file;
|
||||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::str::from_utf8;
|
||||
use std::ffi::OsStr;
|
||||
use self::tempdir::TempDir;
|
||||
use std::rc::Rc;
|
||||
|
||||
static PROGNAME: &'static str = "target/debug/uutils";
|
||||
static FIXTURES_DIR: &'static str = "tests/fixtures";
|
||||
static ALREADY_RUN: &'static str = " you have already run this UCommand, if you want to run \
|
||||
another command in the same test, use TestSet::new instead of \
|
||||
testing();";
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_empty_stderr(
|
||||
($cond:expr) => (
|
||||
if $cond.stderr.len() > 0 {
|
||||
panic!(format!("stderr: {}", $cond.stderr))
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! assert_no_error(
|
||||
($cond:expr) => (
|
||||
assert!($cond.success);
|
||||
if $cond.stderr.len() > 0 {
|
||||
panic!(format!("stderr: {}", $cond.stderr))
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
pub struct CmdResult {
|
||||
pub success: bool,
|
||||
pub stdout: String,
|
||||
pub stderr: String,
|
||||
}
|
||||
|
||||
pub fn log_info<T: AsRef<str>, U: AsRef<str>>(msg: T, par: U) {
|
||||
println!("{}: {}", msg.as_ref(), par.as_ref());
|
||||
}
|
||||
|
||||
|
||||
pub fn repeat_str(s: &str, n: u32) -> String {
|
||||
let mut repeated = String::new();
|
||||
for _ in 0..n {
|
||||
repeated.push_str(s);
|
||||
}
|
||||
repeated
|
||||
}
|
||||
|
||||
pub fn recursive_copy(src: &Path, dest: &Path) -> Result<()> {
|
||||
if try!(fs::metadata(src)).is_dir() {
|
||||
for entry in try!(fs::read_dir(src)) {
|
||||
let entry = try!(entry);
|
||||
let mut new_dest = PathBuf::from(dest);
|
||||
new_dest.push(entry.file_name());
|
||||
if try!(fs::metadata(entry.path())).is_dir() {
|
||||
try!(fs::create_dir(&new_dest));
|
||||
try!(recursive_copy(&entry.path(), &new_dest));
|
||||
} else {
|
||||
try!(fs::copy(&entry.path(), new_dest));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub struct AtPath {
|
||||
pub subdir: PathBuf,
|
||||
}
|
||||
impl AtPath {
|
||||
pub fn new(subdir: &Path) -> AtPath {
|
||||
AtPath { subdir: PathBuf::from(subdir) }
|
||||
}
|
||||
pub fn as_string(&self) -> String {
|
||||
self.subdir.to_str().unwrap().to_owned()
|
||||
}
|
||||
pub fn plus(&self, name: &str) -> PathBuf {
|
||||
let mut pathbuf = self.subdir.clone();
|
||||
pathbuf.push(name);
|
||||
pathbuf
|
||||
}
|
||||
pub fn plus_as_string(&self, name: &str) -> String {
|
||||
String::from(self.plus(name).to_str().unwrap())
|
||||
}
|
||||
fn minus(&self, name: &str) -> PathBuf {
|
||||
// relative_from is currently unstable
|
||||
let prefixed = PathBuf::from(name);
|
||||
if prefixed.starts_with(&self.subdir) {
|
||||
let mut unprefixed = PathBuf::new();
|
||||
for component in prefixed.components()
|
||||
.skip(self.subdir.components().count()) {
|
||||
unprefixed.push(component.as_ref().to_str().unwrap());
|
||||
}
|
||||
unprefixed
|
||||
} else {
|
||||
prefixed
|
||||
}
|
||||
}
|
||||
pub fn minus_as_string(&self, name: &str) -> String {
|
||||
String::from(self.minus(name).to_str().unwrap())
|
||||
}
|
||||
pub fn open(&self, name: &str) -> File {
|
||||
log_info("open", self.plus_as_string(name));
|
||||
File::open(self.plus(name)).unwrap()
|
||||
}
|
||||
pub fn read(&self, name: &str) -> String {
|
||||
let mut f = self.open(name);
|
||||
let mut contents = String::new();
|
||||
let _ = f.read_to_string(&mut contents);
|
||||
contents
|
||||
}
|
||||
pub fn write(&self, name: &str, contents: &str) {
|
||||
let mut f = self.open(name);
|
||||
let _ = f.write(contents.as_bytes());
|
||||
}
|
||||
pub fn mkdir(&self, dir: &str) {
|
||||
log_info("mkdir", self.plus_as_string(dir));
|
||||
fs::create_dir(&self.plus(dir)).unwrap();
|
||||
}
|
||||
pub fn mkdir_all(&self, dir: &str) {
|
||||
log_info("mkdir_all", self.plus_as_string(dir));
|
||||
fs::create_dir_all(self.plus(dir)).unwrap();
|
||||
}
|
||||
pub fn make_file(&self, name: &str) -> File {
|
||||
match File::create(&self.plus(name)) {
|
||||
Ok(f) => f,
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
pub fn touch(&self, file: &str) {
|
||||
log_info("touch", self.plus_as_string(file));
|
||||
File::create(&self.plus(file)).unwrap();
|
||||
}
|
||||
pub fn symlink(&self, src: &str, dst: &str) {
|
||||
log_info("symlink",
|
||||
&format!("{},{}", self.plus_as_string(src), self.plus_as_string(dst)));
|
||||
symlink_file(&self.plus(src), &self.plus(dst)).unwrap();
|
||||
}
|
||||
pub fn is_symlink(&self, path: &str) -> bool {
|
||||
log_info("is_symlink", self.plus_as_string(path));
|
||||
match fs::symlink_metadata(&self.plus(path)) {
|
||||
Ok(m) => m.file_type().is_symlink(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_link(&self, path: &str) -> String {
|
||||
log_info("resolve_link", self.plus_as_string(path));
|
||||
match fs::read_link(&self.plus(path)) {
|
||||
Ok(p) => {
|
||||
self.minus_as_string(p.to_str().unwrap())
|
||||
}
|
||||
Err(_) => "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&self, path: &str) -> fs::Metadata {
|
||||
match fs::metadata(&self.plus(path)) {
|
||||
Ok(m) => m,
|
||||
Err(e) => panic!("{}", e),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_exists(&self, path: &str) -> bool {
|
||||
match fs::metadata(&self.plus(path)) {
|
||||
Ok(m) => m.is_file(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dir_exists(&self, path: &str) -> bool {
|
||||
match fs::metadata(&self.plus(path)) {
|
||||
Ok(m) => m.is_dir(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cleanup(&self, path: &'static str) {
|
||||
let p = &self.plus(path);
|
||||
match fs::metadata(p) {
|
||||
Ok(m) => if m.is_file() {
|
||||
fs::remove_file(&p).unwrap();
|
||||
} else {
|
||||
fs::remove_dir(&p).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
pub fn root_dir(&self) -> String {
|
||||
log_info("current_directory", "");
|
||||
self.subdir.to_str().unwrap().to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TestSet {
|
||||
bin_path: PathBuf,
|
||||
util_name: String,
|
||||
pub fixtures: AtPath,
|
||||
tmpd: Rc<TempDir>,
|
||||
}
|
||||
impl TestSet {
|
||||
pub fn new(util_name: &str) -> TestSet {
|
||||
let tmpd = Rc::new(TempDir::new("uutils").unwrap());
|
||||
let ts = TestSet {
|
||||
bin_path: {
|
||||
let mut bin_path_builder = env::current_dir().unwrap();
|
||||
bin_path_builder.push(PathBuf::from(PROGNAME));
|
||||
bin_path_builder
|
||||
},
|
||||
util_name: String::from(util_name),
|
||||
fixtures: AtPath::new(&tmpd.as_ref().path()),
|
||||
tmpd: tmpd,
|
||||
};
|
||||
let mut fixture_path_builder = env::current_dir().unwrap();
|
||||
fixture_path_builder.push(PathBuf::from(FIXTURES_DIR));
|
||||
fixture_path_builder.push(PathBuf::from(util_name));
|
||||
match fs::metadata(&fixture_path_builder) {
|
||||
Ok(m) => if m.is_dir() {
|
||||
recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
ts
|
||||
}
|
||||
pub fn util_cmd(&self) -> UCommand {
|
||||
let mut cmd = self.cmd(&self.bin_path);
|
||||
cmd.arg(&self.util_name);
|
||||
cmd
|
||||
}
|
||||
pub fn cmd<S: AsRef<OsStr>>(&self, bin: S) -> UCommand {
|
||||
UCommand::new_from_tmp(bin, self.tmpd.clone(), true)
|
||||
}
|
||||
// different names are used rather than an argument
|
||||
// because the need to keep the environment is exceedingly rare.
|
||||
pub fn util_cmd_keepenv(&self) -> UCommand {
|
||||
let mut cmd = self.cmd_keepenv(&self.bin_path);
|
||||
cmd.arg(&self.util_name);
|
||||
cmd
|
||||
}
|
||||
pub fn cmd_keepenv<S: AsRef<OsStr>>(&self, bin: S) -> UCommand {
|
||||
UCommand::new_from_tmp(bin, self.tmpd.clone(), false)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UCommand {
|
||||
pub raw: Command,
|
||||
comm_string: String,
|
||||
tmpd: Option<Rc<TempDir>>,
|
||||
has_run: bool,
|
||||
}
|
||||
impl UCommand {
|
||||
pub fn new<T: AsRef<OsStr>, U: AsRef<OsStr>>(arg: T, curdir: U, env_clear: bool) -> UCommand {
|
||||
UCommand {
|
||||
tmpd: None,
|
||||
has_run: false,
|
||||
raw: {
|
||||
let mut cmd = Command::new(arg.as_ref());
|
||||
cmd.current_dir(curdir.as_ref());
|
||||
if env_clear {
|
||||
cmd.env_clear();
|
||||
}
|
||||
cmd
|
||||
},
|
||||
comm_string: String::from(arg.as_ref().to_str().unwrap()),
|
||||
}
|
||||
}
|
||||
pub fn new_from_tmp<T: AsRef<OsStr>>(arg: T, tmpd: Rc<TempDir>, env_clear: bool) -> UCommand {
|
||||
let tmpd_path_buf = String::from(&(*tmpd.as_ref().path().to_str().unwrap()));
|
||||
let mut ucmd: UCommand = UCommand::new(arg.as_ref(), tmpd_path_buf, env_clear);
|
||||
ucmd.tmpd = Some(tmpd);
|
||||
ucmd
|
||||
}
|
||||
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> Box<&mut UCommand> {
|
||||
if self.has_run {
|
||||
panic!(ALREADY_RUN);
|
||||
}
|
||||
self.comm_string.push_str(" ");
|
||||
self.comm_string.push_str(arg.as_ref().to_str().unwrap());
|
||||
self.raw.arg(arg.as_ref());
|
||||
Box::new(self)
|
||||
}
|
||||
|
||||
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> Box<&mut UCommand> {
|
||||
if self.has_run {
|
||||
panic!(ALREADY_RUN);
|
||||
}
|
||||
for s in args {
|
||||
self.comm_string.push_str(" ");
|
||||
self.comm_string.push_str(s.as_ref().to_str().unwrap());
|
||||
}
|
||||
|
||||
self.raw.args(args.as_ref());
|
||||
Box::new(self)
|
||||
}
|
||||
pub fn run(&mut self) -> CmdResult {
|
||||
self.has_run = true;
|
||||
log_info("run", &self.comm_string);
|
||||
let prog = self.raw.output().unwrap();
|
||||
CmdResult {
|
||||
success: prog.status.success(),
|
||||
stdout: from_utf8(&prog.stdout).unwrap().to_string(),
|
||||
stderr: from_utf8(&prog.stderr).unwrap().to_string(),
|
||||
}
|
||||
}
|
||||
pub fn run_piped_stdin<T: AsRef<[u8]>>(&mut self, input: T) -> CmdResult {
|
||||
self.has_run = true;
|
||||
log_info("run_piped_stdin", &self.comm_string);
|
||||
let mut result = self.raw
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
result.stdin
|
||||
.take()
|
||||
.unwrap_or_else(|| panic!("Could not take child process stdin"))
|
||||
.write_all(input.as_ref())
|
||||
.unwrap_or_else(|e| panic!("{}", e));
|
||||
|
||||
let prog = result.wait_with_output().unwrap();
|
||||
CmdResult {
|
||||
success: prog.status.success(),
|
||||
stdout: from_utf8(&prog.stdout).unwrap().to_string(),
|
||||
stderr: from_utf8(&prog.stderr).unwrap().to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// returns a testSet and a ucommand initialized to the utility binary
|
||||
// operating in the fixtures directory with a cleared environment
|
||||
pub fn testset_and_ucommand(utilname: &str) -> (TestSet, UCommand) {
|
||||
let ts = TestSet::new(utilname);
|
||||
let ucmd = ts.util_cmd();
|
||||
(ts, ucmd)
|
||||
}
|
||||
pub fn testing(utilname: &str) -> (AtPath, UCommand) {
|
||||
let ts = TestSet::new(utilname);
|
||||
let ucmd = ts.util_cmd();
|
||||
(ts.fixtures, ucmd)
|
||||
}
|
25
tests/cp.rs
Normal file
25
tests/cp.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cp";
|
||||
|
||||
static TEST_HELLO_WORLD_SOURCE: &'static str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_DEST: &'static str = "copy_of_hello_world.txt";
|
||||
|
||||
#[test]
|
||||
fn test_cp_cp() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
// Invoke our binary to make the copy.
|
||||
let result = ucmd.arg(TEST_HELLO_WORLD_SOURCE)
|
||||
.arg(TEST_HELLO_WORLD_DEST)
|
||||
.run();
|
||||
|
||||
// Check that the exit code represents a successful copy.
|
||||
let exit_success = result.success;
|
||||
assert_eq!(exit_success, true);
|
||||
|
||||
// Check the content of the destination file that was copied.
|
||||
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
|
||||
}
|
60
tests/cut.rs
Normal file
60
tests/cut.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "cut";
|
||||
|
||||
static INPUT: &'static str = "lists.txt";
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_prefix() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-c", "-10", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lists_prefix.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_char_range() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-c", "4-10", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lists_char_range.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_column_to_end_of_line() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-d", ":", "-f", "5-", INPUT]).run();
|
||||
assert_eq!(result.stdout,
|
||||
at.read("lists_column_to_end_of_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_specific_field() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-d", " ", "-f", "3", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lists_specific_field.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_fields() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-d", ":", "-f", "1,3", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lists_multiple_fields.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tail() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-d", ":", "--complement", "-f", "1", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lists_tail.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_change_delimiter() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-d", ":", "--complement", "--output-delimiter=#", "-f", "1", INPUT])
|
||||
.run();
|
||||
assert_eq!(result.stdout, at.read("lists_change_delimiter.expected"));
|
||||
}
|
25
tests/dirname.rs
Normal file
25
tests/dirname.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "dirname";
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_path_with_trailing_slashes() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega//";
|
||||
let out = ucmd.arg(dir).run().stdout;
|
||||
|
||||
assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_without_trailing_slashes() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega";
|
||||
let out = ucmd.arg(dir).run().stdout;
|
||||
|
||||
assert_eq!(out.trim_right(), "/root/alpha/beta/gamma/delta/epsilon");
|
||||
}
|
39
tests/echo.rs
Normal file
39
tests/echo.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "echo";
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
assert_eq!(ucmd.run().stdout, "\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_trailing_newline() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
ucmd.arg("-n")
|
||||
.arg("hello_world");
|
||||
|
||||
assert_eq!(ucmd.run().stdout, "hello_world");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_enable_escapes() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
ucmd.arg("-e")
|
||||
.arg("\\\\\\t\\r");
|
||||
|
||||
assert_eq!(ucmd.run().stdout, "\\\t\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_disable_escapes() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
ucmd.arg("-E")
|
||||
.arg("\\b\\c\\e");
|
||||
|
||||
assert_eq!(ucmd.run().stdout, "\\b\\c\\e\n");
|
||||
}
|
72
tests/env.rs
Normal file
72
tests/env.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "env";
|
||||
|
||||
#[test]
|
||||
fn test_single_name_value_pair() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("FOO=bar").run().stdout;
|
||||
|
||||
assert!(out.lines().any(|line| line == "FOO=bar"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_name_value_pairs() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("FOO=bar")
|
||||
.arg("ABC=xyz")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(),
|
||||
2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_environment() {
|
||||
let ts = TestSet::new(UTIL_NAME);
|
||||
|
||||
let out = ts.util_cmd()
|
||||
.arg("-i")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, "");
|
||||
|
||||
let out = ts.util_cmd()
|
||||
.arg("-")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_null_delimiter() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("-i")
|
||||
.arg("--null")
|
||||
.arg("FOO=bar")
|
||||
.arg("ABC=xyz")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, "FOO=bar\0ABC=xyz\0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unset_variable() {
|
||||
// This test depends on the HOME variable being pre-defined by the
|
||||
// default shell
|
||||
let out = TestSet::new(UTIL_NAME)
|
||||
.util_cmd_keepenv()
|
||||
.arg("-u")
|
||||
.arg("HOME")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
|
||||
}
|
1057
tests/factor.rs
Normal file
1057
tests/factor.rs
Normal file
File diff suppressed because it is too large
Load diff
14
tests/false.rs
Normal file
14
tests/false.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "false";
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_exit_code() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let exit_status = ucmd.run().success;
|
||||
assert_eq!(exit_status, false);
|
||||
}
|
BIN
tests/fixtures/cat/256.txt
vendored
Normal file
BIN
tests/fixtures/cat/256.txt
vendored
Normal file
Binary file not shown.
5
tests/fixtures/cat/alpha.txt
vendored
Normal file
5
tests/fixtures/cat/alpha.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
abcde
|
||||
fghij
|
||||
klmno
|
||||
pqrst
|
||||
uvwxyz
|
5
tests/fixtures/cksum/alice_in_wonderland.txt
vendored
Normal file
5
tests/fixtures/cksum/alice_in_wonderland.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Alice was beginning to get very tired of sitting by
|
||||
her sister on the bank, and of having nothing to do: once or twice
|
||||
she had peeped into the book her sister was reading, but it had no
|
||||
pictures or conversations in it, "and what is the use of a book,"
|
||||
thought Alice "without pictures or conversation?"
|
13
tests/fixtures/cksum/lorem_ipsum.txt
vendored
Normal file
13
tests/fixtures/cksum/lorem_ipsum.txt
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Nunc interdum suscipit sem vel ornare. Proin euismod, justo
|
||||
sed mollis dictum, eros urna ultricies augue, eu pharetra mi ex id
|
||||
ante. Duis convallis porttitor aliquam. Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia. Donec vel
|
||||
velit dui. Etiam fringilla, dolor quis tempor vehicula, lacus
|
||||
turpis bibendum velit, et pellentesque elit odio a magna. Cras
|
||||
vulputate tortor non libero vehicula euismod. Aliquam tincidunt
|
||||
nisl eget enim cursus, viverra sagittis magna commodo. Cras rhoncus
|
||||
egestas leo nec blandit. Suspendisse potenti. Etiam ullamcorper
|
||||
leo vel lacus vestibulum, cursus semper eros efficitur. In hac
|
||||
habitasse platea dictumst. Phasellus scelerisque vehicula
|
||||
fringilla.
|
2
tests/fixtures/cksum/multiple_files.expected
vendored
Normal file
2
tests/fixtures/cksum/multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
378294376 772 lorem_ipsum.txt
|
||||
3805907707 302 alice_in_wonderland.txt
|
1
tests/fixtures/cksum/single_file.expected
vendored
Normal file
1
tests/fixtures/cksum/single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
378294376 772 lorem_ipsum.txt
|
1
tests/fixtures/cksum/stdin.expected
vendored
Normal file
1
tests/fixtures/cksum/stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
378294376 772
|
1
tests/fixtures/cp/hello_world.txt
vendored
Normal file
1
tests/fixtures/cp/hello_world.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Hello, World!
|
4
tests/fixtures/cut/lists.txt
vendored
Normal file
4
tests/fixtures/cut/lists.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:bar:baz:qux:quux
|
||||
one:two:three:four:five:six:seven
|
||||
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
the quick brown fox jumps over the lazy dog
|
4
tests/fixtures/cut/lists_change_delimiter.expected
vendored
Normal file
4
tests/fixtures/cut/lists_change_delimiter.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
bar#baz#qux#quux
|
||||
two#three#four#five#six#seven
|
||||
beta#gamma#delta#epsilon#zeta#eta#theta#iota#kappa#lambda#mu
|
||||
the quick brown fox jumps over the lazy dog
|
4
tests/fixtures/cut/lists_char_range.expected
vendored
Normal file
4
tests/fixtures/cut/lists_char_range.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
:bar:ba
|
||||
:two:th
|
||||
ha:beta
|
||||
quick
|
4
tests/fixtures/cut/lists_column_to_end_of_line.expected
vendored
Normal file
4
tests/fixtures/cut/lists_column_to_end_of_line.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
quux
|
||||
five:six:seven
|
||||
epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
the quick brown fox jumps over the lazy dog
|
4
tests/fixtures/cut/lists_multiple_fields.expected
vendored
Normal file
4
tests/fixtures/cut/lists_multiple_fields.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:baz
|
||||
one:three
|
||||
alpha:gamma
|
||||
the quick brown fox jumps over the lazy dog
|
4
tests/fixtures/cut/lists_prefix.expected
vendored
Normal file
4
tests/fixtures/cut/lists_prefix.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:bar:ba
|
||||
one:two:th
|
||||
alpha:beta
|
||||
the quick
|
4
tests/fixtures/cut/lists_specific_field.expected
vendored
Normal file
4
tests/fixtures/cut/lists_specific_field.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
foo:bar:baz:qux:quux
|
||||
one:two:three:four:five:six:seven
|
||||
alpha:beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
brown
|
4
tests/fixtures/cut/lists_tail.expected
vendored
Normal file
4
tests/fixtures/cut/lists_tail.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
bar:baz:qux:quux
|
||||
two:three:four:five:six:seven
|
||||
beta:gamma:delta:epsilon:zeta:eta:theta:iota:kappa:lambda:mu
|
||||
the quick brown fox jumps over the lazy dog
|
1
tests/fixtures/fold/lorem_ipsum.txt
vendored
Normal file
1
tests/fixtures/fold/lorem_ipsum.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc interdum suscipit sem vel ornare. Proin euismod, justo sed mollis dictum, eros urna ultricies augue, eu pharetra mi ex id ante. Duis convallis porttitor aliquam. Nunc vitae tincidunt ex. Suspendisse iaculis ligula ac diam consectetur lacinia. Donec vel velit dui. Etiam fringilla, dolor quis tempor vehicula, lacus turpis bibendum velit, et pellentesque elit odio a magna. Cras vulputate tortor non libero vehicula euismod. Aliquam tincidunt nisl eget enim cursus, viverra sagittis magna commodo. Cras rhoncus egestas leo nec blandit. Suspendisse potenti. Etiam ullamcorper leo vel lacus vestibulum, cursus semper eros efficitur. In hac habitasse platea dictumst. Phasellus scelerisque vehicula fringilla.
|
20
tests/fixtures/fold/lorem_ipsum_40_column_hard.expected
vendored
Normal file
20
tests/fixtures/fold/lorem_ipsum_40_column_hard.expected
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit. Nunc interdum suscipit
|
||||
sem vel ornare. Proin euismod, justo sed
|
||||
mollis dictum, eros urna ultricies augu
|
||||
e, eu pharetra mi ex id ante. Duis conva
|
||||
llis porttitor aliquam. Nunc vitae tinci
|
||||
dunt ex. Suspendisse iaculis ligula ac d
|
||||
iam consectetur lacinia. Donec vel velit
|
||||
dui. Etiam fringilla, dolor quis tempor
|
||||
vehicula, lacus turpis bibendum velit,
|
||||
et pellentesque elit odio a magna. Cras
|
||||
vulputate tortor non libero vehicula eui
|
||||
smod. Aliquam tincidunt nisl eget enim c
|
||||
ursus, viverra sagittis magna commodo. C
|
||||
ras rhoncus egestas leo nec blandit. Sus
|
||||
pendisse potenti. Etiam ullamcorper leo
|
||||
vel lacus vestibulum, cursus semper eros
|
||||
efficitur. In hac habitasse platea dict
|
||||
umst. Phasellus scelerisque vehicula fri
|
||||
ngilla.
|
21
tests/fixtures/fold/lorem_ipsum_40_column_word.expected
vendored
Normal file
21
tests/fixtures/fold/lorem_ipsum_40_column_word.expected
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit. Nunc interdum suscipit
|
||||
sem vel ornare. Proin euismod, justo
|
||||
sed mollis dictum, eros urna ultricies
|
||||
augue, eu pharetra mi ex id ante. Duis
|
||||
convallis porttitor aliquam. Nunc vitae
|
||||
tincidunt ex. Suspendisse iaculis
|
||||
ligula ac diam consectetur lacinia.
|
||||
Donec vel velit dui. Etiam fringilla,
|
||||
dolor quis tempor vehicula, lacus
|
||||
turpis bibendum velit, et pellentesque
|
||||
elit odio a magna. Cras vulputate
|
||||
tortor non libero vehicula euismod.
|
||||
Aliquam tincidunt nisl eget enim
|
||||
cursus, viverra sagittis magna commodo.
|
||||
Cras rhoncus egestas leo nec blandit.
|
||||
Suspendisse potenti. Etiam ullamcorper
|
||||
leo vel lacus vestibulum, cursus semper
|
||||
eros efficitur. In hac habitasse platea
|
||||
dictumst. Phasellus scelerisque
|
||||
vehicula fringilla.
|
10
tests/fixtures/fold/lorem_ipsum_80_column.expected
vendored
Normal file
10
tests/fixtures/fold/lorem_ipsum_80_column.expected
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc interdum suscipit
|
||||
sem vel ornare. Proin euismod, justo sed mollis dictum, eros urna ultricies augu
|
||||
e, eu pharetra mi ex id ante. Duis convallis porttitor aliquam. Nunc vitae tinci
|
||||
dunt ex. Suspendisse iaculis ligula ac diam consectetur lacinia. Donec vel velit
|
||||
dui. Etiam fringilla, dolor quis tempor vehicula, lacus turpis bibendum velit,
|
||||
et pellentesque elit odio a magna. Cras vulputate tortor non libero vehicula eui
|
||||
smod. Aliquam tincidunt nisl eget enim cursus, viverra sagittis magna commodo. C
|
||||
ras rhoncus egestas leo nec blandit. Suspendisse potenti. Etiam ullamcorper leo
|
||||
vel lacus vestibulum, cursus semper eros efficitur. In hac habitasse platea dict
|
||||
umst. Phasellus scelerisque vehicula fringilla.
|
1
tests/fixtures/hashsum/input.txt
vendored
Normal file
1
tests/fixtures/hashsum/input.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
hello, world
|
1
tests/fixtures/hashsum/md5.expected
vendored
Normal file
1
tests/fixtures/hashsum/md5.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
e4d7f1b4ed2e42d15898f4b27b019da4
|
1
tests/fixtures/hashsum/sha1.expected
vendored
Normal file
1
tests/fixtures/hashsum/sha1.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
b7e23ec29af22b0b4e41da31e868d57226121c84
|
1
tests/fixtures/hashsum/sha224.expected
vendored
Normal file
1
tests/fixtures/hashsum/sha224.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
6e1a93e32fb44081a401f3db3ef2e6e108b7bbeeb5705afdaf01fb27
|
1
tests/fixtures/hashsum/sha256.expected
vendored
Normal file
1
tests/fixtures/hashsum/sha256.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b
|
1
tests/fixtures/hashsum/sha384.expected
vendored
Normal file
1
tests/fixtures/hashsum/sha384.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
1fcdb6059ce05172a26bbe2a3ccc88ed5a8cd5fc53edfd9053304d429296a6da23b1cd9e5c9ed3bb34f00418a70cdb7e
|
1
tests/fixtures/hashsum/sha512.expected
vendored
Normal file
1
tests/fixtures/hashsum/sha512.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
8710339dcb6814d0d9d2290ef422285c9322b7163951f9a0ca8f883d3305286f44139aa374848e4174f5aada663027e4548637b6d19894aec4fb6c46a139fbf9
|
24
tests/fixtures/head/lorem_ipsum.txt
vendored
Normal file
24
tests/fixtures/head/lorem_ipsum.txt
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Nunc interdum suscipit sem vel ornare.
|
||||
Proin euismod,
|
||||
justo sed mollis dictum,
|
||||
eros urna ultricies augue,
|
||||
eu pharetra mi ex id ante.
|
||||
Duis convallis porttitor aliquam.
|
||||
Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia.
|
||||
Donec vel velit dui.
|
||||
Etiam fringilla,
|
||||
dolor quis tempor vehicula,
|
||||
lacus turpis bibendum velit,
|
||||
et pellentesque elit odio a magna.
|
||||
Cras vulputate tortor non libero vehicula euismod.
|
||||
Aliquam tincidunt nisl eget enim cursus,
|
||||
viverra sagittis magna commodo.
|
||||
Cras rhoncus egestas leo nec blandit.
|
||||
Suspendisse potenti.
|
||||
Etiam ullamcorper leo vel lacus vestibulum,
|
||||
cursus semper eros efficitur.
|
||||
In hac habitasse platea dictumst.
|
||||
Phasellus scelerisque vehicula fringilla.
|
1
tests/fixtures/head/lorem_ipsum_1_line.expected
vendored
Normal file
1
tests/fixtures/head/lorem_ipsum_1_line.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Lorem ipsum dolor sit amet,
|
1
tests/fixtures/head/lorem_ipsum_5_chars.expected
vendored
Normal file
1
tests/fixtures/head/lorem_ipsum_5_chars.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Lorem
|
10
tests/fixtures/head/lorem_ipsum_default.expected
vendored
Normal file
10
tests/fixtures/head/lorem_ipsum_default.expected
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Nunc interdum suscipit sem vel ornare.
|
||||
Proin euismod,
|
||||
justo sed mollis dictum,
|
||||
eros urna ultricies augue,
|
||||
eu pharetra mi ex id ante.
|
||||
Duis convallis porttitor aliquam.
|
||||
Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia.
|
11
tests/fixtures/head/lorem_ipsum_verbose.expected
vendored
Normal file
11
tests/fixtures/head/lorem_ipsum_verbose.expected
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
==> lorem_ipsum.txt <==
|
||||
Lorem ipsum dolor sit amet,
|
||||
consectetur adipiscing elit.
|
||||
Nunc interdum suscipit sem vel ornare.
|
||||
Proin euismod,
|
||||
justo sed mollis dictum,
|
||||
eros urna ultricies augue,
|
||||
eu pharetra mi ex id ante.
|
||||
Duis convallis porttitor aliquam.
|
||||
Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia.
|
1
tests/fixtures/mv/hello_world.txt
vendored
Normal file
1
tests/fixtures/mv/hello_world.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Hello, World!
|
27
tests/fixtures/nl/joinblanklines.txt
vendored
Normal file
27
tests/fixtures/nl/joinblanklines.txt
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
Nonempty
|
||||
Nonempty
|
||||
Followed by 10x empty
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Followed by 5x empty
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Followed by 4x empty
|
||||
|
||||
|
||||
|
||||
|
||||
Nonempty
|
||||
Nonempty
|
||||
Nonempty.
|
18
tests/fixtures/nl/section.txt
vendored
Normal file
18
tests/fixtures/nl/section.txt
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
\:\:\:
|
||||
HEADER1
|
||||
HEADER2
|
||||
\:\:
|
||||
BODY1
|
||||
BODY2
|
||||
\:
|
||||
FOOTER1
|
||||
FOOTER2
|
||||
\:\:\:
|
||||
NEXTHEADER1
|
||||
NEXTHEADER2
|
||||
\:\:
|
||||
NEXTBODY1
|
||||
NEXTBODY2
|
||||
\:
|
||||
NEXTFOOTER1
|
||||
NEXTFOOTER2
|
15
tests/fixtures/nl/simple.txt
vendored
Normal file
15
tests/fixtures/nl/simple.txt
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
L1
|
||||
L2
|
||||
L3
|
||||
L4
|
||||
L5
|
||||
L6
|
||||
L7
|
||||
L8
|
||||
L9
|
||||
L10
|
||||
L11
|
||||
L12
|
||||
L13
|
||||
L14
|
||||
L15
|
16
tests/fixtures/paste/html_colors.expected
vendored
Normal file
16
tests/fixtures/paste/html_colors.expected
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
white #FFFFFF
|
||||
silver #C0C0C0
|
||||
gray #808080
|
||||
black #000000
|
||||
red #FF0000
|
||||
maroon #800000
|
||||
yellow #FFFF00
|
||||
olive #808000
|
||||
lime #00FF00
|
||||
green #008000
|
||||
aqua #00FFFF
|
||||
teal #008080
|
||||
blue #0000FF
|
||||
navy #000080
|
||||
fuchsia #FF00FF
|
||||
purple #800080
|
32
tests/fixtures/paste/html_colors.txt
vendored
Normal file
32
tests/fixtures/paste/html_colors.txt
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
white
|
||||
#FFFFFF
|
||||
silver
|
||||
#C0C0C0
|
||||
gray
|
||||
#808080
|
||||
black
|
||||
#000000
|
||||
red
|
||||
#FF0000
|
||||
maroon
|
||||
#800000
|
||||
yellow
|
||||
#FFFF00
|
||||
olive
|
||||
#808000
|
||||
lime
|
||||
#00FF00
|
||||
green
|
||||
#008000
|
||||
aqua
|
||||
#00FFFF
|
||||
teal
|
||||
#008080
|
||||
blue
|
||||
#0000FF
|
||||
navy
|
||||
#000080
|
||||
fuchsia
|
||||
#FF00FF
|
||||
purple
|
||||
#800080
|
2
tests/fixtures/ptx/gnu_ext_disabled_ignore_and_only_file.expected
vendored
Normal file
2
tests/fixtures/ptx/gnu_ext_disabled_ignore_and_only_file.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.xx "" """quotes"", for" "roff" ""
|
||||
.xx "" "{brackets} for" "tex" ""
|
24
tests/fixtures/ptx/gnu_ext_disabled_roff_auto_ref.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_roff_auto_ref.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
.xx "" "" """quotes"", for roff" "" "input:3"
|
||||
.xx "" "and some other like" "%a, b#, c$c" "" "input:5"
|
||||
.xx "" "maybe" "also~or^" "" "input:6"
|
||||
.xx "" "" "and some other like %a, b#, c$c" "" "input:5"
|
||||
.xx "" "oh," "and back\slash" "" "input:7"
|
||||
.xx "" "and some other like %a," "b#, c$c" "" "input:5"
|
||||
.xx "" "oh, and" "back\slash" "" "input:7"
|
||||
.xx "" "and some other like %a, b#," "c$c" "" "input:5"
|
||||
.xx "" "let's check special" "characters:" "" "input:2"
|
||||
.xx "" "let's" "check special characters:" "" "input:2"
|
||||
.xx "" """quotes""," "for roff" "" "input:3"
|
||||
.xx "" "{brackets}" "for tex" "" "input:4"
|
||||
.xx "" "" "hello world!" "" "input:1"
|
||||
.xx "" "" "let's check special characters:" "" "input:2"
|
||||
.xx "" "and some other" "like %a, b#, c$c" "" "input:5"
|
||||
.xx "" "" "maybe also~or^" "" "input:6"
|
||||
.xx "" "" "oh, and back\slash" "" "input:7"
|
||||
.xx "" "and some" "other like %a, b#, c$c" "" "input:5"
|
||||
.xx "" """quotes"", for" "roff" "" "input:3"
|
||||
.xx "" "and" "some other like %a, b#, c$c" "" "input:5"
|
||||
.xx "" "let's check" "special characters:" "" "input:2"
|
||||
.xx "" "{brackets} for" "tex" "" "input:4"
|
||||
.xx "" "hello" "world!" "" "input:1"
|
||||
.xx "" "" "{brackets} for tex" "" "input:4"
|
17
tests/fixtures/ptx/gnu_ext_disabled_roff_input_ref.expected
vendored
Normal file
17
tests/fixtures/ptx/gnu_ext_disabled_roff_input_ref.expected
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
.xx "" "some other like" "%a, b#, c$c" "" "and"
|
||||
.xx "" "" "also~or^" "" "maybe"
|
||||
.xx "" "" "and back\slash" "" "oh,"
|
||||
.xx "" "some other like %a," "b#, c$c" "" "and"
|
||||
.xx "" "and" "back\slash" "" "oh,"
|
||||
.xx "" "some other like %a, b#," "c$c" "" "and"
|
||||
.xx "" "check special" "characters:" "" "let's"
|
||||
.xx "" "" "check special characters:" "" "let's"
|
||||
.xx "" "" "for roff" "" """quotes"","
|
||||
.xx "" "" "for tex" "" "{brackets}"
|
||||
.xx "" "some other" "like %a, b#, c$c" "" "and"
|
||||
.xx "" "some" "other like %a, b#, c$c" "" "and"
|
||||
.xx "" "for" "roff" "" """quotes"","
|
||||
.xx "" "" "some other like %a, b#, c$c" "" "and"
|
||||
.xx "" "check" "special characters:" "" "let's"
|
||||
.xx "" "for" "tex" "" "{brackets}"
|
||||
.xx "" "" "world!" "" "hello"
|
24
tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_roff_no_ref.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
.xx "" "" """quotes"", for roff" ""
|
||||
.xx "" "and some other like" "%a, b#, c$c" ""
|
||||
.xx "" "maybe" "also~or^" ""
|
||||
.xx "" "" "and some other like %a, b#, c$c" ""
|
||||
.xx "" "oh," "and back\slash" ""
|
||||
.xx "" "and some other like %a," "b#, c$c" ""
|
||||
.xx "" "oh, and" "back\slash" ""
|
||||
.xx "" "and some other like %a, b#," "c$c" ""
|
||||
.xx "" "let's check special" "characters:" ""
|
||||
.xx "" "let's" "check special characters:" ""
|
||||
.xx "" """quotes""," "for roff" ""
|
||||
.xx "" "{brackets}" "for tex" ""
|
||||
.xx "" "" "hello world!" ""
|
||||
.xx "" "" "let's check special characters:" ""
|
||||
.xx "" "and some other" "like %a, b#, c$c" ""
|
||||
.xx "" "" "maybe also~or^" ""
|
||||
.xx "" "" "oh, and back\slash" ""
|
||||
.xx "" "and some" "other like %a, b#, c$c" ""
|
||||
.xx "" """quotes"", for" "roff" ""
|
||||
.xx "" "and" "some other like %a, b#, c$c" ""
|
||||
.xx "" "let's check" "special characters:" ""
|
||||
.xx "" "{brackets} for" "tex" ""
|
||||
.xx "" "hello" "world!" ""
|
||||
.xx "" "" "{brackets} for tex" ""
|
24
tests/fixtures/ptx/gnu_ext_disabled_tex_auto_ref.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_tex_auto_ref.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
\xx {}{}{"quotes",}{ for roff}{}{input:3}
|
||||
\xx {}{and some other like}{\%a,}{ b\#, c\$c}{}{input:5}
|
||||
\xx {}{maybe}{also~or^}{}{}{input:6}
|
||||
\xx {}{}{and}{ some other like \%a, b\#, c\$c}{}{input:5}
|
||||
\xx {}{oh,}{and}{ back\backslash{}slash}{}{input:7}
|
||||
\xx {}{and some other like \%a,}{b\#,}{ c\$c}{}{input:5}
|
||||
\xx {}{oh, and}{back\backslash{}slash}{}{}{input:7}
|
||||
\xx {}{and some other like \%a, b\#,}{c\$c}{}{}{input:5}
|
||||
\xx {}{let's check special}{characters:}{}{}{input:2}
|
||||
\xx {}{let's}{check}{ special characters:}{}{input:2}
|
||||
\xx {}{"quotes",}{for}{ roff}{}{input:3}
|
||||
\xx {}{$\{$brackets$\}$}{for}{ tex}{}{input:4}
|
||||
\xx {}{}{hello}{ world!}{}{input:1}
|
||||
\xx {}{}{let's}{ check special characters:}{}{input:2}
|
||||
\xx {}{and some other}{like}{ \%a, b\#, c\$c}{}{input:5}
|
||||
\xx {}{}{maybe}{ also~or^}{}{input:6}
|
||||
\xx {}{}{oh,}{ and back\backslash{}slash}{}{input:7}
|
||||
\xx {}{and some}{other}{ like \%a, b\#, c\$c}{}{input:5}
|
||||
\xx {}{"quotes", for}{roff}{}{}{input:3}
|
||||
\xx {}{and}{some}{ other like \%a, b\#, c\$c}{}{input:5}
|
||||
\xx {}{let's check}{special}{ characters:}{}{input:2}
|
||||
\xx {}{$\{$brackets$\}$ for}{tex}{}{}{input:4}
|
||||
\xx {}{hello}{world!}{}{}{input:1}
|
||||
\xx {}{}{$\{$brackets$\}$}{ for tex}{}{input:4}
|
17
tests/fixtures/ptx/gnu_ext_disabled_tex_input_ref.expected
vendored
Normal file
17
tests/fixtures/ptx/gnu_ext_disabled_tex_input_ref.expected
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
\xx {}{some other like}{\%a,}{ b\#, c\$c}{}{and}
|
||||
\xx {}{}{also~or^}{}{}{maybe}
|
||||
\xx {}{}{and}{ back\backslash{}slash}{}{oh,}
|
||||
\xx {}{some other like \%a,}{b\#,}{ c\$c}{}{and}
|
||||
\xx {}{and}{back\backslash{}slash}{}{}{oh,}
|
||||
\xx {}{some other like \%a, b\#,}{c\$c}{}{}{and}
|
||||
\xx {}{check special}{characters:}{}{}{let's}
|
||||
\xx {}{}{check}{ special characters:}{}{let's}
|
||||
\xx {}{}{for}{ roff}{}{"quotes",}
|
||||
\xx {}{}{for}{ tex}{}{$\{$brackets$\}$}
|
||||
\xx {}{some other}{like}{ \%a, b\#, c\$c}{}{and}
|
||||
\xx {}{some}{other}{ like \%a, b\#, c\$c}{}{and}
|
||||
\xx {}{for}{roff}{}{}{"quotes",}
|
||||
\xx {}{}{some}{ other like \%a, b\#, c\$c}{}{and}
|
||||
\xx {}{check}{special}{ characters:}{}{let's}
|
||||
\xx {}{for}{tex}{}{}{$\{$brackets$\}$}
|
||||
\xx {}{}{world!}{}{}{hello}
|
24
tests/fixtures/ptx/gnu_ext_disabled_tex_no_ref.expected
vendored
Normal file
24
tests/fixtures/ptx/gnu_ext_disabled_tex_no_ref.expected
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
\xx {}{}{"quotes",}{ for roff}{}
|
||||
\xx {}{and some other like}{\%a,}{ b\#, c\$c}{}
|
||||
\xx {}{maybe}{also~or^}{}{}
|
||||
\xx {}{}{and}{ some other like \%a, b\#, c\$c}{}
|
||||
\xx {}{oh,}{and}{ back\backslash{}slash}{}
|
||||
\xx {}{and some other like \%a,}{b\#,}{ c\$c}{}
|
||||
\xx {}{oh, and}{back\backslash{}slash}{}{}
|
||||
\xx {}{and some other like \%a, b\#,}{c\$c}{}{}
|
||||
\xx {}{let's check special}{characters:}{}{}
|
||||
\xx {}{let's}{check}{ special characters:}{}
|
||||
\xx {}{"quotes",}{for}{ roff}{}
|
||||
\xx {}{$\{$brackets$\}$}{for}{ tex}{}
|
||||
\xx {}{}{hello}{ world!}{}
|
||||
\xx {}{}{let's}{ check special characters:}{}
|
||||
\xx {}{and some other}{like}{ \%a, b\#, c\$c}{}
|
||||
\xx {}{}{maybe}{ also~or^}{}
|
||||
\xx {}{}{oh,}{ and back\backslash{}slash}{}
|
||||
\xx {}{and some}{other}{ like \%a, b\#, c\$c}{}
|
||||
\xx {}{"quotes", for}{roff}{}{}
|
||||
\xx {}{and}{some}{ other like \%a, b\#, c\$c}{}
|
||||
\xx {}{let's check}{special}{ characters:}{}
|
||||
\xx {}{$\{$brackets$\}$ for}{tex}{}{}
|
||||
\xx {}{hello}{world!}{}{}
|
||||
\xx {}{}{$\{$brackets$\}$}{ for tex}{}
|
2
tests/fixtures/ptx/ignore
vendored
Normal file
2
tests/fixtures/ptx/ignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
maybe
|
||||
about
|
7
tests/fixtures/ptx/input
vendored
Normal file
7
tests/fixtures/ptx/input
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
hello world!
|
||||
let's check special characters:
|
||||
"quotes", for roff
|
||||
{brackets} for tex
|
||||
and some other like %a, b#, c$c
|
||||
maybe also~or^
|
||||
oh, and back\slash
|
5
tests/fixtures/ptx/only
vendored
Normal file
5
tests/fixtures/ptx/only
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
roff
|
||||
tex
|
||||
world
|
||||
maybe
|
||||
about
|
11
tests/fixtures/sort/human1.ans
vendored
Normal file
11
tests/fixtures/sort/human1.ans
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
844K
|
||||
981K
|
||||
11M
|
||||
13M
|
||||
14M
|
||||
16M
|
||||
18M
|
||||
19M
|
||||
20M
|
||||
981T
|
||||
20P
|
11
tests/fixtures/sort/human1.txt
vendored
Normal file
11
tests/fixtures/sort/human1.txt
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
14M
|
||||
20M
|
||||
20P
|
||||
11M
|
||||
981T
|
||||
16M
|
||||
18M
|
||||
19M
|
||||
844K
|
||||
981K
|
||||
13M
|
2
tests/fixtures/sort/numeric1.ans
vendored
Normal file
2
tests/fixtures/sort/numeric1.ans
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
0
|
||||
.02
|
2
tests/fixtures/sort/numeric1.txt
vendored
Normal file
2
tests/fixtures/sort/numeric1.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.02
|
||||
0
|
2
tests/fixtures/sort/numeric2.ans
vendored
Normal file
2
tests/fixtures/sort/numeric2.ans
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.02
|
||||
.03
|
2
tests/fixtures/sort/numeric2.txt
vendored
Normal file
2
tests/fixtures/sort/numeric2.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.03
|
||||
.02
|
2
tests/fixtures/sort/numeric3.ans
vendored
Normal file
2
tests/fixtures/sort/numeric3.ans
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.000
|
||||
.01
|
2
tests/fixtures/sort/numeric3.txt
vendored
Normal file
2
tests/fixtures/sort/numeric3.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.01
|
||||
.000
|
2
tests/fixtures/sort/numeric4.ans
vendored
Normal file
2
tests/fixtures/sort/numeric4.ans
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.00
|
||||
.01
|
2
tests/fixtures/sort/numeric4.txt
vendored
Normal file
2
tests/fixtures/sort/numeric4.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.01
|
||||
.00
|
2
tests/fixtures/sort/numeric5.ans
vendored
Normal file
2
tests/fixtures/sort/numeric5.ans
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.022
|
||||
.024
|
2
tests/fixtures/sort/numeric5.txt
vendored
Normal file
2
tests/fixtures/sort/numeric5.txt
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.022
|
||||
.024
|
100
tests/fixtures/sort/numeric6.ans
vendored
Normal file
100
tests/fixtures/sort/numeric6.ans
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
22
|
||||
23
|
||||
24
|
||||
25
|
||||
26
|
||||
27
|
||||
28
|
||||
29
|
||||
30
|
||||
31
|
||||
32
|
||||
33
|
||||
34
|
||||
35
|
||||
36
|
||||
37
|
||||
38
|
||||
39
|
||||
40
|
||||
41
|
||||
42
|
||||
43
|
||||
44
|
||||
45
|
||||
46
|
||||
47
|
||||
48
|
||||
49
|
||||
50
|
||||
51
|
||||
52
|
||||
53
|
||||
54
|
||||
55
|
||||
56
|
||||
57
|
||||
58
|
||||
59
|
||||
60
|
||||
61
|
||||
62
|
||||
63
|
||||
64
|
||||
65
|
||||
66
|
||||
67
|
||||
68
|
||||
69
|
||||
70
|
||||
71
|
||||
72
|
||||
73
|
||||
74
|
||||
75
|
||||
76
|
||||
77
|
||||
78
|
||||
79
|
||||
80
|
||||
81
|
||||
82
|
||||
83
|
||||
84
|
||||
85
|
||||
86
|
||||
87
|
||||
88
|
||||
89
|
||||
90
|
||||
91
|
||||
92
|
||||
93
|
||||
94
|
||||
95
|
||||
96
|
||||
97
|
||||
98
|
||||
99
|
||||
100
|
100
tests/fixtures/sort/numeric6.txt
vendored
Normal file
100
tests/fixtures/sort/numeric6.txt
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
33
|
||||
16
|
||||
35
|
||||
56
|
||||
72
|
||||
37
|
||||
21
|
||||
49
|
||||
70
|
||||
48
|
||||
90
|
||||
83
|
||||
44
|
||||
79
|
||||
10
|
||||
20
|
||||
4
|
||||
26
|
||||
27
|
||||
63
|
||||
29
|
||||
47
|
||||
51
|
||||
85
|
||||
88
|
||||
46
|
||||
30
|
||||
61
|
||||
93
|
||||
81
|
||||
78
|
||||
53
|
||||
87
|
||||
18
|
||||
98
|
||||
38
|
||||
13
|
||||
39
|
||||
23
|
||||
71
|
||||
5
|
||||
100
|
||||
96
|
||||
8
|
||||
24
|
||||
14
|
||||
28
|
||||
15
|
||||
25
|
||||
43
|
||||
36
|
||||
67
|
||||
75
|
||||
66
|
||||
31
|
||||
57
|
||||
34
|
||||
80
|
||||
40
|
||||
86
|
||||
17
|
||||
55
|
||||
9
|
||||
1
|
||||
62
|
||||
12
|
||||
74
|
||||
58
|
||||
69
|
||||
76
|
||||
11
|
||||
73
|
||||
68
|
||||
59
|
||||
41
|
||||
45
|
||||
52
|
||||
97
|
||||
82
|
||||
6
|
||||
7
|
||||
77
|
||||
42
|
||||
84
|
||||
95
|
||||
94
|
||||
89
|
||||
19
|
||||
64
|
||||
2
|
||||
22
|
||||
50
|
||||
60
|
||||
32
|
||||
92
|
||||
3
|
||||
99
|
||||
65
|
||||
54
|
||||
91
|
5
tests/fixtures/sum/alice_in_wonderland.txt
vendored
Normal file
5
tests/fixtures/sum/alice_in_wonderland.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Alice was beginning to get very tired of sitting by
|
||||
her sister on the bank, and of having nothing to do: once or twice
|
||||
she had peeped into the book her sister was reading, but it had no
|
||||
pictures or conversations in it, "and what is the use of a book,"
|
||||
thought Alice "without pictures or conversation?"
|
2
tests/fixtures/sum/bsd_multiple_files.expected
vendored
Normal file
2
tests/fixtures/sum/bsd_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
8109 1 lorem_ipsum.txt
|
||||
1814 1 alice_in_wonderland.txt
|
1
tests/fixtures/sum/bsd_single_file.expected
vendored
Normal file
1
tests/fixtures/sum/bsd_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
8109 1
|
1
tests/fixtures/sum/bsd_stdin.expected
vendored
Normal file
1
tests/fixtures/sum/bsd_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
8109 1
|
13
tests/fixtures/sum/lorem_ipsum.txt
vendored
Normal file
13
tests/fixtures/sum/lorem_ipsum.txt
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Nunc interdum suscipit sem vel ornare. Proin euismod, justo
|
||||
sed mollis dictum, eros urna ultricies augue, eu pharetra mi ex id
|
||||
ante. Duis convallis porttitor aliquam. Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia. Donec vel
|
||||
velit dui. Etiam fringilla, dolor quis tempor vehicula, lacus
|
||||
turpis bibendum velit, et pellentesque elit odio a magna. Cras
|
||||
vulputate tortor non libero vehicula euismod. Aliquam tincidunt
|
||||
nisl eget enim cursus, viverra sagittis magna commodo. Cras rhoncus
|
||||
egestas leo nec blandit. Suspendisse potenti. Etiam ullamcorper
|
||||
leo vel lacus vestibulum, cursus semper eros efficitur. In hac
|
||||
habitasse platea dictumst. Phasellus scelerisque vehicula
|
||||
fringilla.
|
2
tests/fixtures/sum/sysv_multiple_files.expected
vendored
Normal file
2
tests/fixtures/sum/sysv_multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
6985 2 lorem_ipsum.txt
|
||||
27441 1 alice_in_wonderland.txt
|
1
tests/fixtures/sum/sysv_single_file.expected
vendored
Normal file
1
tests/fixtures/sum/sysv_single_file.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
6985 2 lorem_ipsum.txt
|
1
tests/fixtures/sum/sysv_stdin.expected
vendored
Normal file
1
tests/fixtures/sum/sysv_stdin.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
6985 2
|
1
tests/fixtures/tac/delimited_primes.expected
vendored
Normal file
1
tests/fixtures/tac/delimited_primes.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
9789:83:79:73:71:67:61:59:53:47:43:41:37:31:29:23:19:17:13:11:7:5:3:2:
|
1
tests/fixtures/tac/delimited_primes.txt
vendored
Normal file
1
tests/fixtures/tac/delimited_primes.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
2:3:5:7:11:13:17:19:23:29:31:37:41:43:47:53:59:61:67:71:73:79:83:89:97
|
1
tests/fixtures/tac/delimited_primes_before.expected
vendored
Normal file
1
tests/fixtures/tac/delimited_primes_before.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
97:89:83:79:73:71:67:61:59:53:47:43:41:37:31:29:23:19:17:13:11:7:5:3:2
|
25
tests/fixtures/tac/prime_per_line.expected
vendored
Normal file
25
tests/fixtures/tac/prime_per_line.expected
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
97
|
||||
89
|
||||
83
|
||||
79
|
||||
73
|
||||
71
|
||||
67
|
||||
61
|
||||
59
|
||||
53
|
||||
47
|
||||
43
|
||||
41
|
||||
37
|
||||
31
|
||||
29
|
||||
23
|
||||
19
|
||||
17
|
||||
13
|
||||
11
|
||||
7
|
||||
5
|
||||
3
|
||||
2
|
25
tests/fixtures/tac/prime_per_line.txt
vendored
Normal file
25
tests/fixtures/tac/prime_per_line.txt
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
2
|
||||
3
|
||||
5
|
||||
7
|
||||
11
|
||||
13
|
||||
17
|
||||
19
|
||||
23
|
||||
29
|
||||
31
|
||||
37
|
||||
41
|
||||
43
|
||||
47
|
||||
53
|
||||
59
|
||||
61
|
||||
67
|
||||
71
|
||||
73
|
||||
79
|
||||
83
|
||||
89
|
||||
97
|
17
tests/fixtures/tsort/call_graph.expected
vendored
Normal file
17
tests/fixtures/tsort/call_graph.expected
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
main
|
||||
parse_options
|
||||
tail_file
|
||||
tail_forever
|
||||
tail
|
||||
recheck
|
||||
write_header
|
||||
tail_lines
|
||||
tail_bytes
|
||||
pretty_name
|
||||
start_lines
|
||||
file_lines
|
||||
pipe_lines
|
||||
xlseek
|
||||
start_bytes
|
||||
pipe_bytes
|
||||
dump_remainder
|
22
tests/fixtures/tsort/call_graph.txt
vendored
Normal file
22
tests/fixtures/tsort/call_graph.txt
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
main parse_options
|
||||
main tail_file
|
||||
main tail_forever
|
||||
tail_file pretty_name
|
||||
tail_file write_header
|
||||
tail_file tail
|
||||
tail_forever recheck
|
||||
tail_forever pretty_name
|
||||
tail_forever write_header
|
||||
tail_forever dump_remainder
|
||||
tail tail_lines
|
||||
tail tail_bytes
|
||||
tail_lines start_lines
|
||||
tail_lines dump_remainder
|
||||
tail_lines file_lines
|
||||
tail_lines pipe_lines
|
||||
tail_bytes xlseek
|
||||
tail_bytes start_bytes
|
||||
tail_bytes dump_remainder
|
||||
tail_bytes pipe_bytes
|
||||
file_lines dump_remainder
|
||||
recheck pretty_name
|
5
tests/fixtures/wc/alice_in_wonderland.txt
vendored
Normal file
5
tests/fixtures/wc/alice_in_wonderland.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
Alice was beginning to get very tired of sitting by
|
||||
her sister on the bank, and of having nothing to do: once or twice
|
||||
she had peeped into the book her sister was reading, but it had no
|
||||
pictures or conversations in it, "and what is the use of a book,"
|
||||
thought Alice "without pictures or conversation?"
|
13
tests/fixtures/wc/lorem_ipsum.txt
vendored
Normal file
13
tests/fixtures/wc/lorem_ipsum.txt
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
Lorem ipsum dolor sit amet, consectetur adipiscing
|
||||
elit. Nunc interdum suscipit sem vel ornare. Proin euismod, justo
|
||||
sed mollis dictum, eros urna ultricies augue, eu pharetra mi ex id
|
||||
ante. Duis convallis porttitor aliquam. Nunc vitae tincidunt ex.
|
||||
Suspendisse iaculis ligula ac diam consectetur lacinia. Donec vel
|
||||
velit dui. Etiam fringilla, dolor quis tempor vehicula, lacus
|
||||
turpis bibendum velit, et pellentesque elit odio a magna. Cras
|
||||
vulputate tortor non libero vehicula euismod. Aliquam tincidunt
|
||||
nisl eget enim cursus, viverra sagittis magna commodo. Cras rhoncus
|
||||
egestas leo nec blandit. Suspendisse potenti. Etiam ullamcorper
|
||||
leo vel lacus vestibulum, cursus semper eros efficitur. In hac
|
||||
habitasse platea dictumst. Phasellus scelerisque vehicula
|
||||
fringilla.
|
18
tests/fixtures/wc/moby_dick.txt
vendored
Normal file
18
tests/fixtures/wc/moby_dick.txt
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
Call me Ishmael. Some years ago - never mind how long
|
||||
precisely - having little or no money in my purse, and nothing
|
||||
particular to interest me on shore, I thought I would sail about a
|
||||
little and see the watery part of the world. It is a way I have of
|
||||
driving off the spleen and regulating the circulation. Whenever I
|
||||
find myself growing grim about the mouth; whenever it is a damp,
|
||||
drizzly November in my soul; whenever I find myself involuntarily
|
||||
pausing before coffin warehouses, and bringing up the rear of every
|
||||
funeral I meet; and especially whenever my hypos get such an upper
|
||||
hand of me, that it requires a strong moral principle to prevent me
|
||||
from deliberately stepping into the street, and methodically
|
||||
knocking people's hats off - then, I account it high time to get to
|
||||
sea as soon as I can. This is my substitute for pistol and ball.
|
||||
With a philosophical flourish Cato throws himself upon his sword; I
|
||||
quietly take to the ship. There is nothing surprising in this. If
|
||||
they but knew it, almost all men in their degree, some time or
|
||||
other, cherish very nearly the same feelings towards the ocean with
|
||||
me.
|
41
tests/fold.rs
Normal file
41
tests/fold.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "fold";
|
||||
|
||||
#[test]
|
||||
fn test_default_80_column_wrap() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("lorem_ipsum.txt")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, at.read("lorem_ipsum_80_column.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_40_column_hard_cutoff() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("-w")
|
||||
.arg("40")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, at.read("lorem_ipsum_40_column_hard.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_40_column_word_boundary() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let out = ucmd.arg("-s")
|
||||
.arg("-w")
|
||||
.arg("40")
|
||||
.arg("lorem_ipsum.txt")
|
||||
.run()
|
||||
.stdout;
|
||||
|
||||
assert_eq!(out, at.read("lorem_ipsum_40_column_word.expected"));
|
||||
}
|
47
tests/hashsum.rs
Normal file
47
tests/hashsum.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
macro_rules! get_hash(
|
||||
($str:expr) => (
|
||||
$str.split(' ').collect::<Vec<&str>>()[0]
|
||||
);
|
||||
);
|
||||
|
||||
macro_rules! test_digest {
|
||||
($($t:ident)*) => ($(
|
||||
|
||||
mod $t {
|
||||
use common::util::*;
|
||||
static UTIL_NAME: &'static str = "hashsum";
|
||||
static DIGEST_ARG: &'static str = concat!("--", stringify!($t));
|
||||
static EXPECTED_FILE: &'static str = concat!(stringify!($t), ".expected");
|
||||
|
||||
#[test]
|
||||
fn test_single_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.arg(DIGEST_ARG).arg("input.txt").run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(get_hash!(result.stdout), at.read(EXPECTED_FILE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let input = at.read("input.txt");
|
||||
let result = ucmd.arg(DIGEST_ARG).run_piped_stdin(input);
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert_eq!(get_hash!(result.stdout), at.read(EXPECTED_FILE));
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
test_digest! { md5 sha1 sha224 sha256 sha384 sha512 }
|
75
tests/head.rs
Normal file
75
tests/head.rs
Normal file
|
@ -0,0 +1,75 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "head";
|
||||
|
||||
static INPUT: &'static str = "lorem_ipsum.txt";
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_stdin_default() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.run_piped_stdin(at.read(INPUT));
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_default.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_1_line_obsolete() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-1"])
|
||||
.run_piped_stdin(at.read(INPUT));
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_1_line() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-n", "1"])
|
||||
.run_piped_stdin(at.read(INPUT));
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_5_chars() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-c", "5"])
|
||||
.run_piped_stdin(at.read(INPUT));
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_5_chars.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_default() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.arg(INPUT).run();
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_default.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_1_line_obsolete() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-1", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_1_line() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-n", "1", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_1_line.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_5_chars() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-c", "5", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_5_chars.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_verbose() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let result = ucmd.args(&["-v", INPUT]).run();
|
||||
assert_eq!(result.stdout, at.read("lorem_ipsum_verbose.expected"));
|
||||
}
|
53
tests/link.rs
Normal file
53
tests/link.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
extern crate libc;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "link";
|
||||
|
||||
#[test]
|
||||
fn test_link_existing_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_link_existing_file";
|
||||
let link = "test_link_existing_file_link";
|
||||
|
||||
at.touch(file);
|
||||
at.write(file, "foobar");
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
let result = ucmd.args(&[file, link]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.file_exists(link));
|
||||
assert_eq!(at.read(file), at.read(link));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_link_no_circular() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let link = "test_link_no_circular";
|
||||
|
||||
let result = ucmd.args(&[link, link]).run();
|
||||
assert_eq!(result.stderr,
|
||||
"link: error: No such file or directory (os error 2)\n");
|
||||
assert!(!result.success);
|
||||
assert!(!at.file_exists(link));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_link_nonexistent_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_link_nonexistent_file";
|
||||
let link = "test_link_nonexistent_file_link";
|
||||
|
||||
let result = ucmd.args(&[file, link]).run();
|
||||
assert_eq!(result.stderr,
|
||||
"link: error: No such file or directory (os error 2)\n");
|
||||
assert!(!result.success);
|
||||
assert!(!at.file_exists(file));
|
||||
assert!(!at.file_exists(link));
|
||||
}
|
375
tests/ln.rs
Normal file
375
tests/ln.rs
Normal file
|
@ -0,0 +1,375 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "ln";
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_symlink_existing_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_existing_file";
|
||||
let link = "test_symlink_existing_file_link";
|
||||
|
||||
at.touch(file);
|
||||
|
||||
let result = ucmd.args(&["-s", file, link]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_dangling_file() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_dangling_file";
|
||||
let link = "test_symlink_dangling_file_link";
|
||||
|
||||
let result = ucmd.args(&["-s", file, link]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(!at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_existing_directory() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_symlink_existing_dir";
|
||||
let link = "test_symlink_existing_dir_link";
|
||||
|
||||
at.mkdir(dir);
|
||||
|
||||
let result = ucmd.args(&["-s", dir, link]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.dir_exists(dir));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_dangling_directory() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_symlink_dangling_dir";
|
||||
let link = "test_symlink_dangling_dir_link";
|
||||
|
||||
let result = ucmd.args(&["-s", dir, link]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(!at.dir_exists(dir));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_circular() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let link = "test_symlink_circular";
|
||||
|
||||
let result = ucmd.args(&["-s", link]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), link);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_dont_overwrite() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_dont_overwrite";
|
||||
let link = "test_symlink_dont_overwrite_link";
|
||||
|
||||
at.touch(file);
|
||||
at.touch(link);
|
||||
|
||||
let result = ucmd.args(&["-s", file, link]).run();
|
||||
assert!(!result.success);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.file_exists(link));
|
||||
assert!(!at.is_symlink(link));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_overwrite_force() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file_a = "test_symlink_overwrite_force_a";
|
||||
let file_b = "test_symlink_overwrite_force_b";
|
||||
let link = "test_symlink_overwrite_force_link";
|
||||
|
||||
// Create symlink
|
||||
at.symlink(file_a, link);
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file_a);
|
||||
|
||||
// Force overwrite of existing symlink
|
||||
let result = ucmd.args(&["--force", "-s", file_b, link]).run();
|
||||
assert!(result.success);
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file_b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_interactive() {
|
||||
let ts = TestSet::new(UTIL_NAME);
|
||||
let at = &ts.fixtures;
|
||||
let file = "test_symlink_interactive_file";
|
||||
let link = "test_symlink_interactive_file_link";
|
||||
|
||||
at.touch(file);
|
||||
at.touch(link);
|
||||
|
||||
let result1 = ts.util_cmd()
|
||||
.args(&["-i", "-s", file, link])
|
||||
.run_piped_stdin(b"n");
|
||||
|
||||
assert_empty_stderr!(result1);
|
||||
assert!(result1.success);
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
assert!(!at.is_symlink(link));
|
||||
|
||||
let result2 = ts.util_cmd()
|
||||
.args(&["-i", "-s", file, link])
|
||||
.run_piped_stdin(b"Yesh");
|
||||
|
||||
assert_empty_stderr!(result2);
|
||||
assert!(result2.success);
|
||||
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_simple_backup() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_simple_backup";
|
||||
let link = "test_symlink_simple_backup_link";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink(file, link);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let result = ucmd.args(&["-b", "-s", file, link]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let backup = &format!("{}~", link);
|
||||
assert!(at.is_symlink(backup));
|
||||
assert_eq!(at.resolve_link(backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_custom_backup_suffix() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_custom_backup_suffix";
|
||||
let link = "test_symlink_custom_backup_suffix_link";
|
||||
let suffix = "super-suffix-of-the-century";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink(file, link);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let arg = &format!("--suffix={}", suffix);
|
||||
let result = ucmd.args(&["-b", arg, "-s", file, link]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let backup = &format!("{}{}", link, suffix);
|
||||
assert!(at.is_symlink(backup));
|
||||
assert_eq!(at.resolve_link(backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_backup_numbering() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_backup_numbering";
|
||||
let link = "test_symlink_backup_numbering_link";
|
||||
|
||||
at.touch(file);
|
||||
at.symlink(file, link);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let result = ucmd.args(&["-s", "--backup=t", file, link]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
let backup = &format!("{}.~1~", link);
|
||||
assert!(at.is_symlink(backup));
|
||||
assert_eq!(at.resolve_link(backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_existing_backup() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let file = "test_symlink_existing_backup";
|
||||
let link = "test_symlink_existing_backup_link";
|
||||
let link_backup = "test_symlink_existing_backup_link.~1~";
|
||||
let resulting_backup = "test_symlink_existing_backup_link.~2~";
|
||||
|
||||
// Create symlink and verify
|
||||
at.touch(file);
|
||||
at.symlink(file, link);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link));
|
||||
assert_eq!(at.resolve_link(link), file);
|
||||
|
||||
// Create backup symlink and verify
|
||||
at.symlink(file, link_backup);
|
||||
assert!(at.file_exists(file));
|
||||
assert!(at.is_symlink(link_backup));
|
||||
assert_eq!(at.resolve_link(link_backup), file);
|
||||
|
||||
let result = ucmd.args(&["-s", "--backup=nil", file, link]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
assert!(at.file_exists(file));
|
||||
|
||||
assert!(at.is_symlink(link_backup));
|
||||
assert_eq!(at.resolve_link(link_backup), file);
|
||||
|
||||
assert!(at.is_symlink(resulting_backup));
|
||||
assert_eq!(at.resolve_link(resulting_backup), file);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_target_dir() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_ln_target_dir_dir";
|
||||
let file_a = "test_ln_target_dir_file_a";
|
||||
let file_b = "test_ln_target_dir_file_b";
|
||||
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
at.mkdir(dir);
|
||||
|
||||
let result = ucmd.args(&["-s", "-t", dir, file_a, file_b]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
let file_a_link = &format!("{}/{}", dir, file_a);
|
||||
assert!(at.is_symlink(file_a_link));
|
||||
assert_eq!(at.resolve_link(file_a_link), file_a);
|
||||
|
||||
let file_b_link = &format!("{}/{}", dir, file_b);
|
||||
assert!(at.is_symlink(file_b_link));
|
||||
assert_eq!(at.resolve_link(file_b_link), file_b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_overwrite_dir() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let path_a = "test_symlink_overwrite_dir_a";
|
||||
let path_b = "test_symlink_overwrite_dir_b";
|
||||
|
||||
at.touch(path_a);
|
||||
at.mkdir(path_b);
|
||||
|
||||
let result = ucmd.args(&["-s", "-T", path_a, path_b]).run();
|
||||
|
||||
assert_empty_stderr!(result);
|
||||
assert!(result.success);
|
||||
|
||||
assert!(at.file_exists(path_a));
|
||||
assert!(at.is_symlink(path_b));
|
||||
assert_eq!(at.resolve_link(path_b), path_a);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_overwrite_nonempty_dir() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let path_a = "test_symlink_overwrite_nonempty_dir_a";
|
||||
let path_b = "test_symlink_overwrite_nonempty_dir_b";
|
||||
let dummy = "test_symlink_overwrite_nonempty_dir_b/file";
|
||||
|
||||
at.touch(path_a);
|
||||
at.mkdir(path_b);
|
||||
at.touch(dummy);
|
||||
|
||||
let result = ucmd.args(&["-v", "-T", "-s", path_a, path_b]).run();
|
||||
|
||||
// Not same error as GNU; the error message is a Rust builtin
|
||||
// TODO: test (and implement) correct error message (or at least decide whether to do so)
|
||||
// Current: "ln: error: Directory not empty (os error 66)"
|
||||
// GNU: "ln: cannot link 'a' to 'b': Directory not empty"
|
||||
assert!(result.stderr.len() > 0);
|
||||
|
||||
// Verbose output for the link should not be shown on failure
|
||||
assert!(result.stdout.len() == 0);
|
||||
|
||||
assert!(!result.success);
|
||||
assert!(at.file_exists(path_a));
|
||||
assert!(at.dir_exists(path_b));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_errors() {
|
||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||
let dir = "test_symlink_errors_dir";
|
||||
let file_a = "test_symlink_errors_file_a";
|
||||
let file_b = "test_symlink_errors_file_b";
|
||||
|
||||
at.mkdir(dir);
|
||||
at.touch(file_a);
|
||||
at.touch(file_b);
|
||||
|
||||
// $ ln -T -t a b
|
||||
// ln: cannot combine --target-directory (-t) and --no-target-directory (-T)
|
||||
let result = ucmd.args(&["-T", "-t", dir, file_a, file_b]).run();
|
||||
assert_eq!(result.stderr,
|
||||
"ln: error: cannot combine --target-directory (-t) and --no-target-directory \
|
||||
(-T)\n");
|
||||
assert!(!result.success);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_symlink_verbose() {
|
||||
let ts = TestSet::new(UTIL_NAME);
|
||||
let at = &ts.fixtures;
|
||||
let file_a = "test_symlink_verbose_file_a";
|
||||
let file_b = "test_symlink_verbose_file_b";
|
||||
|
||||
at.touch(file_a);
|
||||
|
||||
let result = ts.util_cmd().args(&["-v", file_a, file_b]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert_eq!(result.stdout, format!("'{}' -> '{}'\n", file_b, file_a));
|
||||
assert!(result.success);
|
||||
|
||||
at.touch(file_b);
|
||||
|
||||
let result = ts.util_cmd().args(&["-v", "-b", file_a, file_b]).run();
|
||||
assert_empty_stderr!(result);
|
||||
assert_eq!(result.stdout,
|
||||
format!("'{}' -> '{}' (backup: '{}~')\n", file_b, file_a, file_b));
|
||||
assert!(result.success);
|
||||
}
|
54
tests/mkdir.rs
Normal file
54
tests/mkdir.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
static UTIL_NAME: &'static str = "mkdir";
|
||||
|
||||
static TEST_DIR1: &'static str = "mkdir_test1";
|
||||
static TEST_DIR2: &'static str = "mkdir_test2";
|
||||
static TEST_DIR3: &'static str = "mkdir_test3";
|
||||
static TEST_DIR4: &'static str = "mkdir_test4/mkdir_test4_1";
|
||||
static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1";
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_mkdir() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let exit_success = ucmd.arg(TEST_DIR1).run().success;
|
||||
assert_eq!(exit_success, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_dup_dir() {
|
||||
let ts = TestSet::new(UTIL_NAME);
|
||||
let exit_success = ts.util_cmd().arg(TEST_DIR2).run().success;
|
||||
let exit_success2 = ts.util_cmd().arg(TEST_DIR2).run().success;
|
||||
assert!(exit_success);
|
||||
assert!(!exit_success2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_mode() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let exit_success = ucmd.arg("-m")
|
||||
.arg("755")
|
||||
.arg(TEST_DIR3)
|
||||
.run()
|
||||
.success;
|
||||
assert!(exit_success);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_parent() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let exit_success = ucmd.arg("-p").arg(TEST_DIR4).run().success;
|
||||
assert!(exit_success);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_no_parent() {
|
||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||
let exit_success = ucmd.arg(TEST_DIR5).run().success;
|
||||
assert!(!exit_success);
|
||||
}
|
1
tests/mod.rs
Normal file
1
tests/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod common;
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue