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

fix a lot of clippy warnings

This commit is contained in:
Jan Scheer 2021-05-29 14:32:35 +02:00
parent fb812ff9d0
commit 3aeccfd802
48 changed files with 269 additions and 250 deletions

View file

@ -136,7 +136,8 @@ fn basename(fullname: &str, suffix: &str) -> String {
} }
} }
// can be replaced with strip_suffix once the minimum rust version is 1.45 // can be replaced with strip_suffix once MSRV is 1.45
#[allow(clippy::manual_strip)]
fn strip_suffix(name: &str, suffix: &str) -> String { fn strip_suffix(name: &str, suffix: &str) -> String {
if name == suffix { if name == suffix {
return name.to_owned(); return name.to_owned();

View file

@ -1108,7 +1108,7 @@ fn context_for(src: &Path, dest: &Path) -> String {
/// Implements a simple backup copy for the destination file. /// Implements a simple backup copy for the destination file.
/// TODO: for the backup, should this function be replaced by `copy_file(...)`? /// TODO: for the backup, should this function be replaced by `copy_file(...)`?
fn backup_dest(dest: &Path, backup_path: &PathBuf) -> CopyResult<PathBuf> { fn backup_dest(dest: &Path, backup_path: &Path) -> CopyResult<PathBuf> {
fs::copy(dest, &backup_path)?; fs::copy(dest, &backup_path)?;
Ok(backup_path.into()) Ok(backup_path.into())
} }

View file

@ -30,7 +30,7 @@ impl Iterator for Sieve {
#[inline] #[inline]
fn next(&mut self) -> Option<u64> { fn next(&mut self) -> Option<u64> {
while let Some(n) = self.inner.next() { for n in &mut self.inner {
let mut prime = true; let mut prime = true;
while let Some((next, inc)) = self.filts.peek() { while let Some((next, inc)) = self.filts.peek() {
// need to keep checking the min element of the heap // need to keep checking the min element of the heap

View file

@ -14,7 +14,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
let mut num_end = 0usize; let mut num_end = 0usize;
let mut has_num = false; let mut has_num = false;
let mut last_char = 0 as char; let mut last_char = 0 as char;
while let Some((n, c)) = chars.next() { for (n, c) in &mut chars {
if c.is_numeric() { if c.is_numeric() {
has_num = true; has_num = true;
num_end = n; num_end = n;
@ -109,7 +109,7 @@ pub fn parse_num(src: &str) -> Result<(usize, bool), ParseError> {
let mut num_end = 0usize; let mut num_end = 0usize;
let mut last_char = 0 as char; let mut last_char = 0 as char;
let mut num_count = 0usize; let mut num_count = 0usize;
while let Some((n, c)) = chars.next() { for (n, c) in &mut chars {
if c.is_numeric() { if c.is_numeric() {
num_end = n; num_end = n;
num_count += 1; num_count += 1;

View file

@ -520,6 +520,7 @@ fn copy_file_to_file(file: &Path, target: &Path, b: &Behavior) -> i32 {
/// ///
/// If the copy system call fails, we print a verbose error and return an empty error value. /// If the copy system call fails, we print a verbose error and return an empty error value.
/// ///
#[allow(clippy::cognitive_complexity)]
fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> { fn copy(from: &Path, to: &Path, b: &Behavior) -> Result<(), ()> {
if b.compare && !need_copy(from, to, b) { if b.compare && !need_copy(from, to, b) {
return Ok(()); return Ok(());

View file

@ -218,6 +218,7 @@ struct LongFormat {
} }
impl Config { impl Config {
#[allow(clippy::cognitive_complexity)]
fn from(options: clap::ArgMatches) -> Config { fn from(options: clap::ArgMatches) -> Config {
let (mut format, opt) = if let Some(format_) = options.value_of(options::FORMAT) { let (mut format, opt) = if let Some(format_) = options.value_of(options::FORMAT) {
( (

View file

@ -73,6 +73,7 @@ impl Chunk {
/// * `lines`: The recycled vector to fill with lines. Must be empty. /// * `lines`: The recycled vector to fill with lines. Must be empty.
/// * `settings`: The global settings. /// * `settings`: The global settings.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[allow(clippy::borrowed_box)]
pub fn read( pub fn read(
sender_option: &mut Option<SyncSender<Chunk>>, sender_option: &mut Option<SyncSender<Chunk>>,
mut buffer: Vec<u8>, mut buffer: Vec<u8>,
@ -164,6 +165,7 @@ fn parse_lines<'a>(
/// The remaining bytes must be copied to the start of the buffer for the next invocation, /// The remaining bytes must be copied to the start of the buffer for the next invocation,
/// if another invocation is necessary, which is determined by the other return value. /// if another invocation is necessary, which is determined by the other return value.
/// * Whether this function should be called again. /// * Whether this function should be called again.
#[allow(clippy::borrowed_box)]
fn read_to_buffer( fn read_to_buffer(
file: &mut Box<dyn Read + Send>, file: &mut Box<dyn Read + Send>,
next_files: &mut impl Iterator<Item = Box<dyn Read + Send>>, next_files: &mut impl Iterator<Item = Box<dyn Read + Send>>,

View file

@ -200,6 +200,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
split(&settings) split(&settings)
} }
#[allow(dead_code)]
struct Settings { struct Settings {
prefix: String, prefix: String,
numeric_suffix: bool, numeric_suffix: bool,
@ -210,7 +211,7 @@ struct Settings {
filter: Option<String>, filter: Option<String>,
strategy: String, strategy: String,
strategy_param: String, strategy_param: String,
verbose: bool, verbose: bool, // TODO: warning: field is never read: `verbose`
} }
trait Splitter { trait Splitter {

View file

@ -199,6 +199,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} }
} }
#[allow(clippy::if_same_then_else)]
if matches.is_present(options::FILE_SYSTEM) { if matches.is_present(options::FILE_SYSTEM) {
#[cfg(any(target_os = "linux", target_os = "windows"))] #[cfg(any(target_os = "linux", target_os = "windows"))]
syncfs(files); syncfs(files);

View file

@ -265,11 +265,10 @@ impl Parser {
fn boolop(&mut self, op: Symbol) { fn boolop(&mut self, op: Symbol) {
if op == Symbol::BoolOp(OsString::from("-a")) { if op == Symbol::BoolOp(OsString::from("-a")) {
self.term(); self.term();
self.stack.push(op);
} else { } else {
self.expr(); self.expr();
self.stack.push(op);
} }
self.stack.push(op);
} }
/// Parse a (possible) unary argument test (string length or file /// Parse a (possible) unary argument test (string length or file

View file

@ -145,14 +145,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|| matches.is_present(options::sources::CURRENT) || matches.is_present(options::sources::CURRENT)
{ {
let timestamp = if matches.is_present(options::sources::DATE) { let timestamp = if matches.is_present(options::sources::DATE) {
parse_date(matches.value_of(options::sources::DATE).unwrap().as_ref()) parse_date(matches.value_of(options::sources::DATE).unwrap())
} else { } else {
parse_timestamp( parse_timestamp(matches.value_of(options::sources::CURRENT).unwrap())
matches
.value_of(options::sources::CURRENT)
.unwrap()
.as_ref(),
)
}; };
(timestamp, timestamp) (timestamp, timestamp)
} else { } else {

View file

@ -110,7 +110,7 @@ impl<'a> Iterator for ExpandSet<'a> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
// while the Range has elements, try to return chars from it // while the Range has elements, try to return chars from it
// but make sure that they actually turn out to be Chars! // but make sure that they actually turn out to be Chars!
while let Some(n) = self.range.next() { for n in &mut self.range {
if let Some(c) = from_u32(n) { if let Some(c) = from_u32(n) {
return Some(c); return Some(c);
} }

View file

@ -551,10 +551,11 @@ impl Who {
" ?".into() " ?".into()
}; };
let mut s = ut.host(); let s = if self.do_lookup {
if self.do_lookup { safe_unwrap!(ut.canon_host())
s = safe_unwrap!(ut.canon_host()); } else {
} ut.host()
};
let hoststr = if s.is_empty() { s } else { format!("({})", s) }; let hoststr = if s.is_empty() { s } else { format!("({})", s) };
self.print_line( self.print_line(

View file

@ -179,7 +179,7 @@ impl MountInfo {
/* for Irix 6.5 */ /* for Irix 6.5 */
| "ignore" => self.dummy = true, | "ignore" => self.dummy = true,
_ => self.dummy = self.fs_type == "none" _ => self.dummy = self.fs_type == "none"
&& self.mount_option.find(MOUNT_OPT_BIND).is_none(), && !self.mount_option.contains(MOUNT_OPT_BIND)
} }
// set MountInfo::remote // set MountInfo::remote
#[cfg(windows)] #[cfg(windows)]

View file

@ -40,6 +40,7 @@ pub enum ExitStatus {
Signal(i32), Signal(i32),
} }
#[allow(clippy::trivially_copy_pass_by_ref)]
impl ExitStatus { impl ExitStatus {
fn from_std_status(status: StdExitStatus) -> Self { fn from_std_status(status: StdExitStatus) -> Self {
#[cfg(unix)] #[cfg(unix)]

View file

@ -34,7 +34,7 @@ fn test_base32_encode_file() {
#[test] #[test]
fn test_decode() { fn test_decode() {
for decode_param in vec!["-d", "--decode"] { for decode_param in &["-d", "--decode"] {
let input = "JBSWY3DPFQQFO33SNRSCC===\n"; let input = "JBSWY3DPFQQFO33SNRSCC===\n";
new_ucmd!() new_ucmd!()
.arg(decode_param) .arg(decode_param)
@ -56,7 +56,7 @@ fn test_garbage() {
#[test] #[test]
fn test_ignore_garbage() { fn test_ignore_garbage() {
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] { for ignore_garbage_param in &["-i", "--ignore-garbage"] {
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n"; let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n";
new_ucmd!() new_ucmd!()
.arg("-d") .arg("-d")
@ -69,7 +69,7 @@ fn test_ignore_garbage() {
#[test] #[test]
fn test_wrap() { fn test_wrap() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
let input = "The quick brown fox jumps over the lazy dog."; let input = "The quick brown fox jumps over the lazy dog.";
new_ucmd!() new_ucmd!()
.arg(wrap_param) .arg(wrap_param)
@ -84,16 +84,21 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
new_ucmd!().arg(wrap_param).fails().stderr_only(format!( let expected_stderr = "error: The argument '--wrap <wrap>\' requires a value but none was \
"error: The argument '--wrap <wrap>\' requires a value but none was supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more information try --help" supplied\n\nUSAGE:\n base32 [OPTION]... [FILE]\n\nFor more \
)); information try --help"
.to_string();
new_ucmd!()
.arg(wrap_param)
.fails()
.stderr_only(expected_stderr);
} }
} }
#[test] #[test]
fn test_wrap_bad_arg() { fn test_wrap_bad_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
new_ucmd!() new_ucmd!()
.arg(wrap_param) .arg(wrap_param)
.arg("b") .arg("b")

View file

@ -26,7 +26,7 @@ fn test_base64_encode_file() {
#[test] #[test]
fn test_decode() { fn test_decode() {
for decode_param in vec!["-d", "--decode"] { for decode_param in &["-d", "--decode"] {
let input = "aGVsbG8sIHdvcmxkIQ=="; let input = "aGVsbG8sIHdvcmxkIQ==";
new_ucmd!() new_ucmd!()
.arg(decode_param) .arg(decode_param)
@ -48,7 +48,7 @@ fn test_garbage() {
#[test] #[test]
fn test_ignore_garbage() { fn test_ignore_garbage() {
for ignore_garbage_param in vec!["-i", "--ignore-garbage"] { for ignore_garbage_param in &["-i", "--ignore-garbage"] {
let input = "aGVsbG8sIHdvcmxkIQ==\0"; let input = "aGVsbG8sIHdvcmxkIQ==\0";
new_ucmd!() new_ucmd!()
.arg("-d") .arg("-d")
@ -61,7 +61,7 @@ fn test_ignore_garbage() {
#[test] #[test]
fn test_wrap() { fn test_wrap() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
let input = "The quick brown fox jumps over the lazy dog."; let input = "The quick brown fox jumps over the lazy dog.";
new_ucmd!() new_ucmd!()
.arg(wrap_param) .arg(wrap_param)
@ -74,7 +74,7 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
new_ucmd!().arg(wrap_param).fails().stderr_contains( new_ucmd!().arg(wrap_param).fails().stderr_contains(
&"The argument '--wrap <wrap>' requires a value but none was supplied", &"The argument '--wrap <wrap>' requires a value but none was supplied",
); );
@ -83,7 +83,7 @@ fn test_wrap_no_arg() {
#[test] #[test]
fn test_wrap_bad_arg() { fn test_wrap_bad_arg() {
for wrap_param in vec!["-w", "--wrap"] { for wrap_param in &["-w", "--wrap"] {
new_ucmd!() new_ucmd!()
.arg(wrap_param) .arg(wrap_param)
.arg("b") .arg("b")

View file

@ -4,7 +4,7 @@ use std::ffi::OsStr;
#[test] #[test]
fn test_help() { fn test_help() {
for help_flg in vec!["-h", "--help"] { for help_flg in &["-h", "--help"] {
new_ucmd!() new_ucmd!()
.arg(&help_flg) .arg(&help_flg)
.succeeds() .succeeds()
@ -15,7 +15,7 @@ fn test_help() {
#[test] #[test]
fn test_version() { fn test_version() {
for version_flg in vec!["-V", "--version"] { for version_flg in &["-V", "--version"] {
assert!(new_ucmd!() assert!(new_ucmd!()
.arg(&version_flg) .arg(&version_flg)
.succeeds() .succeeds()
@ -59,7 +59,7 @@ fn test_dont_remove_suffix() {
#[test] #[test]
fn test_multiple_param() { fn test_multiple_param() {
for multiple_param in vec!["-a", "--multiple"] { for &multiple_param in &["-a", "--multiple"] {
let path = "/foo/bar/baz"; let path = "/foo/bar/baz";
new_ucmd!() new_ucmd!()
.args(&[multiple_param, path, path]) .args(&[multiple_param, path, path])
@ -70,7 +70,7 @@ fn test_multiple_param() {
#[test] #[test]
fn test_suffix_param() { fn test_suffix_param() {
for suffix_param in vec!["-s", "--suffix"] { for &suffix_param in &["-s", "--suffix"] {
let path = "/foo/bar/baz.exe"; let path = "/foo/bar/baz.exe";
new_ucmd!() new_ucmd!()
.args(&[suffix_param, ".exe", path, path]) .args(&[suffix_param, ".exe", path, path])
@ -81,7 +81,7 @@ fn test_suffix_param() {
#[test] #[test]
fn test_zero_param() { fn test_zero_param() {
for zero_param in vec!["-z", "--zero"] { for &zero_param in &["-z", "--zero"] {
let path = "/foo/bar/baz"; let path = "/foo/bar/baz";
new_ucmd!() new_ucmd!()
.args(&[zero_param, "-a", path, path]) .args(&[zero_param, "-a", path, path])
@ -91,7 +91,12 @@ fn test_zero_param() {
} }
fn expect_error(input: Vec<&str>) { fn expect_error(input: Vec<&str>) {
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr().len() > 0); assert!(!new_ucmd!()
.args(&input)
.fails()
.no_stdout()
.stderr_str()
.is_empty());
} }
#[test] #[test]

View file

@ -237,7 +237,7 @@ fn test_numbered_lines_no_trailing_newline() {
#[test] #[test]
fn test_stdin_show_nonprinting() { fn test_stdin_show_nonprinting() {
for same_param in vec!["-v", "--show-nonprinting"] { for same_param in &["-v", "--show-nonprinting"] {
new_ucmd!() new_ucmd!()
.args(&[same_param]) .args(&[same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
@ -248,7 +248,7 @@ fn test_stdin_show_nonprinting() {
#[test] #[test]
fn test_stdin_show_tabs() { fn test_stdin_show_tabs() {
for same_param in vec!["-T", "--show-tabs"] { for same_param in &["-T", "--show-tabs"] {
new_ucmd!() new_ucmd!()
.args(&[same_param]) .args(&[same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
@ -259,7 +259,7 @@ fn test_stdin_show_tabs() {
#[test] #[test]
fn test_stdin_show_ends() { fn test_stdin_show_ends() {
for same_param in vec!["-E", "--show-ends"] { for &same_param in &["-E", "--show-ends"] {
new_ucmd!() new_ucmd!()
.args(&[same_param, "-"]) .args(&[same_param, "-"])
.pipe_in("\t\0\n\t") .pipe_in("\t\0\n\t")
@ -270,7 +270,7 @@ fn test_stdin_show_ends() {
#[test] #[test]
fn test_stdin_show_all() { fn test_stdin_show_all() {
for same_param in vec!["-A", "--show-all"] { for same_param in &["-A", "--show-all"] {
new_ucmd!() new_ucmd!()
.args(&[same_param]) .args(&[same_param])
.pipe_in("\t\0\n") .pipe_in("\t\0\n")
@ -299,7 +299,7 @@ fn test_stdin_nonprinting_and_tabs() {
#[test] #[test]
fn test_stdin_squeeze_blank() { fn test_stdin_squeeze_blank() {
for same_param in vec!["-s", "--squeeze-blank"] { for same_param in &["-s", "--squeeze-blank"] {
new_ucmd!() new_ucmd!()
.arg(same_param) .arg(same_param)
.pipe_in("\n\na\n\n\n\n\nb\n\n\n") .pipe_in("\n\na\n\n\n\n\nb\n\n\n")
@ -310,7 +310,7 @@ fn test_stdin_squeeze_blank() {
#[test] #[test]
fn test_stdin_number_non_blank() { fn test_stdin_number_non_blank() {
for same_param in vec!["-b", "--number-nonblank"] { for same_param in &["-b", "--number-nonblank"] {
new_ucmd!() new_ucmd!()
.arg(same_param) .arg(same_param)
.arg("-") .arg("-")
@ -322,7 +322,7 @@ fn test_stdin_number_non_blank() {
#[test] #[test]
fn test_non_blank_overrides_number() { fn test_non_blank_overrides_number() {
for same_param in vec!["-b", "--number-nonblank"] { for &same_param in &["-b", "--number-nonblank"] {
new_ucmd!() new_ucmd!()
.args(&[same_param, "-"]) .args(&[same_param, "-"])
.pipe_in("\na\nb\n\n\nc") .pipe_in("\na\nb\n\n\nc")
@ -333,7 +333,7 @@ fn test_non_blank_overrides_number() {
#[test] #[test]
fn test_squeeze_blank_before_numbering() { fn test_squeeze_blank_before_numbering() {
for same_param in vec!["-s", "--squeeze-blank"] { for &same_param in &["-s", "--squeeze-blank"] {
new_ucmd!() new_ucmd!()
.args(&[same_param, "-n", "-"]) .args(&[same_param, "-n", "-"])
.pipe_in("a\n\n\nb") .pipe_in("a\n\n\nb")
@ -408,7 +408,10 @@ fn test_domain_socket() {
use std::thread; use std::thread;
use unix_socket::UnixListener; use unix_socket::UnixListener;
let dir = tempfile::Builder::new().prefix("unix_socket").tempdir().expect("failed to create dir"); let dir = tempfile::Builder::new()
.prefix("unix_socket")
.tempdir()
.expect("failed to create dir");
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
let listener = UnixListener::bind(&socket_path).expect("failed to create socket"); let listener = UnixListener::bind(&socket_path).expect("failed to create socket");
@ -426,7 +429,7 @@ fn test_domain_socket() {
let child = new_ucmd!().args(&[socket_path]).run_no_wait(); let child = new_ucmd!().args(&[socket_path]).run_no_wait();
barrier.wait(); barrier.wait();
let stdout = &child.wait_with_output().unwrap().stdout.clone(); let stdout = &child.wait_with_output().unwrap().stdout;
let output = String::from_utf8_lossy(&stdout); let output = String::from_utf8_lossy(&stdout);
assert_eq!("a\tb", output); assert_eq!("a\tb", output);

View file

@ -6,7 +6,7 @@ fn test_invalid_option() {
new_ucmd!().arg("-w").arg("/").fails(); new_ucmd!().arg("-w").arg("/").fails();
} }
static DIR: &'static str = "/tmp"; static DIR: &str = "/tmp";
#[test] #[test]
fn test_invalid_group() { fn test_invalid_group() {

View file

@ -8,8 +8,8 @@ use self::chmod::strip_minus_from_mode;
extern crate chmod; extern crate chmod;
use self::libc::umask; use self::libc::umask;
static TEST_FILE: &'static str = "file"; static TEST_FILE: &str = "file";
static REFERENCE_FILE: &'static str = "reference"; static REFERENCE_FILE: &str = "reference";
static REFERENCE_PERMS: u32 = 0o247; static REFERENCE_PERMS: u32 = 0o247;
lazy_static! { lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(()); static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
@ -69,6 +69,7 @@ fn run_tests(tests: Vec<TestCase>) {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_octal() { fn test_chmod_octal() {
let tests = vec![ let tests = vec![
TestCase { TestCase {
@ -121,6 +122,7 @@ fn test_chmod_octal() {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_ugoa() { fn test_chmod_ugoa() {
let _guard = UMASK_MUTEX.lock(); let _guard = UMASK_MUTEX.lock();
@ -216,6 +218,7 @@ fn test_chmod_ugoa() {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_ugo_copy() { fn test_chmod_ugo_copy() {
let tests = vec![ let tests = vec![
TestCase { TestCase {
@ -248,6 +251,7 @@ fn test_chmod_ugo_copy() {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_many_options() { fn test_chmod_many_options() {
let _guard = UMASK_MUTEX.lock(); let _guard = UMASK_MUTEX.lock();
@ -264,6 +268,7 @@ fn test_chmod_many_options() {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_reference_file() { fn test_chmod_reference_file() {
let tests = vec![ let tests = vec![
TestCase { TestCase {
@ -303,6 +308,7 @@ fn test_permission_denied() {
} }
#[test] #[test]
#[allow(clippy::unreadable_literal)]
fn test_chmod_recursive() { fn test_chmod_recursive() {
let _guard = UMASK_MUTEX.lock(); let _guard = UMASK_MUTEX.lock();
@ -477,7 +483,7 @@ fn test_chmod_strip_minus_from_mode() {
]; ];
for test in tests { for test in tests {
let mut args: Vec<String> = test.0.split(" ").map(|v| v.to_string()).collect(); let mut args: Vec<String> = test.0.split(' ').map(|v| v.to_string()).collect();
let _mode_had_minus_prefix = strip_minus_from_mode(&mut args); let _mode_had_minus_prefix = strip_minus_from_mode(&mut args);
assert_eq!(test.1, args.join(" ")); assert_eq!(test.1, args.join(" "));
} }

View file

@ -39,7 +39,7 @@ mod test_passgrp {
#[test] #[test]
fn test_usr2uid() { fn test_usr2uid() {
assert_eq!(0, usr2uid("root").unwrap()); assert_eq!(0, usr2uid("root").unwrap());
assert!(usr2uid("88888888").is_err()); assert!(usr2uid("88_888_888").is_err());
assert!(usr2uid("auserthatdoesntexist").is_err()); assert!(usr2uid("auserthatdoesntexist").is_err());
} }
@ -50,14 +50,14 @@ mod test_passgrp {
} else { } else {
assert_eq!(0, grp2gid("wheel").unwrap()); assert_eq!(0, grp2gid("wheel").unwrap());
} }
assert!(grp2gid("88888888").is_err()); assert!(grp2gid("88_888_888").is_err());
assert!(grp2gid("agroupthatdoesntexist").is_err()); assert!(grp2gid("agroupthatdoesntexist").is_err());
} }
#[test] #[test]
fn test_uid2usr() { fn test_uid2usr() {
assert_eq!("root", uid2usr(0).unwrap()); assert_eq!("root", uid2usr(0).unwrap());
assert!(uid2usr(88888888).is_err()); assert!(uid2usr(88_888_888).is_err());
} }
#[test] #[test]
@ -67,7 +67,7 @@ mod test_passgrp {
} else { } else {
assert_eq!("wheel", gid2grp(0).unwrap()); assert_eq!("wheel", gid2grp(0).unwrap());
} }
assert!(gid2grp(88888888).is_err()); assert!(gid2grp(88_888_888).is_err());
} }
} }

View file

@ -85,12 +85,12 @@ fn test_crc_for_bigger_than_32_bytes() {
let result = ucmd.arg("chars.txt").succeeds(); let result = ucmd.arg("chars.txt").succeeds();
let mut stdout_splitted = result.stdout_str().split(" "); let mut stdout_splitted = result.stdout_str().split(' ');
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap(); let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap(); let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
assert_eq!(cksum, 586047089); assert_eq!(cksum, 586_047_089);
assert_eq!(bytes_cnt, 16); assert_eq!(bytes_cnt, 16);
} }
@ -100,11 +100,11 @@ fn test_stdin_larger_than_128_bytes() {
let result = ucmd.arg("larger_than_2056_bytes.txt").succeeds(); let result = ucmd.arg("larger_than_2056_bytes.txt").succeeds();
let mut stdout_splitted = result.stdout_str().split(" "); let mut stdout_splitted = result.stdout_str().split(' ');
let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap(); let cksum: i64 = stdout_splitted.next().unwrap().parse().unwrap();
let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap(); let bytes_cnt: i64 = stdout_splitted.next().unwrap().parse().unwrap();
assert_eq!(cksum, 945881979); assert_eq!(cksum, 945_881_979);
assert_eq!(bytes_cnt, 2058); assert_eq!(bytes_cnt, 2058);
} }

View file

@ -74,7 +74,7 @@ fn output_delimiter_require_arg() {
#[cfg_attr(not(feature = "test_unimplemented"), ignore)] #[cfg_attr(not(feature = "test_unimplemented"), ignore)]
#[test] #[test]
fn zero_terminated() { fn zero_terminated() {
for param in vec!["-z", "--zero-terminated"] { for &param in &["-z", "--zero-terminated"] {
new_ucmd!() new_ucmd!()
.args(&[param, "a", "b"]) .args(&[param, "a", "b"])
.fails() .fails()

View file

@ -108,7 +108,7 @@ fn test_cp_multiple_files() {
#[test] #[test]
// FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590 // FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590
#[cfg(not(macos))] #[cfg(not(target_os = "macos"))]
fn test_cp_recurse() { fn test_cp_recurse() {
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
ucmd.arg("-r") ucmd.arg("-r")
@ -132,7 +132,7 @@ fn test_cp_with_dirs_t() {
#[test] #[test]
// FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590 // FixME: for MacOS, this has intermittent failures; track repair progress at GH:uutils/coreutils/issues/1590
#[cfg(not(macos))] #[cfg(not(target_os = "macos"))]
fn test_cp_with_dirs() { fn test_cp_with_dirs() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let at = &scene.fixtures; let at = &scene.fixtures;

View file

@ -1,13 +1,13 @@
use crate::common::util::*; use crate::common::util::*;
static INPUT: &'static str = "lists.txt"; static INPUT: &str = "lists.txt";
struct TestedSequence<'b> { struct TestedSequence<'b> {
name: &'b str, name: &'b str,
sequence: &'b str, sequence: &'b str,
} }
static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[ static EXAMPLE_SEQUENCES: &[TestedSequence] = &[
TestedSequence { TestedSequence {
name: "singular", name: "singular",
sequence: "2", sequence: "2",
@ -34,14 +34,14 @@ static EXAMPLE_SEQUENCES: &'static [TestedSequence<'static>] = &[
}, },
]; ];
static COMPLEX_SEQUENCE: &'static TestedSequence<'static> = &TestedSequence { static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence {
name: "", name: "",
sequence: "9-,6-7,-2,4", sequence: "9-,6-7,-2,4",
}; };
#[test] #[test]
fn test_byte_sequence() { fn test_byte_sequence() {
for param in vec!["-b", "--bytes"] { for &param in &["-b", "--bytes"] {
for example_seq in EXAMPLE_SEQUENCES { for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!() new_ucmd!()
.args(&[param, example_seq.sequence, INPUT]) .args(&[param, example_seq.sequence, INPUT])
@ -53,7 +53,7 @@ fn test_byte_sequence() {
#[test] #[test]
fn test_char_sequence() { fn test_char_sequence() {
for param in vec!["-c", "--characters"] { for &param in &["-c", "--characters"] {
for example_seq in EXAMPLE_SEQUENCES { for example_seq in EXAMPLE_SEQUENCES {
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars. //as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
new_ucmd!() new_ucmd!()
@ -66,7 +66,7 @@ fn test_char_sequence() {
#[test] #[test]
fn test_field_sequence() { fn test_field_sequence() {
for param in vec!["-f", "--fields"] { for &param in &["-f", "--fields"] {
for example_seq in EXAMPLE_SEQUENCES { for example_seq in EXAMPLE_SEQUENCES {
new_ucmd!() new_ucmd!()
.args(&[param, example_seq.sequence, INPUT]) .args(&[param, example_seq.sequence, INPUT])
@ -78,7 +78,7 @@ fn test_field_sequence() {
#[test] #[test]
fn test_specify_delimiter() { fn test_specify_delimiter() {
for param in vec!["-d", "--delimiter"] { for &param in &["-d", "--delimiter"] {
new_ucmd!() new_ucmd!()
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT]) .args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
.succeeds() .succeeds()
@ -122,7 +122,7 @@ fn test_zero_terminated() {
#[test] #[test]
fn test_only_delimited() { fn test_only_delimited() {
for param in vec!["-s", "--only-delimited"] { for param in &["-s", "--only-delimited"] {
new_ucmd!() new_ucmd!()
.args(&["-d_", param, "-f", "1"]) .args(&["-d_", param, "-f", "1"])
.pipe_in("91\n82\n7_3") .pipe_in("91\n82\n7_3")

View file

@ -118,7 +118,7 @@ fn test_null_delimiter() {
let mut vars: Vec<_> = out.split('\0').collect(); let mut vars: Vec<_> = out.split('\0').collect();
assert_eq!(vars.len(), 3); assert_eq!(vars.len(), 3);
vars.sort(); vars.sort_unstable();
assert_eq!(vars[0], ""); assert_eq!(vars[0], "");
assert_eq!(vars[1], "ABC=xyz"); assert_eq!(vars[1], "ABC=xyz");
assert_eq!(vars[2], "FOO=bar"); assert_eq!(vars[2], "FOO=bar");
@ -135,7 +135,7 @@ fn test_unset_variable() {
.succeeds() .succeeds()
.stdout_move_str(); .stdout_move_str();
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false); assert!(!out.lines().any(|line| line.starts_with("HOME=")));
} }
#[test] #[test]
@ -196,7 +196,7 @@ fn test_change_directory() {
fn test_fail_change_directory() { fn test_fail_change_directory() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let some_non_existing_path = "some_nonexistent_path"; let some_non_existing_path = "some_nonexistent_path";
assert_eq!(Path::new(some_non_existing_path).is_dir(), false); assert!(!Path::new(some_non_existing_path).is_dir());
let out = scene let out = scene
.ucmd() .ucmd()

View file

@ -4,6 +4,7 @@
// //
// For the full copyright and license information, please view the LICENSE file // For the full copyright and license information, please view the LICENSE file
// that was distributed with this source code. // that was distributed with this source code.
#![allow(clippy::unreadable_literal)]
use crate::common::util::*; use crate::common::util::*;
use std::time::SystemTime; use std::time::SystemTime;
@ -77,7 +78,7 @@ fn test_random() {
}; };
} }
factors.sort(); factors.sort_unstable();
(product, factors) (product, factors)
}; };
@ -92,7 +93,7 @@ fn test_random() {
for factor in factors { for factor in factors {
outstring.push_str(&(format!(" {}", factor))[..]); outstring.push_str(&(format!(" {}", factor))[..]);
} }
outstring.push_str("\n"); outstring.push('\n');
} }
run(instring.as_bytes(), outstring.as_bytes()); run(instring.as_bytes(), outstring.as_bytes());
@ -131,7 +132,7 @@ fn test_random_big() {
f_bits.push(extrarange.sample(&mut rng)); f_bits.push(extrarange.sample(&mut rng));
} }
f_bits.push(extrabits); f_bits.push(extrabits);
f_bits.sort(); f_bits.sort_unstable();
// compute sequential differences here. We leave off the +14 bits // compute sequential differences here. We leave off the +14 bits
// so we can just index PRIMES_BY_BITS // so we can just index PRIMES_BY_BITS
@ -160,7 +161,7 @@ fn test_random_big() {
} }
assert_eq!(nbits, 64); assert_eq!(nbits, 64);
factors.sort(); factors.sort_unstable();
(product, factors) (product, factors)
}; };
@ -174,7 +175,7 @@ fn test_random_big() {
for factor in factors { for factor in factors {
outstring.push_str(&(format!(" {}", factor))[..]); outstring.push_str(&(format!(" {}", factor))[..]);
} }
outstring.push_str("\n"); outstring.push('\n');
} }
run(instring.as_bytes(), outstring.as_bytes()); run(instring.as_bytes(), outstring.as_bytes());
@ -202,7 +203,7 @@ fn run(instring: &[u8], outstring: &[u8]) {
.stdout_is(String::from_utf8(outstring.to_owned()).unwrap()); .stdout_is(String::from_utf8(outstring.to_owned()).unwrap());
} }
const PRIMES_BY_BITS: &'static [&'static [u64]] = &[ const PRIMES_BY_BITS: &[&[u64]] = &[
PRIMES14, PRIMES15, PRIMES16, PRIMES17, PRIMES18, PRIMES19, PRIMES20, PRIMES21, PRIMES22, PRIMES14, PRIMES15, PRIMES16, PRIMES17, PRIMES18, PRIMES19, PRIMES20, PRIMES21, PRIMES22,
PRIMES23, PRIMES24, PRIMES25, PRIMES26, PRIMES27, PRIMES28, PRIMES29, PRIMES30, PRIMES31, PRIMES23, PRIMES24, PRIMES25, PRIMES26, PRIMES27, PRIMES28, PRIMES29, PRIMES30, PRIMES31,
PRIMES32, PRIMES33, PRIMES34, PRIMES35, PRIMES36, PRIMES37, PRIMES38, PRIMES39, PRIMES40, PRIMES32, PRIMES33, PRIMES34, PRIMES35, PRIMES36, PRIMES37, PRIMES38, PRIMES39, PRIMES40,
@ -210,7 +211,7 @@ const PRIMES_BY_BITS: &'static [&'static [u64]] = &[
PRIMES50, PRIMES50,
]; ];
const PRIMES64: &'static [u64] = &[ const PRIMES64: &[u64] = &[
18446744073709551557, 18446744073709551557,
18446744073709551533, 18446744073709551533,
18446744073709551521, 18446744073709551521,
@ -262,7 +263,7 @@ const PRIMES64: &'static [u64] = &[
18446744073709549571, 18446744073709549571,
]; ];
const PRIMES14: &'static [u64] = &[ const PRIMES14: &[u64] = &[
16381, 16369, 16363, 16361, 16349, 16339, 16333, 16319, 16301, 16273, 16267, 16253, 16249, 16381, 16369, 16363, 16361, 16349, 16339, 16333, 16319, 16301, 16273, 16267, 16253, 16249,
16231, 16229, 16223, 16217, 16193, 16189, 16187, 16183, 16141, 16139, 16127, 16111, 16103, 16231, 16229, 16223, 16217, 16193, 16189, 16187, 16183, 16141, 16139, 16127, 16111, 16103,
16097, 16091, 16087, 16073, 16069, 16067, 16063, 16061, 16057, 16033, 16007, 16001, 15991, 16097, 16091, 16087, 16073, 16069, 16067, 16063, 16061, 16057, 16033, 16007, 16001, 15991,
@ -274,7 +275,7 @@ const PRIMES14: &'static [u64] = &[
15373, 15373,
]; ];
const PRIMES15: &'static [u64] = &[ const PRIMES15: &[u64] = &[
32749, 32719, 32717, 32713, 32707, 32693, 32687, 32653, 32647, 32633, 32621, 32611, 32609, 32749, 32719, 32717, 32713, 32707, 32693, 32687, 32653, 32647, 32633, 32621, 32611, 32609,
32603, 32587, 32579, 32573, 32569, 32563, 32561, 32537, 32533, 32531, 32507, 32503, 32497, 32603, 32587, 32579, 32573, 32569, 32563, 32561, 32537, 32533, 32531, 32507, 32503, 32497,
32491, 32479, 32467, 32443, 32441, 32429, 32423, 32413, 32411, 32401, 32381, 32377, 32371, 32491, 32479, 32467, 32443, 32441, 32429, 32423, 32413, 32411, 32401, 32381, 32377, 32371,
@ -285,7 +286,7 @@ const PRIMES15: &'static [u64] = &[
31847, 31817, 31799, 31793, 31771, 31769, 31751, 31847, 31817, 31799, 31793, 31771, 31769, 31751,
]; ];
const PRIMES16: &'static [u64] = &[ const PRIMES16: &[u64] = &[
65521, 65519, 65497, 65479, 65449, 65447, 65437, 65423, 65419, 65413, 65407, 65393, 65381, 65521, 65519, 65497, 65479, 65449, 65447, 65437, 65423, 65419, 65413, 65407, 65393, 65381,
65371, 65357, 65353, 65327, 65323, 65309, 65293, 65287, 65269, 65267, 65257, 65239, 65213, 65371, 65357, 65353, 65327, 65323, 65309, 65293, 65287, 65269, 65267, 65257, 65239, 65213,
65203, 65183, 65179, 65173, 65171, 65167, 65147, 65141, 65129, 65123, 65119, 65111, 65101, 65203, 65183, 65179, 65173, 65171, 65167, 65147, 65141, 65129, 65123, 65119, 65111, 65101,
@ -295,7 +296,7 @@ const PRIMES16: &'static [u64] = &[
64627, 64621, 64613, 64609, 64601, 64591, 64579, 64577, 64567, 64553, 64627, 64621, 64613, 64609, 64601, 64591, 64579, 64577, 64567, 64553,
]; ];
const PRIMES17: &'static [u64] = &[ const PRIMES17: &[u64] = &[
131071, 131063, 131059, 131041, 131023, 131011, 131009, 130987, 130981, 130973, 130969, 130957, 131071, 131063, 131059, 131041, 131023, 131011, 131009, 130987, 130981, 130973, 130969, 130957,
130927, 130873, 130859, 130843, 130841, 130829, 130817, 130811, 130807, 130787, 130783, 130769, 130927, 130873, 130859, 130843, 130841, 130829, 130817, 130811, 130807, 130787, 130783, 130769,
130729, 130699, 130693, 130687, 130681, 130657, 130651, 130649, 130643, 130639, 130633, 130631, 130729, 130699, 130693, 130687, 130681, 130657, 130651, 130649, 130643, 130639, 130633, 130631,
@ -306,7 +307,7 @@ const PRIMES17: &'static [u64] = &[
130073, 130069, 130057, 130051, 130073, 130069, 130057, 130051,
]; ];
const PRIMES18: &'static [u64] = &[ const PRIMES18: &[u64] = &[
262139, 262133, 262127, 262121, 262111, 262109, 262103, 262079, 262069, 262051, 262049, 262027, 262139, 262133, 262127, 262121, 262111, 262109, 262103, 262079, 262069, 262051, 262049, 262027,
262007, 261983, 261977, 261973, 261971, 261959, 261917, 261887, 261881, 261847, 261823, 261799, 262007, 261983, 261977, 261973, 261971, 261959, 261917, 261887, 261881, 261847, 261823, 261799,
261791, 261787, 261773, 261761, 261757, 261739, 261721, 261713, 261707, 261697, 261673, 261643, 261791, 261787, 261773, 261761, 261757, 261739, 261721, 261713, 261707, 261697, 261673, 261643,
@ -316,7 +317,7 @@ const PRIMES18: &'static [u64] = &[
261169, 261167, 261127, 261169, 261167, 261127,
]; ];
const PRIMES19: &'static [u64] = &[ const PRIMES19: &[u64] = &[
524287, 524269, 524261, 524257, 524243, 524231, 524221, 524219, 524203, 524201, 524197, 524189, 524287, 524269, 524261, 524257, 524243, 524231, 524221, 524219, 524203, 524201, 524197, 524189,
524171, 524149, 524123, 524119, 524113, 524099, 524087, 524081, 524071, 524063, 524057, 524053, 524171, 524149, 524123, 524119, 524113, 524099, 524087, 524081, 524071, 524063, 524057, 524053,
524047, 523997, 523987, 523969, 523949, 523937, 523927, 523907, 523903, 523877, 523867, 523847, 524047, 523997, 523987, 523969, 523949, 523937, 523927, 523907, 523903, 523877, 523867, 523847,
@ -326,7 +327,7 @@ const PRIMES19: &'static [u64] = &[
523403, 523387, 523357, 523351, 523349, 523333, 523307, 523297, 523403, 523387, 523357, 523351, 523349, 523333, 523307, 523297,
]; ];
const PRIMES20: &'static [u64] = &[ const PRIMES20: &[u64] = &[
1048573, 1048571, 1048559, 1048549, 1048517, 1048507, 1048447, 1048433, 1048423, 1048391, 1048573, 1048571, 1048559, 1048549, 1048517, 1048507, 1048447, 1048433, 1048423, 1048391,
1048387, 1048367, 1048361, 1048357, 1048343, 1048309, 1048291, 1048273, 1048261, 1048219, 1048387, 1048367, 1048361, 1048357, 1048343, 1048309, 1048291, 1048273, 1048261, 1048219,
1048217, 1048213, 1048193, 1048189, 1048139, 1048129, 1048127, 1048123, 1048063, 1048051, 1048217, 1048213, 1048193, 1048189, 1048139, 1048129, 1048127, 1048123, 1048063, 1048051,
@ -336,7 +337,7 @@ const PRIMES20: &'static [u64] = &[
1047691, 1047689, 1047671, 1047667, 1047653, 1047649, 1047647, 1047589, 1047587, 1047559, 1047691, 1047689, 1047671, 1047667, 1047653, 1047649, 1047647, 1047589, 1047587, 1047559,
]; ];
const PRIMES21: &'static [u64] = &[ const PRIMES21: &[u64] = &[
2097143, 2097133, 2097131, 2097097, 2097091, 2097083, 2097047, 2097041, 2097031, 2097023, 2097143, 2097133, 2097131, 2097097, 2097091, 2097083, 2097047, 2097041, 2097031, 2097023,
2097013, 2096993, 2096987, 2096971, 2096959, 2096957, 2096947, 2096923, 2096911, 2096909, 2097013, 2096993, 2096987, 2096971, 2096959, 2096957, 2096947, 2096923, 2096911, 2096909,
2096893, 2096881, 2096873, 2096867, 2096851, 2096837, 2096807, 2096791, 2096789, 2096777, 2096893, 2096881, 2096873, 2096867, 2096851, 2096837, 2096807, 2096791, 2096789, 2096777,
@ -346,7 +347,7 @@ const PRIMES21: &'static [u64] = &[
2096221, 2096209, 2096191, 2096183, 2096147, 2096221, 2096209, 2096191, 2096183, 2096147,
]; ];
const PRIMES22: &'static [u64] = &[ const PRIMES22: &[u64] = &[
4194301, 4194287, 4194277, 4194271, 4194247, 4194217, 4194199, 4194191, 4194187, 4194181, 4194301, 4194287, 4194277, 4194271, 4194247, 4194217, 4194199, 4194191, 4194187, 4194181,
4194173, 4194167, 4194143, 4194137, 4194131, 4194107, 4194103, 4194023, 4194011, 4194007, 4194173, 4194167, 4194143, 4194137, 4194131, 4194107, 4194103, 4194023, 4194011, 4194007,
4193977, 4193971, 4193963, 4193957, 4193939, 4193929, 4193909, 4193869, 4193807, 4193803, 4193977, 4193971, 4193963, 4193957, 4193939, 4193929, 4193909, 4193869, 4193807, 4193803,
@ -356,7 +357,7 @@ const PRIMES22: &'static [u64] = &[
4193297, 4193297,
]; ];
const PRIMES23: &'static [u64] = &[ const PRIMES23: &[u64] = &[
8388593, 8388587, 8388581, 8388571, 8388547, 8388539, 8388473, 8388461, 8388451, 8388449, 8388593, 8388587, 8388581, 8388571, 8388547, 8388539, 8388473, 8388461, 8388451, 8388449,
8388439, 8388427, 8388421, 8388409, 8388377, 8388371, 8388319, 8388301, 8388287, 8388283, 8388439, 8388427, 8388421, 8388409, 8388377, 8388371, 8388319, 8388301, 8388287, 8388283,
8388277, 8388239, 8388209, 8388187, 8388113, 8388109, 8388091, 8388071, 8388059, 8388019, 8388277, 8388239, 8388209, 8388187, 8388113, 8388109, 8388091, 8388071, 8388059, 8388019,
@ -365,7 +366,7 @@ const PRIMES23: &'static [u64] = &[
8387723, 8387707, 8387671, 8387611, 8387609, 8387591, 8387723, 8387707, 8387671, 8387611, 8387609, 8387591,
]; ];
const PRIMES24: &'static [u64] = &[ const PRIMES24: &[u64] = &[
16777213, 16777199, 16777183, 16777153, 16777141, 16777139, 16777127, 16777121, 16777099, 16777213, 16777199, 16777183, 16777153, 16777141, 16777139, 16777127, 16777121, 16777099,
16777049, 16777027, 16776989, 16776973, 16776971, 16776967, 16776961, 16776941, 16776937, 16777049, 16777027, 16776989, 16776973, 16776971, 16776967, 16776961, 16776941, 16776937,
16776931, 16776919, 16776901, 16776899, 16776869, 16776857, 16776839, 16776833, 16776817, 16776931, 16776919, 16776901, 16776899, 16776869, 16776857, 16776839, 16776833, 16776817,
@ -375,7 +376,7 @@ const PRIMES24: &'static [u64] = &[
16776317, 16776313, 16776289, 16776217, 16776211, 16776317, 16776313, 16776289, 16776217, 16776211,
]; ];
const PRIMES25: &'static [u64] = &[ const PRIMES25: &[u64] = &[
33554393, 33554383, 33554371, 33554347, 33554341, 33554317, 33554291, 33554273, 33554267, 33554393, 33554383, 33554371, 33554347, 33554341, 33554317, 33554291, 33554273, 33554267,
33554249, 33554239, 33554221, 33554201, 33554167, 33554159, 33554137, 33554123, 33554093, 33554249, 33554239, 33554221, 33554201, 33554167, 33554159, 33554137, 33554123, 33554093,
33554083, 33554077, 33554051, 33554021, 33554011, 33554009, 33553999, 33553991, 33553969, 33554083, 33554077, 33554051, 33554021, 33554011, 33554009, 33553999, 33553991, 33553969,
@ -385,7 +386,7 @@ const PRIMES25: &'static [u64] = &[
33553519, 33553517, 33553511, 33553489, 33553463, 33553451, 33553417, 33553519, 33553517, 33553511, 33553489, 33553463, 33553451, 33553417,
]; ];
const PRIMES26: &'static [u64] = &[ const PRIMES26: &[u64] = &[
67108859, 67108837, 67108819, 67108777, 67108763, 67108757, 67108753, 67108747, 67108739, 67108859, 67108837, 67108819, 67108777, 67108763, 67108757, 67108753, 67108747, 67108739,
67108729, 67108721, 67108709, 67108693, 67108669, 67108667, 67108661, 67108649, 67108633, 67108729, 67108721, 67108709, 67108693, 67108669, 67108667, 67108661, 67108649, 67108633,
67108597, 67108579, 67108529, 67108511, 67108507, 67108493, 67108471, 67108463, 67108453, 67108597, 67108579, 67108529, 67108511, 67108507, 67108493, 67108471, 67108463, 67108453,
@ -396,7 +397,7 @@ const PRIMES26: &'static [u64] = &[
67107863, 67107863,
]; ];
const PRIMES27: &'static [u64] = &[ const PRIMES27: &[u64] = &[
134217689, 134217649, 134217617, 134217613, 134217593, 134217541, 134217529, 134217509, 134217689, 134217649, 134217617, 134217613, 134217593, 134217541, 134217529, 134217509,
134217497, 134217493, 134217487, 134217467, 134217439, 134217437, 134217409, 134217403, 134217497, 134217493, 134217487, 134217467, 134217439, 134217437, 134217409, 134217403,
134217401, 134217367, 134217361, 134217353, 134217323, 134217301, 134217277, 134217257, 134217401, 134217367, 134217361, 134217353, 134217323, 134217301, 134217277, 134217257,
@ -407,7 +408,7 @@ const PRIMES27: &'static [u64] = &[
134216737, 134216729, 134216737, 134216729,
]; ];
const PRIMES28: &'static [u64] = &[ const PRIMES28: &[u64] = &[
268435399, 268435367, 268435361, 268435337, 268435331, 268435313, 268435291, 268435273, 268435399, 268435367, 268435361, 268435337, 268435331, 268435313, 268435291, 268435273,
268435243, 268435183, 268435171, 268435157, 268435147, 268435133, 268435129, 268435121, 268435243, 268435183, 268435171, 268435157, 268435147, 268435133, 268435129, 268435121,
268435109, 268435091, 268435067, 268435043, 268435039, 268435033, 268435019, 268435009, 268435109, 268435091, 268435067, 268435043, 268435039, 268435033, 268435019, 268435009,
@ -418,7 +419,7 @@ const PRIMES28: &'static [u64] = &[
268434479, 268434461, 268434479, 268434461,
]; ];
const PRIMES29: &'static [u64] = &[ const PRIMES29: &[u64] = &[
536870909, 536870879, 536870869, 536870849, 536870839, 536870837, 536870819, 536870813, 536870909, 536870879, 536870869, 536870849, 536870839, 536870837, 536870819, 536870813,
536870791, 536870779, 536870767, 536870743, 536870729, 536870723, 536870717, 536870701, 536870791, 536870779, 536870767, 536870743, 536870729, 536870723, 536870717, 536870701,
536870683, 536870657, 536870641, 536870627, 536870611, 536870603, 536870599, 536870573, 536870683, 536870657, 536870641, 536870627, 536870611, 536870603, 536870599, 536870573,
@ -428,7 +429,7 @@ const PRIMES29: &'static [u64] = &[
536870027, 536869999, 536869951, 536869943, 536869937, 536869919, 536869901, 536869891, 536870027, 536869999, 536869951, 536869943, 536869937, 536869919, 536869901, 536869891,
]; ];
const PRIMES30: &'static [u64] = &[ const PRIMES30: &[u64] = &[
1073741789, 1073741783, 1073741741, 1073741723, 1073741719, 1073741717, 1073741689, 1073741671, 1073741789, 1073741783, 1073741741, 1073741723, 1073741719, 1073741717, 1073741689, 1073741671,
1073741663, 1073741651, 1073741621, 1073741567, 1073741561, 1073741527, 1073741503, 1073741477, 1073741663, 1073741651, 1073741621, 1073741567, 1073741561, 1073741527, 1073741503, 1073741477,
1073741467, 1073741441, 1073741419, 1073741399, 1073741387, 1073741381, 1073741371, 1073741329, 1073741467, 1073741441, 1073741419, 1073741399, 1073741387, 1073741381, 1073741371, 1073741329,
@ -437,7 +438,7 @@ const PRIMES30: &'static [u64] = &[
1073740853, 1073740847, 1073740819, 1073740807, 1073740853, 1073740847, 1073740819, 1073740807,
]; ];
const PRIMES31: &'static [u64] = &[ const PRIMES31: &[u64] = &[
2147483647, 2147483629, 2147483587, 2147483579, 2147483563, 2147483549, 2147483543, 2147483497, 2147483647, 2147483629, 2147483587, 2147483579, 2147483563, 2147483549, 2147483543, 2147483497,
2147483489, 2147483477, 2147483423, 2147483399, 2147483353, 2147483323, 2147483269, 2147483249, 2147483489, 2147483477, 2147483423, 2147483399, 2147483353, 2147483323, 2147483269, 2147483249,
2147483237, 2147483179, 2147483171, 2147483137, 2147483123, 2147483077, 2147483069, 2147483059, 2147483237, 2147483179, 2147483171, 2147483137, 2147483123, 2147483077, 2147483069, 2147483059,
@ -446,7 +447,7 @@ const PRIMES31: &'static [u64] = &[
2147482763, 2147482739, 2147482697, 2147482693, 2147482681, 2147482663, 2147482661, 2147482763, 2147482739, 2147482697, 2147482693, 2147482681, 2147482663, 2147482661,
]; ];
const PRIMES32: &'static [u64] = &[ const PRIMES32: &[u64] = &[
4294967291, 4294967279, 4294967231, 4294967197, 4294967189, 4294967161, 4294967143, 4294967111, 4294967291, 4294967279, 4294967231, 4294967197, 4294967189, 4294967161, 4294967143, 4294967111,
4294967087, 4294967029, 4294966997, 4294966981, 4294966943, 4294966927, 4294966909, 4294966877, 4294967087, 4294967029, 4294966997, 4294966981, 4294966943, 4294966927, 4294966909, 4294966877,
4294966829, 4294966813, 4294966769, 4294966667, 4294966661, 4294966657, 4294966651, 4294966639, 4294966829, 4294966813, 4294966769, 4294966667, 4294966661, 4294966657, 4294966651, 4294966639,
@ -454,7 +455,7 @@ const PRIMES32: &'static [u64] = &[
4294966373, 4294966367, 4294966337, 4294966297, 4294966373, 4294966367, 4294966337, 4294966297,
]; ];
const PRIMES33: &'static [u64] = &[ const PRIMES33: &[u64] = &[
8589934583, 8589934567, 8589934543, 8589934513, 8589934487, 8589934307, 8589934291, 8589934289, 8589934583, 8589934567, 8589934543, 8589934513, 8589934487, 8589934307, 8589934291, 8589934289,
8589934271, 8589934237, 8589934211, 8589934207, 8589934201, 8589934187, 8589934151, 8589934141, 8589934271, 8589934237, 8589934211, 8589934207, 8589934201, 8589934187, 8589934151, 8589934141,
8589934139, 8589934117, 8589934103, 8589934099, 8589934091, 8589934069, 8589934049, 8589934027, 8589934139, 8589934117, 8589934103, 8589934099, 8589934091, 8589934069, 8589934049, 8589934027,
@ -463,7 +464,7 @@ const PRIMES33: &'static [u64] = &[
8589933647, 8589933641, 8589933637, 8589933631, 8589933629, 8589933619, 8589933601, 8589933581, 8589933647, 8589933641, 8589933637, 8589933631, 8589933629, 8589933619, 8589933601, 8589933581,
]; ];
const PRIMES34: &'static [u64] = &[ const PRIMES34: &[u64] = &[
17179869143, 17179869143,
17179869107, 17179869107,
17179869071, 17179869071,
@ -514,7 +515,7 @@ const PRIMES34: &'static [u64] = &[
17179868183, 17179868183,
]; ];
const PRIMES35: &'static [u64] = &[ const PRIMES35: &[u64] = &[
34359738337, 34359738337,
34359738319, 34359738319,
34359738307, 34359738307,
@ -547,7 +548,7 @@ const PRIMES35: &'static [u64] = &[
34359737371, 34359737371,
]; ];
const PRIMES36: &'static [u64] = &[ const PRIMES36: &[u64] = &[
68719476731, 68719476731,
68719476719, 68719476719,
68719476713, 68719476713,
@ -599,7 +600,7 @@ const PRIMES36: &'static [u64] = &[
68719475729, 68719475729,
]; ];
const PRIMES37: &'static [u64] = &[ const PRIMES37: &[u64] = &[
137438953447, 137438953447,
137438953441, 137438953441,
137438953427, 137438953427,
@ -625,7 +626,7 @@ const PRIMES37: &'static [u64] = &[
137438952491, 137438952491,
]; ];
const PRIMES38: &'static [u64] = &[ const PRIMES38: &[u64] = &[
274877906899, 274877906899,
274877906857, 274877906857,
274877906837, 274877906837,
@ -665,7 +666,7 @@ const PRIMES38: &'static [u64] = &[
274877905931, 274877905931,
]; ];
const PRIMES39: &'static [u64] = &[ const PRIMES39: &[u64] = &[
549755813881, 549755813881,
549755813869, 549755813869,
549755813821, 549755813821,
@ -711,7 +712,7 @@ const PRIMES39: &'static [u64] = &[
549755812867, 549755812867,
]; ];
const PRIMES40: &'static [u64] = &[ const PRIMES40: &[u64] = &[
1099511627689, 1099511627689,
1099511627609, 1099511627609,
1099511627581, 1099511627581,
@ -741,7 +742,7 @@ const PRIMES40: &'static [u64] = &[
1099511626771, 1099511626771,
]; ];
const PRIMES41: &'static [u64] = &[ const PRIMES41: &[u64] = &[
2199023255531, 2199023255531,
2199023255521, 2199023255521,
2199023255497, 2199023255497,
@ -780,7 +781,7 @@ const PRIMES41: &'static [u64] = &[
2199023254567, 2199023254567,
]; ];
const PRIMES42: &'static [u64] = &[ const PRIMES42: &[u64] = &[
4398046511093, 4398046511093,
4398046511087, 4398046511087,
4398046511071, 4398046511071,
@ -820,7 +821,7 @@ const PRIMES42: &'static [u64] = &[
4398046510093, 4398046510093,
]; ];
const PRIMES43: &'static [u64] = &[ const PRIMES43: &[u64] = &[
8796093022151, 8796093022151,
8796093022141, 8796093022141,
8796093022091, 8796093022091,
@ -855,7 +856,7 @@ const PRIMES43: &'static [u64] = &[
8796093021269, 8796093021269,
]; ];
const PRIMES44: &'static [u64] = &[ const PRIMES44: &[u64] = &[
17592186044399, 17592186044399,
17592186044299, 17592186044299,
17592186044297, 17592186044297,
@ -888,7 +889,7 @@ const PRIMES44: &'static [u64] = &[
17592186043409, 17592186043409,
]; ];
const PRIMES45: &'static [u64] = &[ const PRIMES45: &[u64] = &[
35184372088777, 35184372088777,
35184372088763, 35184372088763,
35184372088751, 35184372088751,
@ -929,7 +930,7 @@ const PRIMES45: &'static [u64] = &[
35184372087869, 35184372087869,
]; ];
const PRIMES46: &'static [u64] = &[ const PRIMES46: &[u64] = &[
70368744177643, 70368744177643,
70368744177607, 70368744177607,
70368744177601, 70368744177601,
@ -964,7 +965,7 @@ const PRIMES46: &'static [u64] = &[
70368744176711, 70368744176711,
]; ];
const PRIMES47: &'static [u64] = &[ const PRIMES47: &[u64] = &[
140737488355213, 140737488355213,
140737488355201, 140737488355201,
140737488355181, 140737488355181,
@ -986,7 +987,7 @@ const PRIMES47: &'static [u64] = &[
140737488354329, 140737488354329,
]; ];
const PRIMES48: &'static [u64] = &[ const PRIMES48: &[u64] = &[
281474976710597, 281474976710597,
281474976710591, 281474976710591,
281474976710567, 281474976710567,
@ -1019,7 +1020,7 @@ const PRIMES48: &'static [u64] = &[
281474976709637, 281474976709637,
]; ];
const PRIMES49: &'static [u64] = &[ const PRIMES49: &[u64] = &[
562949953421231, 562949953421231,
562949953421201, 562949953421201,
562949953421189, 562949953421189,
@ -1053,7 +1054,7 @@ const PRIMES49: &'static [u64] = &[
562949953420297, 562949953420297,
]; ];
const PRIMES50: &'static [u64] = &[ const PRIMES50: &[u64] = &[
1125899906842597, 1125899906842597,
1125899906842589, 1125899906842589,
1125899906842573, 1125899906842573,

View file

@ -1,6 +1,6 @@
use crate::common::util::*; use crate::common::util::*;
static INPUT: &'static str = "lorem_ipsum.txt"; static INPUT: &str = "lorem_ipsum.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {

View file

@ -116,11 +116,11 @@ fn test_install_ancestors_mode_directories() {
assert!(at.dir_exists(ancestor2)); assert!(at.dir_exists(ancestor2));
assert!(at.dir_exists(target_dir)); assert!(at.dir_exists(target_dir));
assert_ne!(0o40700 as u32, at.metadata(ancestor1).permissions().mode()); assert_ne!(0o40_700_u32, at.metadata(ancestor1).permissions().mode());
assert_ne!(0o40700 as u32, at.metadata(ancestor2).permissions().mode()); assert_ne!(0o40_700_u32, at.metadata(ancestor2).permissions().mode());
// Expected mode only on the target_dir. // Expected mode only on the target_dir.
assert_eq!(0o40700 as u32, at.metadata(target_dir).permissions().mode()); assert_eq!(0o40_700_u32, at.metadata(target_dir).permissions().mode());
} }
#[test] #[test]
@ -184,7 +184,7 @@ fn test_install_mode_numeric() {
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(dest_file)); assert!(at.file_exists(dest_file));
let permissions = at.metadata(dest_file).permissions(); let permissions = at.metadata(dest_file).permissions();
assert_eq!(0o100333 as u32, PermissionsExt::mode(&permissions)); assert_eq!(0o100_333_u32, PermissionsExt::mode(&permissions));
let mode_arg = "-m 0333"; let mode_arg = "-m 0333";
at.mkdir(dir2); at.mkdir(dir2);
@ -195,7 +195,7 @@ fn test_install_mode_numeric() {
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(dest_file)); assert!(at.file_exists(dest_file));
let permissions = at.metadata(dest_file).permissions(); let permissions = at.metadata(dest_file).permissions();
assert_eq!(0o100333 as u32, PermissionsExt::mode(&permissions)); assert_eq!(0o100_333_u32, PermissionsExt::mode(&permissions));
} }
#[test] #[test]
@ -213,7 +213,7 @@ fn test_install_mode_symbolic() {
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(dest_file)); assert!(at.file_exists(dest_file));
let permissions = at.metadata(dest_file).permissions(); let permissions = at.metadata(dest_file).permissions();
assert_eq!(0o100003 as u32, PermissionsExt::mode(&permissions)); assert_eq!(0o100_003_u32, PermissionsExt::mode(&permissions));
} }
#[test] #[test]
@ -251,7 +251,7 @@ fn test_install_mode_directories() {
assert!(at.dir_exists(component)); assert!(at.dir_exists(component));
let permissions = at.metadata(component).permissions(); let permissions = at.metadata(component).permissions();
assert_eq!(0o040333 as u32, PermissionsExt::mode(&permissions)); assert_eq!(0o040_333_u32, PermissionsExt::mode(&permissions));
} }
#[test] #[test]

View file

@ -51,6 +51,7 @@ fn test_ls_a() {
.unwrap(), .unwrap(),
); );
#[allow(clippy::trivial_regex)]
let re_pwd = Regex::new(r"^\.\n").unwrap(); let re_pwd = Regex::new(r"^\.\n").unwrap();
// Using the present working directory // Using the present working directory
@ -124,7 +125,7 @@ fn test_ls_width() {
for option in &["-w 100", "-w=100", "--width=100", "--width 100"] { for option in &["-w 100", "-w=100", "--width=100", "--width 100"] {
scene scene
.ucmd() .ucmd()
.args(&option.split(" ").collect::<Vec<_>>()) .args(&option.split(' ').collect::<Vec<_>>())
.succeeds() .succeeds()
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n"); .stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
} }
@ -132,7 +133,7 @@ fn test_ls_width() {
for option in &["-w 50", "-w=50", "--width=50", "--width 50"] { for option in &["-w 50", "-w=50", "--width=50", "--width 50"] {
scene scene
.ucmd() .ucmd()
.args(&option.split(" ").collect::<Vec<_>>()) .args(&option.split(' ').collect::<Vec<_>>())
.succeeds() .succeeds()
.stdout_only("test-width-1 test-width-3\ntest-width-2 test-width-4\n"); .stdout_only("test-width-1 test-width-3\ntest-width-2 test-width-4\n");
} }
@ -149,7 +150,7 @@ fn test_ls_width() {
] { ] {
scene scene
.ucmd() .ucmd()
.args(&option.split(" ").collect::<Vec<_>>()) .args(&option.split(' ').collect::<Vec<_>>())
.succeeds() .succeeds()
.stdout_only("test-width-1\ntest-width-2\ntest-width-3\ntest-width-4\n"); .stdout_only("test-width-1\ntest-width-2\ntest-width-3\ntest-width-4\n");
} }
@ -163,7 +164,7 @@ fn test_ls_width() {
for option in &["-w 1a", "-w=1a", "--width=1a", "--width 1a"] { for option in &["-w 1a", "-w=1a", "--width=1a", "--width 1a"] {
scene scene
.ucmd() .ucmd()
.args(&option.split(" ").collect::<Vec<_>>()) .args(&option.split(' ').collect::<Vec<_>>())
.fails() .fails()
.stderr_only("ls: invalid line width: 1a"); .stderr_only("ls: invalid line width: 1a");
} }
@ -417,7 +418,7 @@ fn test_ls_long_formats() {
] { ] {
let result = scene let result = scene
.ucmd() .ucmd()
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_two.is_match(result.stdout_str())); assert!(re_two.is_match(result.stdout_str()));
@ -427,7 +428,7 @@ fn test_ls_long_formats() {
let result = scene let result = scene
.ucmd() .ucmd()
.arg("-n") .arg("-n")
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_two_num.is_match(result.stdout_str())); assert!(re_two_num.is_match(result.stdout_str()));
@ -446,7 +447,7 @@ fn test_ls_long_formats() {
] { ] {
let result = scene let result = scene
.ucmd() .ucmd()
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_one.is_match(result.stdout_str())); assert!(re_one.is_match(result.stdout_str()));
@ -456,7 +457,7 @@ fn test_ls_long_formats() {
let result = scene let result = scene
.ucmd() .ucmd()
.arg("-n") .arg("-n")
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_one_num.is_match(result.stdout_str())); assert!(re_one_num.is_match(result.stdout_str()));
@ -478,7 +479,7 @@ fn test_ls_long_formats() {
] { ] {
let result = scene let result = scene
.ucmd() .ucmd()
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_zero.is_match(result.stdout_str())); assert!(re_zero.is_match(result.stdout_str()));
@ -488,7 +489,7 @@ fn test_ls_long_formats() {
let result = scene let result = scene
.ucmd() .ucmd()
.arg("-n") .arg("-n")
.args(&arg.split(" ").collect::<Vec<_>>()) .args(&arg.split(' ').collect::<Vec<_>>())
.arg("test-long-formats") .arg("test-long-formats")
.succeeds(); .succeeds();
assert!(re_zero.is_match(result.stdout_str())); assert!(re_zero.is_match(result.stdout_str()));
@ -1063,7 +1064,7 @@ fn test_ls_indicator_style() {
for opt in options { for opt in options {
scene scene
.ucmd() .ucmd()
.arg(format!("{}", opt)) .arg(opt.to_string())
.succeeds() .succeeds()
.stdout_contains(&"/"); .stdout_contains(&"/");
} }
@ -1085,7 +1086,10 @@ fn test_ls_indicator_style() {
{ {
use self::unix_socket::UnixListener; use self::unix_socket::UnixListener;
let dir = tempfile::Builder::new().prefix("unix_socket").tempdir().expect("failed to create dir"); let dir = tempfile::Builder::new()
.prefix("unix_socket")
.tempdir()
.expect("failed to create dir");
let socket_path = dir.path().join("sock"); let socket_path = dir.path().join("sock");
let _listener = UnixListener::bind(&socket_path).expect("failed to create socket"); let _listener = UnixListener::bind(&socket_path).expect("failed to create socket");

View file

@ -1,12 +1,12 @@
use crate::common::util::*; use crate::common::util::*;
static TEST_DIR1: &'static str = "mkdir_test1"; static TEST_DIR1: &str = "mkdir_test1";
static TEST_DIR2: &'static str = "mkdir_test2"; static TEST_DIR2: &str = "mkdir_test2";
static TEST_DIR3: &'static str = "mkdir_test3"; static TEST_DIR3: &str = "mkdir_test3";
static TEST_DIR4: &'static str = "mkdir_test4/mkdir_test4_1"; static TEST_DIR4: &str = "mkdir_test4/mkdir_test4_1";
static TEST_DIR5: &'static str = "mkdir_test5/mkdir_test5_1"; static TEST_DIR5: &str = "mkdir_test5/mkdir_test5_1";
static TEST_DIR6: &'static str = "mkdir_test6"; static TEST_DIR6: &str = "mkdir_test6";
static TEST_FILE7: &'static str = "mkdir_test7"; static TEST_FILE7: &str = "mkdir_test7";
#[test] #[test]
fn test_mkdir_mkdir() { fn test_mkdir_mkdir() {

View file

@ -3,19 +3,19 @@ use crate::common::util::*;
use std::path::PathBuf; use std::path::PathBuf;
use tempfile::tempdir; use tempfile::tempdir;
static TEST_TEMPLATE1: &'static str = "tempXXXXXX"; static TEST_TEMPLATE1: &str = "tempXXXXXX";
static TEST_TEMPLATE2: &'static str = "temp"; static TEST_TEMPLATE2: &str = "temp";
static TEST_TEMPLATE3: &'static str = "tempX"; static TEST_TEMPLATE3: &str = "tempX";
static TEST_TEMPLATE4: &'static str = "tempXX"; static TEST_TEMPLATE4: &str = "tempXX";
static TEST_TEMPLATE5: &'static str = "tempXXX"; static TEST_TEMPLATE5: &str = "tempXXX";
static TEST_TEMPLATE6: &'static str = "tempXXXlate"; static TEST_TEMPLATE6: &str = "tempXXXlate";
static TEST_TEMPLATE7: &'static str = "XXXtemplate"; static TEST_TEMPLATE7: &str = "XXXtemplate";
#[cfg(unix)] #[cfg(unix)]
static TEST_TEMPLATE8: &'static str = "tempXXXl/ate"; static TEST_TEMPLATE8: &str = "tempXXXl/ate";
#[cfg(windows)] #[cfg(windows)]
static TEST_TEMPLATE8: &'static str = "tempXXXl\\ate"; static TEST_TEMPLATE8: &str = "tempXXXl\\ate";
const TMPDIR: &'static str = "TMPDIR"; const TMPDIR: &str = "TMPDIR";
#[test] #[test]
fn test_mktemp_mktemp() { fn test_mktemp_mktemp() {

View file

@ -82,7 +82,7 @@ fn test_mv_strip_slashes() {
let dir = "test_mv_strip_slashes_dir"; let dir = "test_mv_strip_slashes_dir";
let file = "test_mv_strip_slashes_file"; let file = "test_mv_strip_slashes_file";
let mut source = file.to_owned(); let mut source = file.to_owned();
source.push_str("/"); source.push('/');
at.mkdir(dir); at.mkdir(dir);
at.touch(file); at.touch(file);

View file

@ -9,7 +9,7 @@ use std::io::Write;
use std::path::Path; use std::path::Path;
// octal dump of 'abcdefghijklmnopqrstuvwxyz\n' // octal dump of 'abcdefghijklmnopqrstuvwxyz\n'
static ALPHA_OUT: &'static str = " static ALPHA_OUT: &str = "
0000000 061141 062143 063145 064147 065151 066153 067155 070157 0000000 061141 062143 063145 064147 065151 066153 067155 070157
0000020 071161 072163 073165 074167 075171 000012 0000020 071161 072163 073165 074167 075171 000012
0000033 0000033
@ -563,7 +563,7 @@ fn test_dec_offset() {
#[test] #[test]
fn test_no_offset() { fn test_no_offset() {
let input = [0u8; 31]; let input = [0u8; 31];
const LINE: &'static str = " 00000000 00000000 00000000 00000000\n"; const LINE: &str = " 00000000 00000000 00000000 00000000\n";
let expected_output = [LINE, LINE, LINE, LINE].join(""); let expected_output = [LINE, LINE, LINE, LINE].join("");
new_ucmd!() new_ucmd!()

View file

@ -7,7 +7,7 @@ struct TestData<'b> {
out: &'b str, out: &'b str,
} }
static EXAMPLE_DATA: &'static [TestData<'static>] = &[ static EXAMPLE_DATA: &[TestData] = &[
// Ensure that paste properly handles files lacking a final newline. // Ensure that paste properly handles files lacking a final newline.
TestData { TestData {
name: "no-nl-1", name: "no-nl-1",
@ -64,8 +64,8 @@ static EXAMPLE_DATA: &'static [TestData<'static>] = &[
#[test] #[test]
fn test_combine_pairs_of_lines() { fn test_combine_pairs_of_lines() {
for s in vec!["-s", "--serial"] { for &s in &["-s", "--serial"] {
for d in vec!["-d", "--delimiters"] { for &d in &["-d", "--delimiters"] {
new_ucmd!() new_ucmd!()
.args(&[s, d, "\t\n", "html_colors.txt"]) .args(&[s, d, "\t\n", "html_colors.txt"])
.run() .run()
@ -76,7 +76,7 @@ fn test_combine_pairs_of_lines() {
#[test] #[test]
fn test_multi_stdin() { fn test_multi_stdin() {
for d in vec!["-d", "--delimiters"] { for &d in &["-d", "--delimiters"] {
new_ucmd!() new_ucmd!()
.args(&[d, "\t\n", "-", "-"]) .args(&[d, "\t\n", "-", "-"])
.pipe_in_fixture("html_colors.txt") .pipe_in_fixture("html_colors.txt")

View file

@ -1,6 +1,6 @@
use crate::common::util::*; use crate::common::util::*;
static GIBBERISH: &'static str = "supercalifragilisticexpialidocious"; static GIBBERISH: &str = "supercalifragilisticexpialidocious";
#[test] #[test]
fn test_canonicalize() { fn test_canonicalize() {

View file

@ -61,6 +61,7 @@ const TESTS: [TestCase; 10] = [
}, },
]; ];
#[allow(clippy::needless_lifetimes)]
fn convert_path<'a>(path: &'a str) -> Cow<'a, str> { fn convert_path<'a>(path: &'a str) -> Cow<'a, str> {
#[cfg(windows)] #[cfg(windows)]
return path.replace("/", "\\").into(); return path.replace("/", "\\").into();

View file

@ -14,11 +14,11 @@ fn test_output_is_random_permutation() {
let mut result_seq: Vec<i32> = result let mut result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\n") .split('\n')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
result_seq.sort(); result_seq.sort_unstable();
assert_ne!(result.stdout_str(), input, "Output is not randomised"); assert_ne!(result.stdout_str(), input, "Output is not randomised");
assert_eq!(result_seq, input_seq, "Output is not a permutation"); assert_eq!(result_seq, input_seq, "Output is not a permutation");
} }
@ -31,11 +31,11 @@ fn test_zero_termination() {
let mut result_seq: Vec<i32> = result let mut result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\0") .split('\0')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
result_seq.sort(); result_seq.sort_unstable();
assert_eq!(result_seq, input_seq, "Output is not a permutation"); assert_eq!(result_seq, input_seq, "Output is not a permutation");
} }
@ -55,11 +55,11 @@ fn test_echo() {
let mut result_seq: Vec<i32> = result let mut result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\n") .split('\n')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
result_seq.sort(); result_seq.sort_unstable();
assert_eq!(result_seq, input_seq, "Output is not a permutation"); assert_eq!(result_seq, input_seq, "Output is not a permutation");
} }
@ -81,11 +81,11 @@ fn test_head_count() {
let mut result_seq: Vec<i32> = result let mut result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\n") .split('\n')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
result_seq.sort(); result_seq.sort_unstable();
assert_eq!(result_seq.len(), repeat_limit, "Output is not limited"); assert_eq!(result_seq.len(), repeat_limit, "Output is not limited");
assert!( assert!(
result_seq.iter().all(|x| input_seq.contains(x)), result_seq.iter().all(|x| input_seq.contains(x)),
@ -113,7 +113,7 @@ fn test_repeat() {
let result_seq: Vec<i32> = result let result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\n") .split('\n')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
@ -141,11 +141,11 @@ fn test_file_input() {
let mut result_seq: Vec<i32> = result let mut result_seq: Vec<i32> = result
.stdout_str() .stdout_str()
.split("\n") .split('\n')
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.map(|x| x.parse().unwrap()) .map(|x| x.parse().unwrap())
.collect(); .collect();
result_seq.sort(); result_seq.sort_unstable();
assert_eq!(result_seq, expected_seq, "Output is not a permutation"); assert_eq!(result_seq, expected_seq, "Output is not a permutation");
} }

View file

@ -288,7 +288,7 @@ fn test_dictionary_order() {
#[test] #[test]
fn test_dictionary_order2() { fn test_dictionary_order2() {
for non_dictionary_order2_param in vec!["-d"] { for non_dictionary_order2_param in &["-d"] {
new_ucmd!() new_ucmd!()
.pipe_in("a👦🏻aa b\naaaa b") .pipe_in("a👦🏻aa b\naaaa b")
.arg(non_dictionary_order2_param) .arg(non_dictionary_order2_param)
@ -299,7 +299,7 @@ fn test_dictionary_order2() {
#[test] #[test]
fn test_non_printing_chars() { fn test_non_printing_chars() {
for non_printing_chars_param in vec!["-i"] { for non_printing_chars_param in &["-i"] {
new_ucmd!() new_ucmd!()
.pipe_in("a👦🏻aa\naaaa") .pipe_in("a👦🏻aa\naaaa")
.arg(non_printing_chars_param) .arg(non_printing_chars_param)
@ -361,7 +361,7 @@ fn test_mixed_floats_ints_chars_numeric_stable() {
#[test] #[test]
fn test_numeric_floats_and_ints2() { fn test_numeric_floats_and_ints2() {
for numeric_sort_param in vec!["-n", "--numeric-sort"] { for numeric_sort_param in &["-n", "--numeric-sort"] {
let input = "1.444\n8.013\n1\n-8\n1.04\n-1"; let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
new_ucmd!() new_ucmd!()
.arg(numeric_sort_param) .arg(numeric_sort_param)
@ -373,7 +373,7 @@ fn test_numeric_floats_and_ints2() {
#[test] #[test]
fn test_numeric_floats2() { fn test_numeric_floats2() {
for numeric_sort_param in vec!["-n", "--numeric-sort"] { for numeric_sort_param in &["-n", "--numeric-sort"] {
let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05"; let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
new_ucmd!() new_ucmd!()
.arg(numeric_sort_param) .arg(numeric_sort_param)
@ -426,7 +426,7 @@ fn test_default_unsorted_ints2() {
#[test] #[test]
fn test_numeric_unique_ints2() { fn test_numeric_unique_ints2() {
for numeric_unique_sort_param in vec!["-nu"] { for numeric_unique_sort_param in &["-nu"] {
let input = "9\n9\n8\n1\n"; let input = "9\n9\n8\n1\n";
new_ucmd!() new_ucmd!()
.arg(numeric_unique_sort_param) .arg(numeric_unique_sort_param)

View file

@ -98,7 +98,7 @@ impl RandomFile {
let to_write = std::cmp::min(remaining_size, buffer.len()); let to_write = std::cmp::min(remaining_size, buffer.len());
let buf = &mut buffer[..to_write]; let buf = &mut buffer[..to_write];
rng.fill(buf); rng.fill(buf);
writer.write(buf).unwrap(); writer.write_all(buf).unwrap();
remaining_size -= to_write; remaining_size -= to_write;
} }
@ -179,6 +179,7 @@ fn test_split_bytes_prime_part_size() {
let mut fns = glob.collect(); let mut fns = glob.collect();
// glob.collect() is not guaranteed to return in sorted order, so we sort. // glob.collect() is not guaranteed to return in sorted order, so we sort.
fns.sort(); fns.sort();
#[allow(clippy::needless_range_loop)]
for i in 0..5 { for i in 0..5 {
assert_eq!(glob.directory.metadata(&fns[i]).len(), 1753); assert_eq!(glob.directory.metadata(&fns[i]).len(), 1753);
} }
@ -246,9 +247,9 @@ fn test_filter() {
assert!( assert!(
glob.collate().iter().find(|&&c| { glob.collate().iter().find(|&&c| {
// is not i // is not i
c != ('i' as u8) c != (b'i')
// is not newline // is not newline
&& c != ('\n' as u8) && c != (b'\n')
}) == None }) == None
); );
} }
@ -271,7 +272,7 @@ fn test_filter_with_env_var_set() {
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$"); let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$");
assert_eq!(glob.collate(), at.read_bytes(name)); assert_eq!(glob.collate(), at.read_bytes(name));
assert!(env::var("FILE").unwrap_or("var was unset".to_owned()) == env_var_value); assert!(env::var("FILE").unwrap_or_else(|_| "var was unset".to_owned()) == env_var_value);
} }
#[test] #[test]

View file

@ -97,13 +97,13 @@ fn test_invalid_option() {
} }
#[cfg(any(target_os = "linux", target_vendor = "apple"))] #[cfg(any(target_os = "linux", target_vendor = "apple"))]
const NORMAL_FMTSTR: &'static str = const NORMAL_FMTSTR: &str =
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations
#[cfg(any(target_os = "linux"))] #[cfg(any(target_os = "linux"))]
const DEV_FMTSTR: &'static str = const DEV_FMTSTR: &str =
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z"; "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z";
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
const FS_FMTSTR: &'static str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions const FS_FMTSTR: &str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -140,7 +140,7 @@ fn test_terse_normal_format() {
assert!(!v_expect.is_empty()); assert!(!v_expect.is_empty());
// uu_stat does not support selinux // uu_stat does not support selinux
if v_actual.len() == v_expect.len() - 1 && v_expect[v_expect.len() - 1].contains(":") { if v_actual.len() == v_expect.len() - 1 && v_expect[v_expect.len() - 1].contains(':') {
// assume last element contains: `SELinux security context string` // assume last element contains: `SELinux security context string`
v_expect.pop(); v_expect.pop();
} }
@ -222,7 +222,7 @@ fn test_symlinks() {
let mut tested: bool = false; let mut tested: bool = false;
// arbitrarily chosen symlinks with hope that the CI environment provides at least one of them // arbitrarily chosen symlinks with hope that the CI environment provides at least one of them
for file in vec![ for file in &[
"/bin/sh", "/bin/sh",
"/bin/sudoedit", "/bin/sudoedit",
"/usr/bin/ex", "/usr/bin/ex",

View file

@ -5,9 +5,9 @@ use crate::common::util::*;
use std::char::from_digit; use std::char::from_digit;
use std::io::Write; use std::io::Write;
static FOOBAR_TXT: &'static str = "foobar.txt"; static FOOBAR_TXT: &str = "foobar.txt";
static FOOBAR_2_TXT: &'static str = "foobar2.txt"; static FOOBAR_2_TXT: &str = "foobar2.txt";
static FOOBAR_WITH_NULL_TXT: &'static str = "foobar_with_null.txt"; static FOOBAR_WITH_NULL_TXT: &str = "foobar_with_null.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {
@ -153,8 +153,8 @@ fn test_follow_with_pid() {
#[test] #[test]
fn test_single_big_args() { fn test_single_big_args() {
const FILE: &'static str = "single_big_args.txt"; const FILE: &str = "single_big_args.txt";
const EXPECTED_FILE: &'static str = "single_big_args_expected.txt"; const EXPECTED_FILE: &str = "single_big_args_expected.txt";
const LINES: usize = 1_000_000; const LINES: usize = 1_000_000;
const N_ARG: usize = 100_000; const N_ARG: usize = 100_000;
@ -162,13 +162,13 @@ fn test_single_big_args() {
let mut big_input = at.make_file(FILE); let mut big_input = at.make_file(FILE);
for i in 0..LINES { for i in 0..LINES {
write!(&mut big_input, "Line {}\n", i).expect("Could not write to FILE"); writeln!(&mut big_input, "Line {}", i).expect("Could not write to FILE");
} }
big_input.flush().expect("Could not flush FILE"); big_input.flush().expect("Could not flush FILE");
let mut big_expected = at.make_file(EXPECTED_FILE); let mut big_expected = at.make_file(EXPECTED_FILE);
for i in (LINES - N_ARG)..LINES { for i in (LINES - N_ARG)..LINES {
write!(&mut big_expected, "Line {}\n", i).expect("Could not write to EXPECTED_FILE"); writeln!(&mut big_expected, "Line {}", i).expect("Could not write to EXPECTED_FILE");
} }
big_expected.flush().expect("Could not flush EXPECTED_FILE"); big_expected.flush().expect("Could not flush EXPECTED_FILE");
@ -201,8 +201,8 @@ fn test_bytes_stdin() {
#[test] #[test]
fn test_bytes_big() { fn test_bytes_big() {
const FILE: &'static str = "test_bytes_big.txt"; const FILE: &str = "test_bytes_big.txt";
const EXPECTED_FILE: &'static str = "test_bytes_big_expected.txt"; const EXPECTED_FILE: &str = "test_bytes_big_expected.txt";
const BYTES: usize = 1_000_000; const BYTES: usize = 1_000_000;
const N_ARG: usize = 100_000; const N_ARG: usize = 100_000;
@ -257,10 +257,10 @@ fn test_parse_size() {
for &(c, exp) in &suffixes { for &(c, exp) in &suffixes {
let s = format!("2{}B", c); let s = format!("2{}B", c);
assert_eq!(Ok(2 * (1000 as u64).pow(exp)), parse_size(&s)); assert_eq!(Ok(2 * (1000_u64).pow(exp)), parse_size(&s));
let s = format!("2{}", c); let s = format!("2{}", c);
assert_eq!(Ok(2 * (1024 as u64).pow(exp)), parse_size(&s)); assert_eq!(Ok(2 * (1024_u64).pow(exp)), parse_size(&s));
} }
// Sizes that are too big. // Sizes that are too big.
@ -273,8 +273,8 @@ fn test_parse_size() {
#[test] #[test]
fn test_lines_with_size_suffix() { fn test_lines_with_size_suffix() {
const FILE: &'static str = "test_lines_with_size_suffix.txt"; const FILE: &str = "test_lines_with_size_suffix.txt";
const EXPECTED_FILE: &'static str = "test_lines_with_size_suffix_expected.txt"; const EXPECTED_FILE: &str = "test_lines_with_size_suffix_expected.txt";
const LINES: usize = 3_000; const LINES: usize = 3_000;
const N_ARG: usize = 2 * 1024; const N_ARG: usize = 2 * 1024;

View file

@ -401,8 +401,8 @@ fn get_dstswitch_hour() -> Option<String> {
for _i in 0..(366 * 24) { for _i in 0..(366 * 24) {
if is_dst_switch_hour(ts) { if is_dst_switch_hour(ts) {
let mut tm = time::at(ts); let mut tm = time::at(ts);
tm.tm_hour = tm.tm_hour + 1; tm.tm_hour += 1;
let s = time::strftime("%Y%m%d%H%M", &tm).unwrap().to_string(); let s = time::strftime("%Y%m%d%H%M", &tm).unwrap();
return Some(s); return Some(s);
} }
ts = ts + time::Duration::hours(1); ts = ts + time::Duration::hours(1);
@ -415,10 +415,7 @@ fn test_touch_mtime_dst_fails() {
let (_at, mut ucmd) = at_and_ucmd!(); let (_at, mut ucmd) = at_and_ucmd!();
let file = "test_touch_set_mtime_dst_fails"; let file = "test_touch_set_mtime_dst_fails";
match get_dstswitch_hour() { if let Some(s) = get_dstswitch_hour() {
Some(s) => { ucmd.args(&["-m", "-t", &s, file]).fails();
ucmd.args(&["-m", "-t", &s, file]).fails();
}
None => (),
} }
} }

View file

@ -1,8 +1,8 @@
use crate::common::util::*; use crate::common::util::*;
use std::io::{Seek, SeekFrom, Write}; use std::io::{Seek, SeekFrom, Write};
static TFILE1: &'static str = "truncate_test_1"; static TFILE1: &str = "truncate_test_1";
static TFILE2: &'static str = "truncate_test_2"; static TFILE2: &str = "truncate_test_2";
#[test] #[test]
fn test_increase_file_size() { fn test_increase_file_size() {

View file

@ -1,10 +1,10 @@
use crate::common::util::*; use crate::common::util::*;
static INPUT: &'static str = "sorted.txt"; static INPUT: &str = "sorted.txt";
static OUTPUT: &'static str = "sorted-output.txt"; static OUTPUT: &str = "sorted-output.txt";
static SKIP_CHARS: &'static str = "skip-chars.txt"; static SKIP_CHARS: &str = "skip-chars.txt";
static SKIP_FIELDS: &'static str = "skip-fields.txt"; static SKIP_FIELDS: &str = "skip-fields.txt";
static SORTED_ZERO_TERMINATED: &'static str = "sorted-zero-terminated.txt"; static SORTED_ZERO_TERMINATED: &str = "sorted-zero-terminated.txt";
#[test] #[test]
fn test_stdin_default() { fn test_stdin_default() {

View file

@ -3,7 +3,7 @@ use crate::common::util::*;
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_count() { fn test_count() {
for opt in vec!["-q", "--count"] { for opt in &["-q", "--count"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -14,7 +14,7 @@ fn test_count() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_boot() { fn test_boot() {
for opt in vec!["-b", "--boot"] { for opt in &["-b", "--boot"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -25,7 +25,7 @@ fn test_boot() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_heading() { fn test_heading() {
for opt in vec!["-H", "--heading"] { for opt in &["-H", "--heading"] {
// allow whitespace variation // allow whitespace variation
// * minor whitespace differences occur between platform built-in outputs; // * minor whitespace differences occur between platform built-in outputs;
// specifically number of TABs between "TIME" and "COMMENT" may be variant // specifically number of TABs between "TIME" and "COMMENT" may be variant
@ -42,7 +42,7 @@ fn test_heading() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_short() { fn test_short() {
for opt in vec!["-s", "--short"] { for opt in &["-s", "--short"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -53,7 +53,7 @@ fn test_short() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_login() { fn test_login() {
for opt in vec!["-l", "--login"] { for opt in &["-l", "--login"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -64,7 +64,7 @@ fn test_login() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_m() { fn test_m() {
for opt in vec!["-m"] { for opt in &["-m"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -75,7 +75,7 @@ fn test_m() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_process() { fn test_process() {
for opt in vec!["-p", "--process"] { for opt in &["-p", "--process"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -85,7 +85,7 @@ fn test_process() {
#[test] #[test]
fn test_runlevel() { fn test_runlevel() {
for opt in vec!["-r", "--runlevel"] { for opt in &["-r", "--runlevel"] {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
@ -100,7 +100,7 @@ fn test_runlevel() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_time() { fn test_time() {
for opt in vec!["-t", "--time"] { for opt in &["-t", "--time"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -117,7 +117,7 @@ fn test_mesg() {
// same as -T // same as -T
// --writable // --writable
// same as -T // same as -T
for opt in vec!["-T", "-w", "--mesg", "--message", "--writable"] { for opt in &["-T", "-w", "--mesg", "--message", "--writable"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -147,7 +147,7 @@ fn test_too_many_args() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_users() { fn test_users() {
for opt in vec!["-u", "--users"] { for opt in &["-u", "--users"] {
let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str(); let actual = new_ucmd!().arg(opt).succeeds().stdout_move_str();
let expect = expected_result(&[opt]); let expect = expected_result(&[opt]);
println!("actual: {:?}", actual); println!("actual: {:?}", actual);
@ -172,18 +172,17 @@ fn test_users() {
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_lookup() { fn test_lookup() {
for opt in vec!["--lookup"] { let opt = "--lookup";
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
.stdout_is(expected_result(&[opt])); .stdout_is(expected_result(&[opt]));
}
} }
#[cfg(any(target_vendor = "apple", target_os = "linux"))] #[cfg(any(target_vendor = "apple", target_os = "linux"))]
#[test] #[test]
fn test_dead() { fn test_dead() {
for opt in vec!["-d", "--dead"] { for opt in &["-d", "--dead"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
@ -222,7 +221,7 @@ fn test_all() {
return; return;
} }
for opt in vec!["-a", "--all"] { for opt in &["-a", "--all"] {
new_ucmd!() new_ucmd!()
.arg(opt) .arg(opt)
.succeeds() .succeeds()

View file

@ -1,7 +1,4 @@
#![allow(dead_code)] #![allow(dead_code)]
#[cfg(not(windows))]
use libc;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use std::env; use std::env;
#[cfg(not(windows))] #[cfg(not(windows))]
@ -39,7 +36,7 @@ static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is
/// Test if the program is running under CI /// Test if the program is running under CI
pub fn is_ci() -> bool { pub fn is_ci() -> bool {
std::env::var("CI") std::env::var("CI")
.unwrap_or(String::from("false")) .unwrap_or_else(|_| String::from("false"))
.eq_ignore_ascii_case("true") .eq_ignore_ascii_case("true")
} }
@ -464,7 +461,7 @@ impl AtPath {
.append(true) .append(true)
.open(self.plus(name)) .open(self.plus(name))
.unwrap(); .unwrap();
f.write(contents.as_bytes()) f.write_all(contents.as_bytes())
.unwrap_or_else(|e| panic!("Couldn't write {}: {}", name, e)); .unwrap_or_else(|e| panic!("Couldn't write {}: {}", name, e));
} }
@ -777,7 +774,7 @@ impl UCommand {
if self.has_run { if self.has_run {
panic!("{}", ALREADY_RUN); panic!("{}", ALREADY_RUN);
} }
self.comm_string.push_str(" "); self.comm_string.push(' ');
self.comm_string self.comm_string
.push_str(arg.as_ref().to_str().unwrap_or_default()); .push_str(arg.as_ref().to_str().unwrap_or_default());
self.raw.arg(arg.as_ref()); self.raw.arg(arg.as_ref());
@ -797,7 +794,7 @@ impl UCommand {
.accept_any(); .accept_any();
for s in strings { for s in strings {
self.comm_string.push_str(" "); self.comm_string.push(' ');
self.comm_string.push_str(&s); self.comm_string.push_str(&s);
} }
@ -853,9 +850,9 @@ impl UCommand {
log_info("run", &self.comm_string); log_info("run", &self.comm_string);
let mut child = self let mut child = self
.raw .raw
.stdin(self.stdin.take().unwrap_or_else(|| Stdio::piped())) .stdin(self.stdin.take().unwrap_or_else(Stdio::piped))
.stdout(self.stdout.take().unwrap_or_else(|| Stdio::piped())) .stdout(self.stdout.take().unwrap_or_else(Stdio::piped))
.stderr(self.stderr.take().unwrap_or_else(|| Stdio::piped())) .stderr(self.stderr.take().unwrap_or_else(Stdio::piped))
.spawn() .spawn()
.unwrap(); .unwrap();
@ -929,10 +926,7 @@ pub fn read_size(child: &mut Child, size: usize) -> String {
} }
pub fn vec_of_size(n: usize) -> Vec<u8> { pub fn vec_of_size(n: usize) -> Vec<u8> {
let mut result = Vec::new(); let result = vec![b'a'; n];
for _ in 0..n {
result.push('a' as u8);
}
assert_eq!(result.len(), n); assert_eq!(result.len(), n);
result result
} }