From fc77e51b64dde3c59012d91910a1feb3f7bb3fa7 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Thu, 9 Sep 2021 22:24:51 -0400 Subject: [PATCH 1/3] printf: derive Default impl for FormatPrimitive --- src/uu/printf/src/tokenize/num_format/formatter.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/uu/printf/src/tokenize/num_format/formatter.rs b/src/uu/printf/src/tokenize/num_format/formatter.rs index 0438f78bf..790c338ae 100644 --- a/src/uu/printf/src/tokenize/num_format/formatter.rs +++ b/src/uu/printf/src/tokenize/num_format/formatter.rs @@ -11,6 +11,7 @@ use super::format_field::FormatField; // output for a number, organized together // to allow for easy generalization of output manipulation // (e.g. max number of digits after decimal) +#[derive(Default)] pub struct FormatPrimitive { pub prefix: Option, pub pre_decimal: Option, @@ -18,17 +19,6 @@ pub struct FormatPrimitive { pub suffix: Option, } -impl Default for FormatPrimitive { - fn default() -> FormatPrimitive { - FormatPrimitive { - prefix: None, - pre_decimal: None, - post_decimal: None, - suffix: None, - } - } -} - #[derive(Clone, PartialEq)] pub enum Base { Ten = 10, From 91d39de16e3098e90d2e9dba8415a0083f3a24b4 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Fri, 10 Sep 2021 19:25:45 +0200 Subject: [PATCH 2/3] sort: derive Default impl for FieldSelector --- src/uu/sort/src/sort.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index c8a429e53..fe286aa6d 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -800,7 +800,7 @@ impl Default for KeyPosition { } } -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Debug, Default)] struct FieldSelector { from: KeyPosition, to: Option, @@ -812,18 +812,6 @@ struct FieldSelector { needs_selection: bool, } -impl Default for FieldSelector { - fn default() -> Self { - Self { - from: Default::default(), - to: None, - settings: Default::default(), - needs_tokens: false, - needs_selection: false, - } - } -} - impl FieldSelector { /// Splits this position into the actual position and the attached options. fn split_key_options(position: &str) -> (&str, &str) { From 8f901ee860cd8f28395a81ae7786cf6b8e74cfe7 Mon Sep 17 00:00:00 2001 From: Jan Verbeek Date: Fri, 27 Aug 2021 18:10:13 +0200 Subject: [PATCH 3/3] tty: Make test_stdout_fail() less flaky --- tests/by-util/test_tty.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_tty.rs b/tests/by-util/test_tty.rs index f31aa67ee..ed490e7ab 100644 --- a/tests/by-util/test_tty.rs +++ b/tests/by-util/test_tty.rs @@ -66,10 +66,23 @@ fn test_wrong_argument() { #[test] // FixME: freebsd panic -#[cfg(not(any(windows, target_os = "freebsd")))] +#[cfg(all(unix, not(target_os = "freebsd")))] fn test_stdout_fail() { - let mut child = new_ucmd!().run_no_wait(); - drop(child.stdout.take()); - let status = child.wait().unwrap(); + use std::process::{Command, Stdio}; + let ts = TestScenario::new(util_name!()); + // Sleep inside a shell to ensure the process doesn't finish before we've + // closed its stdout + let mut proc = Command::new("sh") + .arg("-c") + .arg(format!( + "sleep 0.2; exec {} {}", + ts.bin_path.to_str().unwrap(), + ts.util_name + )) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); + drop(proc.stdout.take()); + let status = proc.wait().unwrap(); assert_eq!(status.code(), Some(3)); }