1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

test: -o arg should trigger an error (#6642)

* test: -o arg should trigger an error

Should fix tests/test/test-diag.pl

* test: use var directly in string

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
Sylvestre Ledru 2024-08-13 11:05:35 +02:00 committed by GitHub
parent fa03b85a47
commit 6b70dc232e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -11,6 +11,7 @@ pub enum ParseError {
MissingArgument(String),
UnknownOperator(String),
InvalidInteger(String),
UnaryOperatorExpected(String),
}
/// A Result type for parsing test expressions
@ -26,6 +27,7 @@ impl std::fmt::Display for ParseError {
Self::ExtraArgument(s) => write!(f, "extra argument {s}"),
Self::UnknownOperator(s) => write!(f, "unknown operator {s}"),
Self::InvalidInteger(s) => write!(f, "invalid integer {s}"),
Self::UnaryOperatorExpected(op) => write!(f, "{op}: unary operator expected"),
}
}
}

View file

@ -162,6 +162,10 @@ fn eval(stack: &mut Vec<Symbol>) -> ParseResult<bool> {
Some(Symbol::Literal(s)) => Ok(!s.is_empty()),
Some(Symbol::None) | None => Ok(false),
Some(Symbol::BoolOp(op)) => {
if (op == "-a" || op == "-o") && stack.len() < 2 {
return Err(ParseError::UnaryOperatorExpected(op.quote().to_string()));
}
let b = eval(stack)?;
let a = eval(stack)?;

View file

@ -67,7 +67,7 @@ fn test_double_not_is_false() {
#[test]
fn test_and_not_is_false() {
new_ucmd!().args(&["-a", "!"]).run().code_is(1);
new_ucmd!().args(&["-a", "!"]).run().code_is(2);
}
#[test]
@ -86,6 +86,18 @@ fn test_simple_or() {
new_ucmd!().args(&["foo", "-o", ""]).succeeds();
}
#[test]
fn test_errors_miss_and_or() {
new_ucmd!()
.args(&["-o", "arg"])
.fails()
.stderr_contains("'-o': unary operator expected");
new_ucmd!()
.args(&["-a", "arg"])
.fails()
.stderr_contains("'-a': unary operator expected");
}
#[test]
fn test_negated_or() {
new_ucmd!()