1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #680 from jbcrail/add-tests-for-sums

Add tests for cksum/sum.
This commit is contained in:
Heather 2015-08-14 08:14:09 +03:00
commit 1b58f5aaec
17 changed files with 164 additions and 1 deletions

View file

@ -165,6 +165,7 @@ TEST_PROGS := \
base64 \
basename \
cat \
cksum \
cp \
cut \
env \
@ -189,6 +190,7 @@ TEST_PROGS := \
sort \
split \
stdbuf \
sum \
tac \
test \
touch \

View file

@ -112,7 +112,11 @@ Checksum and count the blocks in a file.", NAME, VERSION);
matches.free
};
let print_names = sysv || files.len() > 1;
let print_names = if sysv {
files.len() > 1 || files[0] != "-"
} else {
files.len() > 1
};
for file in files.iter() {
let reader = match open(file) {

39
test/cksum.rs Normal file
View file

@ -0,0 +1,39 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./cksum";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_single_file() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("single_file.expected"));
}
#[test]
fn test_multiple_files() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt").arg("alice_in_wonderland.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("multiple_files.expected"));
}
#[test]
fn test_stdin() {
let input = get_file_contents("lorem_ipsum.txt");
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, input);
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("stdin.expected"));
}

View 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/cksum/lorem_ipsum.txt vendored Normal file
View 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.

View file

@ -0,0 +1,2 @@
378294376 772 lorem_ipsum.txt
3805907707 302 alice_in_wonderland.txt

View file

@ -0,0 +1 @@
378294376 772 lorem_ipsum.txt

1
test/fixtures/cksum/stdin.expected vendored Normal file
View file

@ -0,0 +1 @@
378294376 772

View 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?"

View file

@ -0,0 +1,2 @@
8109 1 lorem_ipsum.txt
1814 1 alice_in_wonderland.txt

View file

@ -0,0 +1 @@
8109 1

1
test/fixtures/sum/bsd_stdin.expected vendored Normal file
View file

@ -0,0 +1 @@
8109 1

13
test/fixtures/sum/lorem_ipsum.txt vendored Normal file
View 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.

View file

@ -0,0 +1,2 @@
6985 2 lorem_ipsum.txt
27441 1 alice_in_wonderland.txt

View file

@ -0,0 +1 @@
6985 2 lorem_ipsum.txt

1
test/fixtures/sum/sysv_stdin.expected vendored Normal file
View file

@ -0,0 +1 @@
6985 2

70
test/sum.rs Normal file
View file

@ -0,0 +1,70 @@
use std::process::Command;
use util::*;
static PROGNAME: &'static str = "./sum";
#[path = "common/util.rs"]
#[macro_use]
mod util;
#[test]
fn test_bsd_single_file() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("bsd_single_file.expected"));
}
#[test]
fn test_bsd_multiple_files() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("lorem_ipsum.txt").arg("alice_in_wonderland.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("bsd_multiple_files.expected"));
}
#[test]
fn test_bsd_stdin() {
let input = get_file_contents("lorem_ipsum.txt");
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd, input);
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("bsd_stdin.expected"));
}
#[test]
fn test_sysv_single_file() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("-s").arg("lorem_ipsum.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("sysv_single_file.expected"));
}
#[test]
fn test_sysv_multiple_files() {
let mut cmd = Command::new(PROGNAME);
let result = run(&mut cmd.arg("-s").arg("lorem_ipsum.txt").arg("alice_in_wonderland.txt"));
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("sysv_multiple_files.expected"));
}
#[test]
fn test_sysv_stdin() {
let input = get_file_contents("lorem_ipsum.txt");
let mut cmd = Command::new(PROGNAME);
let result = run_piped_stdin(&mut cmd.arg("-s"), input);
assert_empty_stderr!(result);
assert!(result.success);
assert_eq!(result.stdout, get_file_contents("sysv_stdin.expected"));
}