1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 19:36:16 +00:00

Merge pull request #4498 from jfinkels/dd-seconds-precision-3

dd: fix precision for display of total time spent
This commit is contained in:
Terts Diepraam 2023-03-20 12:52:48 +01:00 committed by GitHub
commit b8f2f295a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 24 deletions

View file

@ -2,6 +2,8 @@
use crate::common::util::*;
use regex::Regex;
use std::fs::{File, OpenOptions};
use std::io::{BufReader, Read, Write};
use std::path::PathBuf;
@ -261,7 +263,9 @@ fn test_final_stats_noxfer() {
fn test_final_stats_unspec() {
new_ucmd!()
.run()
.stderr_only("0+0 records in\n0+0 records out\n0 bytes copied, 0.0 s, 0.0 B/s\n")
.stderr_contains("0+0 records in\n0+0 records out\n0 bytes copied, ")
.stderr_matches(&Regex::new(r"\d\.\d+(e-\d\d)? s, ").unwrap())
.stderr_contains("0.0 B/s")
.success();
}
@ -375,9 +379,11 @@ fn test_existing_file_truncated() {
#[test]
fn test_null_stats() {
new_ucmd!()
.args(&["if=null.txt"])
.arg("if=null.txt")
.run()
.stderr_only("0+0 records in\n0+0 records out\n0 bytes copied, 0.0 s, 0.0 B/s\n")
.stderr_contains("0+0 records in\n0+0 records out\n0 bytes copied, ")
.stderr_matches(&Regex::new(r"\d\.\d+(e-\d\d)? s, ").unwrap())
.stderr_contains("0.0 B/s")
.success();
}

View file

@ -692,6 +692,16 @@ impl CmdResult {
self
}
#[track_caller]
pub fn stderr_matches(&self, regex: &regex::Regex) -> &Self {
assert!(
regex.is_match(self.stderr_str()),
"Stderr does not match regex:\n{}",
self.stderr_str()
);
self
}
#[track_caller]
pub fn stdout_does_not_match(&self, regex: &regex::Regex) -> &Self {
assert!(