mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
test: move to thiserror
This commit is contained in:
parent
6ca60cf2c7
commit
09bb35e11e
4 changed files with 14 additions and 19 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3578,6 +3578,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
|
"thiserror 2.0.12",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
1
fuzz/Cargo.lock
generated
1
fuzz/Cargo.lock
generated
|
@ -1379,6 +1379,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"libc",
|
"libc",
|
||||||
|
"thiserror",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ path = "src/test.rs"
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
libc = { workspace = true }
|
libc = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["process"] }
|
uucore = { workspace = true, features = ["process"] }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "test"
|
name = "test"
|
||||||
|
|
|
@ -2,42 +2,34 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
/// Represents an error encountered while parsing a test expression
|
/// Represents an error encountered while parsing a test expression
|
||||||
#[derive(Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
|
#[error("expected value")]
|
||||||
ExpectedValue,
|
ExpectedValue,
|
||||||
|
#[error("expected {0}")]
|
||||||
Expected(String),
|
Expected(String),
|
||||||
|
#[error("extra argument {0}")]
|
||||||
ExtraArgument(String),
|
ExtraArgument(String),
|
||||||
|
#[error("missing argument after {0}")]
|
||||||
MissingArgument(String),
|
MissingArgument(String),
|
||||||
|
#[error("unknown operator {0}")]
|
||||||
UnknownOperator(String),
|
UnknownOperator(String),
|
||||||
|
#[error("invalid integer {0}")]
|
||||||
InvalidInteger(String),
|
InvalidInteger(String),
|
||||||
|
#[error("{0}: unary operator expected")]
|
||||||
UnaryOperatorExpected(String),
|
UnaryOperatorExpected(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Result type for parsing test expressions
|
/// A Result type for parsing test expressions
|
||||||
pub type ParseResult<T> = Result<T, ParseError>;
|
pub type ParseResult<T> = Result<T, ParseError>;
|
||||||
|
|
||||||
/// Implement Display trait for ParseError to make it easier to print useful errors.
|
|
||||||
impl std::fmt::Display for ParseError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::Expected(s) => write!(f, "expected {s}"),
|
|
||||||
Self::ExpectedValue => write!(f, "expected value"),
|
|
||||||
Self::MissingArgument(s) => write!(f, "missing argument after {s}"),
|
|
||||||
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"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Implement UError trait for ParseError to make it easier to return useful error codes from main().
|
/// Implement UError trait for ParseError to make it easier to return useful error codes from main().
|
||||||
impl uucore::error::UError for ParseError {
|
impl uucore::error::UError for ParseError {
|
||||||
fn code(&self) -> i32 {
|
fn code(&self) -> i32 {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Implement standard Error trait for UError
|
|
||||||
impl std::error::Error for ParseError {}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue