diff --git a/src/uu/seq/src/error.rs b/src/uu/seq/src/error.rs index 8c951240f..819368aad 100644 --- a/src/uu/seq/src/error.rs +++ b/src/uu/seq/src/error.rs @@ -28,6 +28,10 @@ pub enum SeqError { /// No arguments were passed to this function, 1 or more is required #[error("missing operand")] NoArguments, + + /// Both a format and equal width where passed to seq + #[error("format string may not be specified when printing equal width strings")] + FormatAndEqualWidth, } fn parse_error_type(e: &ParseNumberError) -> &'static str { diff --git a/src/uu/seq/src/seq.rs b/src/uu/seq/src/seq.rs index 2ef829a6d..b51df9802 100644 --- a/src/uu/seq/src/seq.rs +++ b/src/uu/seq/src/seq.rs @@ -114,6 +114,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { format: matches.get_one::(OPT_FORMAT).map(|s| s.as_str()), }; + if options.equal_width && options.format.is_some() { + return Err(SeqError::FormatAndEqualWidth.into()); + } + let first = if numbers.len() > 1 { match numbers[0].parse() { Ok(num) => num, diff --git a/tests/by-util/test_seq.rs b/tests/by-util/test_seq.rs index b112c75d8..62870a8f6 100644 --- a/tests/by-util/test_seq.rs +++ b/tests/by-util/test_seq.rs @@ -19,6 +19,14 @@ fn test_no_args() { .stderr_contains("missing operand"); } +#[test] +fn test_format_and_equal_width() { + new_ucmd!() + .args(&["-w", "-f", "%f", "1"]) + .fails_with_code(1) + .stderr_contains("format string may not be specified"); +} + #[test] fn test_hex_rejects_sign_after_identifier() { new_ucmd!()