Begin project level testing. Minor fixes.

This commit is contained in:
Tyler 2021-06-21 11:17:47 -07:00
parent 22265814ba
commit 47464f50a1
3 changed files with 229 additions and 67 deletions

View file

@ -361,7 +361,6 @@ impl<R: Read> Read for Input<R>
{
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize>
{
// Read from source, ignore read errors if conv=noerror
match self.src.read(&mut buf)
{
Ok(len) =>
@ -1052,11 +1051,11 @@ fn make_prog_line(update: &ProgUpdate) -> String
.get_appropriate_unit(false)
.format(1);
format!("{} bytes ({}, {}) copied, {} s, {}/s",
format!("{} bytes ({}, {}) copied, {:.1} s, {}/s",
update.bytes_total,
btotal_metric,
btotal_bin,
safe_millis * 1000,
update.duration.as_secs_f64(),
xfer_rate
).to_string()
}
@ -1066,7 +1065,7 @@ fn reprint_prog_line(update: &ProgUpdate)
}
fn print_prog_line(update: &ProgUpdate)
{
eprint!("{}", make_prog_line(update));
eprintln!("{}", make_prog_line(update));
}
fn print_xfer_stats(update: &ProgUpdate)
{
@ -1387,6 +1386,18 @@ macro_rules! build_app (
if it is smaller than the block size.",
"BYTES"
)
.optopt(
"",
"iflag",
"read as per the comma separated symbol list of flags",
"FLAG"
)
.optopt(
"",
"oflag",
"write as per the comma separated symbol list of flags",
"FLAG"
)
.optopt(
"",
"if",

View file

@ -177,20 +177,23 @@ fn all_valid_ascii_ebcdic_ascii_roundtrip_conv_test()
dd_fileout(i,o).unwrap();
let res = {
let res = File::open(&tmp_fname_ea).unwrap();
let res = BufReader::new(res);
// Final Comparison
let res = File::open(&tmp_fname_ea).unwrap();
let spec = File::open("./test-resources/all-valid-ascii-chars-37eff01866ba3f538421b30b7cbefcac.test").unwrap();
let mut h = Md5::new();
for b in res.bytes()
{
h.update([b.unwrap()]);
}
assert_eq!(res.metadata().unwrap().len(), spec.metadata().unwrap().len());
h.finalize()
};
let res = BufReader::new(res);
let spec = BufReader::new(spec);
assert_eq!(hex!("37eff01866ba3f538421b30b7cbefcac"), res[..]);
let res = BufReader::new(res);
// Check all bytes match
for (b_res, b_spec) in res.bytes().zip(spec.bytes())
{
assert_eq!(b_res.unwrap(),
b_spec.unwrap());
}
fs::remove_file(&tmp_fname_ae).unwrap();
fs::remove_file(&tmp_fname_ea).unwrap();

View file

@ -1,61 +1,209 @@
use crate::common::util::*;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::{self, File};
#[test]
fn dd_zeros_to_stdout_test_from_args()
fn version()
{
new_ucmd!()
.args(&[
"if=../../src/uu/dd/test-resources/zeros-620f0b67a91f7f74151bc5be745b7110.test",
])
.succeeds()
.stdout_only(
"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
"
);
new_ucmd!()
.args(&["--version"])
.succeeds();
}
#[test]
fn dd_ones_to_file_test_from_args()
fn help()
{
let tmp_fname = "../../src/uu/dd/test-resources/FAILED-ones-to-file-from-args.test";
new_ucmd!()
.args(&[
"if=../../src/uu/dd/test-resources/ones-6ae59e64850377ee5470c854761551ea.test",
&format!("of={}", &tmp_fname),
])
.succeeds();
let res = File::open(&tmp_fname).unwrap();
let res = BufReader::new(res);
let spec = File::open("../../src/uu/dd/test-resources/ones-6ae59e64850377ee5470c854761551ea.test").unwrap();
let spec = BufReader::new(spec);
for (b_res, b_spec) in res.bytes().zip(spec.bytes())
{
assert_eq!(b_res.unwrap(),
b_spec.unwrap());
}
fs::remove_file(&tmp_fname).unwrap();
new_ucmd!()
.args(&["--help"])
.succeeds();
}
fn build_ascii_block(n: usize) -> Vec<u8>
{
vec!['a', 'b', 'c', 'd', 'e', 'f']
.into_iter()
.map(|c| c as u8)
.cycle()
.take(n)
.collect()
}
#[test]
fn test_stdin_stdout()
{
let input = build_ascii_block(521);
let output = String::from_utf8(input.clone()).unwrap();
new_ucmd!()
.args(&["status=none"])
.pipe_in(input)
.succeeds()
.stdout_only(output);
}
#[test]
fn test_stdin_stdout_count()
{
let input = build_ascii_block(521);
let mut output = String::from_utf8(input.clone()).unwrap();
output.truncate(256);
new_ucmd!()
.args(&[
"status=none",
"count=2",
"ibs=128",
])
.pipe_in(input)
.succeeds()
.stdout_only(output);
}
#[test]
fn test_stdin_stdout_count_bytes()
{
let input = build_ascii_block(521);
let mut output = String::from_utf8(input.clone()).unwrap();
output.truncate(256);
new_ucmd!()
.args(&[
"status=none",
"count=256",
"iflag=count_bytes",
])
.pipe_in(input)
.succeeds()
.stdout_only(output);
}
#[test]
fn test_stdin_stdout_skip()
{
let input = build_ascii_block(521);
let mut output = String::from_utf8(input.clone()).unwrap();
let _ = output.drain(..256);
new_ucmd!()
.args(&[
"status=none",
"skip=2",
"ibs=128",
])
.pipe_in(input)
.succeeds()
.stdout_only(output);
}
#[test]
fn test_stdin_stdout_skip_bytes()
{
let input = build_ascii_block(521);
let mut output = String::from_utf8(input.clone()).unwrap();
let _ = output.drain(..256);
new_ucmd!()
.args(&[
"status=none",
"skip=256",
"ibs=128",
"iflag=skip_bytes",
])
.pipe_in(input)
.succeeds()
.stdout_only(output);
}
#[test]
fn test_final_stats_noxfer()
{
new_ucmd!()
.args(&[
"status=noxfer",
])
.succeeds()
.stderr_only("");
}
#[test]
fn test_final_stats_unspec()
{
let output = vec![
"0+0 records in",
"0+0 records out",
"0 bytes (0 B, 0 B) copied, 0.0 s, 0 B/s",
];
let output = output.into_iter()
.fold(String::new(), | mut acc, s | {
acc.push_str(s);
acc.push('\n');
acc
});
new_ucmd!()
.succeeds()
.stderr_only(&output);
}
#[test]
fn test_self_transfer()
{
panic!();
// TODO: Make new copy per-test
new_ucmd!()
.args(&[
"conv=notruc",
"if=../fixtures/dd/zero-256k.copy",
"of=../fixtures/dd/zero-256k.copy",
])
.succeeds();
assert!(false/* Must check that zero256k.copy still == zero-256k.txt */)
}
#[cfg(unix)]
#[test]
fn test_null()
{
let stats = vec![
"0+0 records in",
"0+0 records out",
"0 bytes (0 B, 0 B) copied, 0.0 s, 0 B/s",
];
let stats = stats.into_iter()
.fold(String::new(), | mut acc, s | {
acc.push_str(s);
acc.push('\n');
acc
});
new_ucmd!()
.args(&[
"if=/dev/null",
])
.succeeds()
.stderr_only(stats)
.stdout_only("");
}
#[test]
fn test_ys_to_stdout()
{
let output: Vec<_> = String::from("y\n")
.bytes()
.cycle()
.take(1024)
.collect();
let output = String::from_utf8(output).unwrap();
new_ucmd!()
.args(&[
"if=../fixtures/dd/y-nl-1k.txt",
])
.run()
.stdout_only(output);
}
#[test]
fn test_zeros_to_stdout()
{
let output = vec![0; 256*1024];
let output = String::from_utf8(output).unwrap();
new_ucmd!()
.args(&[
"if=../fixtures/dd/zero-256k.txt",
])
.run()
.stdout_only(output);
}