From 6ce077d4c1669c5cb092fd28e24bd30c93a004c4 Mon Sep 17 00:00:00 2001 From: Martin Paulsen <43757366+georgepaulsen@users.noreply.github.com> Date: Wed, 31 Dec 2025 11:57:05 -0500 Subject: [PATCH 1/2] Check for three-string comparison in test --- src/uu/test/src/parser.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/uu/test/src/parser.rs b/src/uu/test/src/parser.rs index 167bf77023a..c1c06e4c581 100644 --- a/src/uu/test/src/parser.rs +++ b/src/uu/test/src/parser.rs @@ -188,7 +188,16 @@ impl Parser { match symbol { Symbol::LParen => self.lparen()?, Symbol::Bang => self.bang()?, - Symbol::UnaryOp(_) => self.uop(symbol), + Symbol::UnaryOp(_) => { + // Three-argument string comparison: `-f = a` means "-f" = "a", not file test + let is_string_cmp = matches!(self.peek(), Symbol::Op(Operator::String(_))) + && !matches!(Symbol::new(self.tokens.clone().nth(1)), Symbol::None); + if is_string_cmp { + self.literal(symbol.into_literal())?; + } else { + self.uop(symbol); + } + } Symbol::None => self.stack.push(symbol), literal => self.literal(literal)?, } From 7bece70d9a88f24c8c626b0df301caa0035efb55 Mon Sep 17 00:00:00 2001 From: Martin Paulsen <43757366+georgepaulsen@users.noreply.github.com> Date: Wed, 31 Dec 2025 11:59:48 -0500 Subject: [PATCH 2/2] Add regression tests for unary operator in three-arg form --- tests/by-util/test_test.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index 4b5460cfd4a..21ea1893e99 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -1027,3 +1027,10 @@ fn test_string_lt_gt_operator() { .fails_with_code(1) .no_output(); } + +#[test] +fn test_unary_op_as_literal_in_three_arg_form() { + // `-f = a` is string comparison "-f" = "a", not file test + new_ucmd!().args(&["-f", "=", "a"]).fails_with_code(1); + new_ucmd!().args(&["-f", "=", "a", "-o", "b"]).succeeds(); +}