mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Adds failures & tests for unimplmented flags.
This commit is contained in:
parent
416488c560
commit
7f03ecf74b
2 changed files with 163 additions and 14 deletions
|
@ -7,7 +7,7 @@ use std::error::Error;
|
||||||
pub type Matches = clap::ArgMatches<'static>;
|
pub type Matches = clap::ArgMatches<'static>;
|
||||||
|
|
||||||
/// Parser Errors describe errors with parser input
|
/// Parser Errors describe errors with parser input
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum ParseError
|
pub enum ParseError
|
||||||
{
|
{
|
||||||
MultipleFmtTable,
|
MultipleFmtTable,
|
||||||
|
@ -21,6 +21,7 @@ pub enum ParseError
|
||||||
MultiplierStringWouldOverflow(String),
|
MultiplierStringWouldOverflow(String),
|
||||||
BlockUnblockWithoutCBS,
|
BlockUnblockWithoutCBS,
|
||||||
StatusLevelNotRecognized(String),
|
StatusLevelNotRecognized(String),
|
||||||
|
Unimplemented(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for ParseError
|
impl std::fmt::Display for ParseError
|
||||||
|
@ -72,6 +73,10 @@ impl std::fmt::Display for ParseError
|
||||||
{
|
{
|
||||||
write!(f, "status=LEVEL not recognized -> {}", arg)
|
write!(f, "status=LEVEL not recognized -> {}", arg)
|
||||||
},
|
},
|
||||||
|
Self::Unimplemented(arg) =>
|
||||||
|
{
|
||||||
|
write!(f, "feature not implemented on this system -> {}", arg)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,31 +198,100 @@ impl std::str::FromStr for Flag
|
||||||
Ok(Self::SkipBytes),
|
Ok(Self::SkipBytes),
|
||||||
// Either
|
// Either
|
||||||
"cio" =>
|
"cio" =>
|
||||||
Ok(Self::Cio),
|
// Ok(Self::Cio),
|
||||||
|
Err(ParseError::Unimplemented(s.to_string())),
|
||||||
"direct" =>
|
"direct" =>
|
||||||
Ok(Self::Direct),
|
// Ok(Self::Direct),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::Direct)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"directory" =>
|
"directory" =>
|
||||||
Ok(Self::Directory),
|
// Ok(Self::Directory),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::Directory)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"dsync" =>
|
"dsync" =>
|
||||||
Ok(Self::Dsync),
|
// Ok(Self::Dsync),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::Dsync)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"sync" =>
|
"sync" =>
|
||||||
Ok(Self::Sync),
|
// Ok(Self::Sync),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::Sync)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"nocache" =>
|
"nocache" =>
|
||||||
Ok(Self::NoCache),
|
// Ok(Self::NoCache),
|
||||||
|
Err(ParseError::Unimplemented(s.to_string())),
|
||||||
"nonblock" =>
|
"nonblock" =>
|
||||||
Ok(Self::NonBlock),
|
// Ok(Self::NonBlock),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::NonBlock)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"noatime" =>
|
"noatime" =>
|
||||||
Ok(Self::NoATime),
|
// Ok(Self::NoATime),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::NoATime)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"noctty" =>
|
"noctty" =>
|
||||||
Ok(Self::NoCtty),
|
// Ok(Self::NoCtty),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::NoCtty)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"nofollow" =>
|
"nofollow" =>
|
||||||
Ok(Self::NoFollow),
|
// Ok(Self::NoFollow),
|
||||||
|
if cfg!(unix)
|
||||||
|
{
|
||||||
|
Ok(Self::NoFollow)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Err(ParseError::Unimplemented(s.to_string()))
|
||||||
|
},
|
||||||
"nolinks" =>
|
"nolinks" =>
|
||||||
Ok(Self::NoLinks),
|
// Ok(Self::NoLinks),
|
||||||
|
Err(ParseError::Unimplemented(s.to_string())),
|
||||||
"binary" =>
|
"binary" =>
|
||||||
Ok(Self::Binary),
|
// Ok(Self::Binary),
|
||||||
|
Err(ParseError::Unimplemented(s.to_string())),
|
||||||
"text" =>
|
"text" =>
|
||||||
Ok(Self::Text),
|
// Ok(Self::Text),
|
||||||
|
Err(ParseError::Unimplemented(s.to_string())),
|
||||||
// Output only
|
// Output only
|
||||||
"append" =>
|
"append" =>
|
||||||
Ok(Self::Append),
|
Ok(Self::Append),
|
||||||
|
|
|
@ -5,6 +5,81 @@ use crate::{
|
||||||
StatusLevel,
|
StatusLevel,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
#[test]
|
||||||
|
fn unimplemented_flags_should_error_non_unix()
|
||||||
|
{
|
||||||
|
let mut unfailed = Vec::new();
|
||||||
|
|
||||||
|
// The following flags are only implemented in unix
|
||||||
|
for flag in vec!["direct", "directory", "dsync", "sync", "nonblock", "noatime", "noctty", "nofollow"]
|
||||||
|
{
|
||||||
|
let args = vec![
|
||||||
|
String::from("dd"),
|
||||||
|
format!("--iflag={}", flag),
|
||||||
|
format!("--oflag={}", flag),
|
||||||
|
];
|
||||||
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
match parse_iflags(&matches)
|
||||||
|
{
|
||||||
|
Ok(_) =>
|
||||||
|
unfailed.push(format!("iflag={}", flag)),
|
||||||
|
Err(_) =>
|
||||||
|
{/* expected behaviour :-) */},
|
||||||
|
}
|
||||||
|
match parse_oflags(&matches)
|
||||||
|
{
|
||||||
|
Ok(_) =>
|
||||||
|
unfailed.push(format!("oflag={}", flag)),
|
||||||
|
Err(_) =>
|
||||||
|
{/* expected behaviour :-) */},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !unfailed.is_empty()
|
||||||
|
{
|
||||||
|
panic!("The following flags did not panic as expected: {:?}", unfailed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn unimplemented_flags_should_error()
|
||||||
|
{
|
||||||
|
let mut unfailed = Vec::new();
|
||||||
|
|
||||||
|
// The following flags are not implemented
|
||||||
|
for flag in vec!["cio", "nocache", "nolinks", "text", "binary"]
|
||||||
|
{
|
||||||
|
let args = vec![
|
||||||
|
String::from("dd"),
|
||||||
|
format!("--iflag={}", flag),
|
||||||
|
format!("--oflag={}", flag),
|
||||||
|
];
|
||||||
|
let matches = build_dd_app!().get_matches_from_safe(args).unwrap();
|
||||||
|
|
||||||
|
match parse_iflags(&matches)
|
||||||
|
{
|
||||||
|
Ok(_) =>
|
||||||
|
unfailed.push(format!("iflag={}", flag)),
|
||||||
|
Err(_) =>
|
||||||
|
{/* expected behaviour :-) */},
|
||||||
|
}
|
||||||
|
match parse_oflags(&matches)
|
||||||
|
{
|
||||||
|
Ok(_) =>
|
||||||
|
unfailed.push(format!("oflag={}", flag)),
|
||||||
|
Err(_) =>
|
||||||
|
{/* expected behaviour :-) */},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !unfailed.is_empty()
|
||||||
|
{
|
||||||
|
panic!("The following flags did not panic as expected: {:?}", unfailed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_level_absent()
|
fn test_status_level_absent()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue