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

Ignores linux-only tests on non-linux platforms.

This commit is contained in:
Tyler 2021-07-21 18:24:31 -07:00
parent 95d9f03cff
commit 989849eca7
3 changed files with 99 additions and 129 deletions

View file

@ -943,7 +943,7 @@ fn dd_fileout<R: Read>(mut i: Input<R>, mut o: Output<File>) -> Result<(), Box<d
} }
fn append_dashes_if_not_present(mut acc: Vec<String>, mut s: String) -> Vec<String> { fn append_dashes_if_not_present(mut acc: Vec<String>, mut s: String) -> Vec<String> {
if !s.starts_with("--") && !s.starts_with("-") { if !s.starts_with("--") && !s.starts_with('-') {
s.insert_str(0, "--"); s.insert_str(0, "--");
} }
acc.push(s); acc.push(s);

View file

@ -508,170 +508,136 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result<IConvFlags, ParseError
/// Parse Conversion Options (Output Variety) /// Parse Conversion Options (Output Variety)
/// Construct and validate a OConvFlags /// Construct and validate a OConvFlags
pub fn parse_conv_flag_output(matches: &Matches) -> Result<OConvFlags, ParseError> { pub fn parse_conv_flag_output(matches: &Matches) -> Result<OConvFlags, ParseError> {
let flags = parse_flag_list("conv", matches)?; let flags = parse_flag_list(options::CONV, matches)?;
let mut sparse = false; let mut oconvflags = OConvFlags {
let mut excl = false; sparse: false,
let mut nocreat = false; excl: false,
let mut notrunc = false; nocreat: false,
let mut fdatasync = false; notrunc: false,
let mut fsync = false; fdatasync: false,
fsync: false,
};
for flag in flags { for flag in flags {
match flag { match flag {
ConvFlag::Sparse => sparse = true, ConvFlag::Sparse => oconvflags.sparse = true,
ConvFlag::Excl => { ConvFlag::Excl => {
if !nocreat { if !oconvflags.nocreat {
excl = true; oconvflags.excl = true;
} else { } else {
return Err(ParseError::MultipleExclNoCreat); return Err(ParseError::MultipleExclNoCreat);
} }
} }
ConvFlag::NoCreat => { ConvFlag::NoCreat => {
if !excl { if !oconvflags.excl {
nocreat = true; oconvflags.nocreat = true;
} else { } else {
return Err(ParseError::MultipleExclNoCreat); return Err(ParseError::MultipleExclNoCreat);
} }
} }
ConvFlag::NoTrunc => notrunc = true, ConvFlag::NoTrunc => oconvflags.notrunc = true,
ConvFlag::FDataSync => fdatasync = true, ConvFlag::FDataSync => oconvflags.fdatasync = true,
ConvFlag::FSync => fsync = true, ConvFlag::FSync => oconvflags.fsync = true,
_ => {} _ => {}
} }
} }
Ok(OConvFlags { Ok(oconvflags)
sparse,
excl,
nocreat,
notrunc,
fdatasync,
fsync,
})
} }
/// Parse IFlags struct from CL-input /// Parse IFlags struct from CL-input
pub fn parse_iflags(matches: &Matches) -> Result<IFlags, ParseError> { pub fn parse_iflags(matches: &Matches) -> Result<IFlags, ParseError> {
let mut cio = false; let mut iflags = IFlags {
let mut direct = false; cio: false,
let mut directory = false; direct: false,
let mut dsync = false; directory: false,
let mut sync = false; dsync: false,
let mut nocache = false; sync: false,
let mut nonblock = false; nocache: false,
let mut noatime = false; nonblock: false,
let mut noctty = false; noatime: false,
let mut nofollow = false; noctty: false,
let mut nolinks = false; nofollow: false,
let mut binary = false; nolinks: false,
let mut text = false; binary: false,
let mut fullblock = false; text: false,
let mut count_bytes = false; fullblock: false,
let mut skip_bytes = false; count_bytes: false,
skip_bytes: false,
};
let flags = parse_flag_list("iflag", matches)?; let flags = parse_flag_list(options::IFLAG, matches)?;
for flag in flags { for flag in flags {
match flag { match flag {
Flag::Cio => cio = true, Flag::Cio => iflags.cio = true,
Flag::Direct => direct = true, Flag::Direct => iflags.direct = true,
Flag::Directory => directory = true, Flag::Directory => iflags.directory = true,
Flag::Dsync => dsync = true, Flag::Dsync => iflags.dsync = true,
Flag::Sync => sync = true, Flag::Sync => iflags.sync = true,
Flag::NoCache => nocache = true, Flag::NoCache => iflags.nocache = true,
Flag::NonBlock => nonblock = true, Flag::NonBlock => iflags.nonblock = true,
Flag::NoATime => noatime = true, Flag::NoATime => iflags.noatime = true,
Flag::NoCtty => noctty = true, Flag::NoCtty => iflags.noctty = true,
Flag::NoFollow => nofollow = true, Flag::NoFollow => iflags.nofollow = true,
Flag::NoLinks => nolinks = true, Flag::NoLinks => iflags.nolinks = true,
Flag::Binary => binary = true, Flag::Binary => iflags.binary = true,
Flag::Text => text = true, Flag::Text => iflags.text = true,
Flag::FullBlock => fullblock = true, Flag::FullBlock => iflags.fullblock = true,
Flag::CountBytes => count_bytes = true, Flag::CountBytes => iflags.count_bytes = true,
Flag::SkipBytes => skip_bytes = true, Flag::SkipBytes => iflags.skip_bytes = true,
_ => {} _ => {}
} }
} }
Ok(IFlags { Ok(iflags)
cio,
direct,
directory,
dsync,
sync,
nocache,
nonblock,
noatime,
noctty,
nofollow,
nolinks,
binary,
text,
fullblock,
count_bytes,
skip_bytes,
})
} }
/// Parse OFlags struct from CL-input /// Parse OFlags struct from CL-input
pub fn parse_oflags(matches: &Matches) -> Result<OFlags, ParseError> { pub fn parse_oflags(matches: &Matches) -> Result<OFlags, ParseError> {
let mut append = false; let mut oflags = OFlags {
let mut cio = false; append: false,
let mut direct = false; cio: false,
let mut directory = false; direct: false,
let mut dsync = false; directory: false,
let mut sync = false; dsync: false,
let mut nocache = false; sync: false,
let mut nonblock = false; nocache: false,
let mut noatime = false; nonblock: false,
let mut noctty = false; noatime: false,
let mut nofollow = false; noctty: false,
let mut nolinks = false; nofollow: false,
let mut binary = false; nolinks: false,
let mut text = false; binary: false,
let mut seek_bytes = false; text: false,
seek_bytes: false,
};
let flags = parse_flag_list("oflag", matches)?; let flags = parse_flag_list(options::OFLAG, matches)?;
for flag in flags { for flag in flags {
match flag { match flag {
Flag::Append => append = true, Flag::Append => oflags.append = true,
Flag::Cio => cio = true, Flag::Cio => oflags.cio = true,
Flag::Direct => direct = true, Flag::Direct => oflags.direct = true,
Flag::Directory => directory = true, Flag::Directory => oflags.directory = true,
Flag::Dsync => dsync = true, Flag::Dsync => oflags.dsync = true,
Flag::Sync => sync = true, Flag::Sync => oflags.sync = true,
Flag::NoCache => nocache = true, Flag::NoCache => oflags.nocache = true,
Flag::NonBlock => nonblock = true, Flag::NonBlock => oflags.nonblock = true,
Flag::NoATime => noatime = true, Flag::NoATime => oflags.noatime = true,
Flag::NoCtty => noctty = true, Flag::NoCtty => oflags.noctty = true,
Flag::NoFollow => nofollow = true, Flag::NoFollow => oflags.nofollow = true,
Flag::NoLinks => nolinks = true, Flag::NoLinks => oflags.nolinks = true,
Flag::Binary => binary = true, Flag::Binary => oflags.binary = true,
Flag::Text => text = true, Flag::Text => oflags.text = true,
Flag::SeekBytes => seek_bytes = true, Flag::SeekBytes => oflags.seek_bytes = true,
_ => {} _ => {}
} }
} }
Ok(OFlags { Ok(oflags)
append,
cio,
direct,
directory,
dsync,
sync,
nocache,
nonblock,
noatime,
noctty,
nofollow,
nolinks,
binary,
text,
seek_bytes,
})
} }
/// Parse the amount of the input file to skip. /// Parse the amount of the input file to skip.
@ -680,7 +646,7 @@ pub fn parse_skip_amt(
iflags: &IFlags, iflags: &IFlags,
matches: &Matches, matches: &Matches,
) -> Result<Option<usize>, ParseError> { ) -> Result<Option<usize>, ParseError> {
if let Some(amt) = matches.value_of("skip") { if let Some(amt) = matches.value_of(options::SKIP) {
let n = parse_bytes_with_opt_multiplier(amt)?; let n = parse_bytes_with_opt_multiplier(amt)?;
if iflags.skip_bytes { if iflags.skip_bytes {
Ok(Some(n)) Ok(Some(n))
@ -698,7 +664,7 @@ pub fn parse_seek_amt(
oflags: &OFlags, oflags: &OFlags,
matches: &Matches, matches: &Matches,
) -> Result<Option<usize>, ParseError> { ) -> Result<Option<usize>, ParseError> {
if let Some(amt) = matches.value_of("seek") { if let Some(amt) = matches.value_of(options::SEEK) {
let n = parse_bytes_with_opt_multiplier(amt)?; let n = parse_bytes_with_opt_multiplier(amt)?;
if oflags.seek_bytes { if oflags.seek_bytes {
Ok(Some(n)) Ok(Some(n))
@ -712,7 +678,7 @@ pub fn parse_seek_amt(
/// Parse the value of count=N and the type of N implied by iflags /// Parse the value of count=N and the type of N implied by iflags
pub fn parse_count(iflags: &IFlags, matches: &Matches) -> Result<Option<CountType>, ParseError> { pub fn parse_count(iflags: &IFlags, matches: &Matches) -> Result<Option<CountType>, ParseError> {
if let Some(amt) = matches.value_of("count") { if let Some(amt) = matches.value_of(options::COUNT) {
let n = parse_bytes_with_opt_multiplier(amt)?; let n = parse_bytes_with_opt_multiplier(amt)?;
if iflags.count_bytes { if iflags.count_bytes {
Ok(Some(CountType::Bytes(n))) Ok(Some(CountType::Bytes(n)))
@ -726,7 +692,7 @@ pub fn parse_count(iflags: &IFlags, matches: &Matches) -> Result<Option<CountTyp
/// Parse whether the args indicate the input is not ascii /// Parse whether the args indicate the input is not ascii
pub fn parse_input_non_ascii(matches: &Matches) -> Result<bool, ParseError> { pub fn parse_input_non_ascii(matches: &Matches) -> Result<bool, ParseError> {
if let Some(conv_opts) = matches.value_of("conv") { if let Some(conv_opts) = matches.value_of(options::CONV) {
Ok(conv_opts.contains("ascii")) Ok(conv_opts.contains("ascii"))
} else { } else {
Ok(false) Ok(false)

View file

@ -202,6 +202,7 @@ fn test_final_stats_unspec() {
new_ucmd!().run().stderr_only(&output).success(); new_ucmd!().run().stderr_only(&output).success();
} }
#[cfg(target_os = "linux")]
#[test] #[test]
fn test_excl_causes_failure_when_present() { fn test_excl_causes_failure_when_present() {
let fname = "this-file-exists-excl.txt"; let fname = "this-file-exists-excl.txt";
@ -212,7 +213,7 @@ fn test_excl_causes_failure_when_present() {
.fails(); .fails();
} }
#[ignore] #[cfg(target_os = "linux")]
#[test] #[test]
fn test_atime_updated() { fn test_atime_updated() {
let fname = "this-file-exists-no-noatime.txt"; let fname = "this-file-exists-no-noatime.txt";
@ -230,6 +231,7 @@ fn test_atime_updated() {
assert!(pre_atime != post_atime); assert!(pre_atime != post_atime);
} }
#[cfg(target_os = "linux")]
#[test] #[test]
fn test_noatime_does_not_update_infile_atime() { fn test_noatime_does_not_update_infile_atime() {
let fname = "this-ifile-exists-noatime.txt"; let fname = "this-ifile-exists-noatime.txt";
@ -246,6 +248,7 @@ fn test_noatime_does_not_update_infile_atime() {
assert_eq!(pre_atime, post_atime); assert_eq!(pre_atime, post_atime);
} }
#[cfg(target_os = "linux")]
#[test] #[test]
fn test_noatime_does_not_update_ofile_atime() { fn test_noatime_does_not_update_ofile_atime() {
let fname = "this-ofile-exists-noatime.txt"; let fname = "this-ofile-exists-noatime.txt";
@ -262,6 +265,7 @@ fn test_noatime_does_not_update_ofile_atime() {
assert_eq!(pre_atime, post_atime); assert_eq!(pre_atime, post_atime);
} }
#[cfg(target_os = "linux")]
#[test] #[test]
fn test_nocreat_causes_failure_when_outfile_not_present() { fn test_nocreat_causes_failure_when_outfile_not_present() {
let fname = "this-file-does-not-exist.txt"; let fname = "this-file-does-not-exist.txt";
@ -345,7 +349,7 @@ fn test_null_fullblock() {
} }
#[cfg(unix)] #[cfg(unix)]
// #[ignore] // See note below before running this test! #[ignore] // See note below before using this test.
#[test] #[test]
fn test_fullblock() { fn test_fullblock() {
let tname = "fullblock-from-urand"; let tname = "fullblock-from-urand";