mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #823 from nathanross/comm-additional-tests
comm: remaining tests for feature completion
This commit is contained in:
commit
68efb303bd
13 changed files with 192 additions and 28 deletions
175
tests/comm.rs
175
tests/comm.rs
|
@ -1,47 +1,166 @@
|
||||||
#[macro_use] mod common;
|
#[macro_use]
|
||||||
|
mod common;
|
||||||
use common::util;
|
|
||||||
|
|
||||||
|
use common::util::testing;
|
||||||
|
use std::ffi::OsStr;
|
||||||
static UTIL_NAME: &'static str = "comm";
|
static UTIL_NAME: &'static str = "comm";
|
||||||
|
|
||||||
#[test]
|
fn comm<A: AsRef<OsStr>, B: AsRef<str>>(args: &[A],
|
||||||
fn test_comm_ab_no_args() {
|
file_stdout_relpath_opt: Option<B>,
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
error_message_opt: Option<B>) {
|
||||||
let result = ucmd.args(&["a", "b"]).run();
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||||
assert_eq!(result.stdout, at.read("ab.expected"));
|
let result = ucmd.args(args)
|
||||||
|
.run();
|
||||||
|
assert!(result.success == error_message_opt.is_none());
|
||||||
|
if let Some(_) = error_message_opt {
|
||||||
|
assert!(result.stderr.len() > 0);
|
||||||
|
// assert!(result.stderr.trim_right() == s);
|
||||||
|
} else {
|
||||||
|
assert!(result.stderr.len() == 0);
|
||||||
|
}
|
||||||
|
if let Some(file_stdout_relpath) = file_stdout_relpath_opt {
|
||||||
|
assert!(result.stdout == at.read(file_stdout_relpath.as_ref()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comm_ab_dash_one() {
|
fn ab_no_args() {
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
comm(&["a", "b"], Some("ab.expected"), None);
|
||||||
let result = ucmd.args(&["a", "b", "-1"]).run();
|
|
||||||
assert_eq!(result.stdout, at.read("ab1.expected"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comm_ab_dash_two() {
|
fn ab_dash_one() {
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
comm(&["a", "b", "-1"], Some("ab1.expected"), None);
|
||||||
let result = ucmd.args(&["a", "b", "-2"]).run();
|
|
||||||
assert_eq!(result.stdout, at.read("ab2.expected"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comm_ab_dash_three() {
|
fn ab_dash_two() {
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
comm(&["a", "b", "-2"], Some("ab2.expected"), None);
|
||||||
let result = ucmd.args(&["a", "b", "-3"]).run();
|
|
||||||
assert_eq!(result.stdout, at.read("ab3.expected"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comm_aempty() {
|
fn ab_dash_three() {
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
comm(&["a", "b", "-3"], Some("ab3.expected"), None);
|
||||||
let result = ucmd.args(&["a", "empty"]).run();
|
|
||||||
assert_eq!(result.stdout, at.read("aempty.expected"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comm_emptyempty() {
|
fn aempty() {
|
||||||
let (at, mut ucmd) = util::testing(UTIL_NAME);
|
comm(&["a", "empty"], Some("aempty.expected"), None);
|
||||||
let result = ucmd.args(&["empty", "empty"]).run();
|
}
|
||||||
assert_eq!(result.stdout, at.read("emptyempty.expected"));
|
|
||||||
|
#[test]
|
||||||
|
fn emptyempty() {
|
||||||
|
comm(&["empty", "empty"], Some("emptyempty.expected"), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn output_delimiter() {
|
||||||
|
comm(&["--output-delimiter=word", "a", "b"],
|
||||||
|
Some("ab_delimiter_word.expected"),
|
||||||
|
None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn output_delimiter_require_arg() {
|
||||||
|
comm(&["--output-delimiter=", "a", "b"],
|
||||||
|
None,
|
||||||
|
Some("error to be defined"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// even though (info) documentation suggests this is an option
|
||||||
|
// in latest GNU Coreutils comm, it actually is not.
|
||||||
|
// this test is essentially an alarm in case someone well-intendingly
|
||||||
|
// implements it.
|
||||||
|
#[test]
|
||||||
|
fn zero_terminated() {
|
||||||
|
for param in vec!["-z", "--zero-terminated"] {
|
||||||
|
comm(&[param, "a", "b"], None, Some("error to be defined"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn check_order() {
|
||||||
|
comm(&["--check-order", "bad_order_1", "bad_order_2"],
|
||||||
|
Some("bad_order12.check_order.expected"),
|
||||||
|
Some("error to be defined"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn nocheck_order() {
|
||||||
|
comm(&["--nocheck-order", "bad_order_1", "bad_order_2"],
|
||||||
|
Some("bad_order12.nocheck_order.expected"),
|
||||||
|
None);
|
||||||
|
}
|
||||||
|
|
||||||
|
// when neither --check-order nor --no-check-order is provided,
|
||||||
|
// stderr and the error code behaves like check order, but stdout
|
||||||
|
// behaves like nocheck_order. However with some quirks detailed below.
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn defaultcheck_order() {
|
||||||
|
comm(&["a", "bad_order_1"], None, Some("error to be defined"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// * the first: if both files are not in order, the default behavior is the only
|
||||||
|
// behavior that will provide an error message
|
||||||
|
|
||||||
|
// * the second: if two rows are paired but are out of order,
|
||||||
|
// it won't matter if all rows in the two files are exactly the same.
|
||||||
|
// This is specified in the documentation
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn defaultcheck_order_identical_bad_order_files() {
|
||||||
|
comm(&["bad_order_1", "bad_order_1"],
|
||||||
|
Some("bad_order11.defaultcheck_order.expected"),
|
||||||
|
None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn defaultcheck_order_two_different_bad_order_files() {
|
||||||
|
comm(&["bad_order_1", "bad_order_2"],
|
||||||
|
Some("bad_order12.nocheck_order.expected"),
|
||||||
|
Some("error to be defined"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// * the third: (it is not know whether this is a bug or not)
|
||||||
|
// for the first incident, and only the first incident,
|
||||||
|
// where both lines are different and one or both file lines being
|
||||||
|
// compared are out of order from the preceding line,
|
||||||
|
// it is ignored and no errors occur.
|
||||||
|
|
||||||
|
// * the fourth: (it is not known whether this is a bug or not)
|
||||||
|
// there are additional, not-yet-understood circumstances where an out-of-order
|
||||||
|
// pair is ignored and is not counted against the 1 maximum out-of-order line.
|
||||||
|
|
||||||
|
#[cfg_attr(not(feature="test_unimplemented"),ignore)]
|
||||||
|
#[test]
|
||||||
|
fn unintuitive_default_behavior_1() {
|
||||||
|
comm(&["defaultcheck_unintuitive_1", "defaultcheck_unintuitive_2"],
|
||||||
|
Some("defaultcheck_unintuitive.expected"),
|
||||||
|
None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[ignore] //bug? should help be stdout if not called via -h|--help?
|
||||||
|
#[test]
|
||||||
|
fn no_arguments() {
|
||||||
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||||
|
let result = ucmd.run();
|
||||||
|
assert!(!result.success);
|
||||||
|
assert!(result.stdout.len() == 0);
|
||||||
|
assert!(result.stderr.len() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[ignore] //bug? should help be stdout if not called via -h|--help?
|
||||||
|
#[test]
|
||||||
|
fn one_argument() {
|
||||||
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||||
|
let result = ucmd.arg("a").run();
|
||||||
|
assert!(!result.success);
|
||||||
|
assert!(result.stdout.len() == 0);
|
||||||
|
assert!(result.stderr.len() > 0);
|
||||||
}
|
}
|
||||||
|
|
3
tests/fixtures/comm/ab_delimiter_word.expected
vendored
Normal file
3
tests/fixtures/comm/ab_delimiter_word.expected
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
a
|
||||||
|
wordb
|
||||||
|
wordwordz
|
4
tests/fixtures/comm/bad_order11.defaultcheck_order.expected
vendored
Normal file
4
tests/fixtures/comm/bad_order11.defaultcheck_order.expected
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
e
|
||||||
|
d
|
||||||
|
b
|
||||||
|
a
|
1
tests/fixtures/comm/bad_order12.check_order.expected
vendored
Normal file
1
tests/fixtures/comm/bad_order12.check_order.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
e
|
7
tests/fixtures/comm/bad_order12.nocheck_order.expected
vendored
Normal file
7
tests/fixtures/comm/bad_order12.nocheck_order.expected
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
e
|
||||||
|
c
|
||||||
|
b
|
||||||
|
a
|
||||||
|
d
|
||||||
|
b
|
||||||
|
a
|
4
tests/fixtures/comm/bad_order_1
vendored
Normal file
4
tests/fixtures/comm/bad_order_1
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
e
|
||||||
|
d
|
||||||
|
b
|
||||||
|
a
|
4
tests/fixtures/comm/bad_order_2
vendored
Normal file
4
tests/fixtures/comm/bad_order_2
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
e
|
||||||
|
c
|
||||||
|
b
|
||||||
|
a
|
6
tests/fixtures/comm/defaultcheck_unintuitive.expected
vendored
Normal file
6
tests/fixtures/comm/defaultcheck_unintuitive.expected
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
m
|
||||||
|
h
|
||||||
|
n
|
||||||
|
o
|
||||||
|
c
|
||||||
|
p
|
6
tests/fixtures/comm/defaultcheck_unintuitive_1
vendored
Normal file
6
tests/fixtures/comm/defaultcheck_unintuitive_1
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
m
|
||||||
|
h
|
||||||
|
n
|
||||||
|
o
|
||||||
|
c
|
||||||
|
p
|
5
tests/fixtures/comm/defaultcheck_unintuitive_2
vendored
Normal file
5
tests/fixtures/comm/defaultcheck_unintuitive_2
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
m
|
||||||
|
h
|
||||||
|
n
|
||||||
|
o
|
||||||
|
p
|
2
tests/fixtures/comm/lowercase_uppercase
vendored
Normal file
2
tests/fixtures/comm/lowercase_uppercase
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
a
|
||||||
|
A
|
1
tests/fixtures/comm/lowercase_uppercase.c.expected
vendored
Normal file
1
tests/fixtures/comm/lowercase_uppercase.c.expected
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
a
|
2
tests/fixtures/comm/lowercase_uppercase.en_us.expected
vendored
Normal file
2
tests/fixtures/comm/lowercase_uppercase.en_us.expected
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
a
|
||||||
|
A
|
Loading…
Add table
Add a link
Reference in a new issue