mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Add initial tests.
This commit is contained in:
parent
1e22455032
commit
2dd90af92a
5 changed files with 95 additions and 1 deletions
3
Makefile
3
Makefile
|
@ -188,7 +188,8 @@ TEST_PROGS := \
|
|||
truncate \
|
||||
tsort \
|
||||
unlink \
|
||||
unexpand
|
||||
unexpand \
|
||||
wc
|
||||
|
||||
TEST ?= $(TEST_PROGS)
|
||||
|
||||
|
|
5
test/fixtures/wc/alice_in_wonderland.txt
vendored
Normal file
5
test/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
test/fixtures/wc/lorem_ipsum.txt
vendored
Normal file
13
test/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
test/fixtures/wc/moby_dick.txt
vendored
Normal file
18
test/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.
|
57
test/wc.rs
Normal file
57
test/wc.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
use std::process::Command;
|
||||
use util::*;
|
||||
|
||||
static PROGNAME: &'static str = "./wc";
|
||||
|
||||
#[path = "common/util.rs"]
|
||||
#[macro_use]
|
||||
mod util;
|
||||
|
||||
#[test]
|
||||
fn test_stdin_default() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run_piped_stdin(&mut cmd, get_file_contents("lorem_ipsum.txt"));
|
||||
assert_eq!(result.stdout, " 13 109 772\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_only_bytes() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run_piped_stdin(&mut cmd.args(&["-c"]), get_file_contents("lorem_ipsum.txt"));
|
||||
assert_eq!(result.stdout, " 772\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_all_counts() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run_piped_stdin(&mut cmd.args(&["-c", "-m", "-l", "-L", "-w"]), get_file_contents("alice_in_wonderland.txt"));
|
||||
assert_eq!(result.stdout, " 5 57 302 302 66\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_default() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.arg("moby_dick.txt"));
|
||||
assert_eq!(result.stdout, " 18 204 1115 moby_dick.txt\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_only_lines() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-l", "moby_dick.txt"]));
|
||||
assert_eq!(result.stdout, " 18 moby_dick.txt\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_all_counts() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["-c", "-l", "-L", "-m", "-w", "alice_in_wonderland.txt"]));
|
||||
assert_eq!(result.stdout, " 5 57 302 302 66 alice_in_wonderland.txt\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_default() {
|
||||
let mut cmd = Command::new(PROGNAME);
|
||||
let result = run(&mut cmd.args(&["lorem_ipsum.txt", "moby_dick.txt", "alice_in_wonderland.txt"]));
|
||||
assert_eq!(result.stdout, " 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 5 57 302 alice_in_wonderland.txt\n 36 370 2189 total\n");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue