1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #4043 from sylvestre/clippy

Fix some clippy warnings
This commit is contained in:
Terts Diepraam 2022-10-13 14:03:57 +02:00 committed by GitHub
commit 28127a433e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 122 additions and 126 deletions

View file

@ -27,7 +27,7 @@ const USAGE: &str = "\
fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> { fn parse_gid_and_uid(matches: &ArgMatches) -> UResult<(Option<u32>, Option<u32>, IfFrom)> {
let dest_gid = if let Some(file) = matches.get_one::<String>(options::REFERENCE) { let dest_gid = if let Some(file) = matches.get_one::<String>(options::REFERENCE) {
fs::metadata(&file) fs::metadata(file)
.map(|meta| Some(meta.gid())) .map(|meta| Some(meta.gid()))
.map_err_context(|| format!("failed to get attributes of {}", file.quote()))? .map_err_context(|| format!("failed to get attributes of {}", file.quote()))?
} else { } else {

View file

@ -40,7 +40,7 @@ fn parse_gid_uid_and_filter(matches: &ArgMatches) -> UResult<(Option<u32>, Optio
let dest_uid: Option<u32>; let dest_uid: Option<u32>;
let dest_gid: Option<u32>; let dest_gid: Option<u32>;
if let Some(file) = matches.get_one::<String>(options::REFERENCE) { if let Some(file) = matches.get_one::<String>(options::REFERENCE) {
let meta = fs::metadata(&file) let meta = fs::metadata(file)
.map_err_context(|| format!("failed to get attributes of {}", file.quote()))?; .map_err_context(|| format!("failed to get attributes of {}", file.quote()))?;
dest_gid = Some(meta.gid()); dest_gid = Some(meta.gid());
dest_uid = Some(meta.uid()); dest_uid = Some(meta.uid());

View file

@ -124,7 +124,7 @@ fn open_file(name: &str) -> io::Result<LineReader> {
match name { match name {
"-" => Ok(LineReader::Stdin(stdin())), "-" => Ok(LineReader::Stdin(stdin())),
_ => { _ => {
let f = File::open(&Path::new(name))?; let f = File::open(Path::new(name))?;
Ok(LineReader::FileIn(BufReader::new(f))) Ok(LineReader::FileIn(BufReader::new(f)))
} }
} }

View file

@ -1115,7 +1115,7 @@ fn copy_directory(
.follow_links(options.dereference) .follow_links(options.dereference)
{ {
let p = or_continue!(path); let p = or_continue!(path);
let path = current_dir.join(&p.path()); let path = current_dir.join(p.path());
let local_to_root_parent = match root_parent { let local_to_root_parent = match root_parent {
Some(parent) => { Some(parent) => {
@ -1131,7 +1131,7 @@ fn copy_directory(
} }
#[cfg(not(windows))] #[cfg(not(windows))]
{ {
or_continue!(path.strip_prefix(&parent)).to_path_buf() or_continue!(path.strip_prefix(parent)).to_path_buf()
} }
} }
None => path.clone(), None => path.clone(),
@ -1351,7 +1351,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: &Path) -> 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())
} }
@ -1566,7 +1566,7 @@ fn copy_file(
.write(true) .write(true)
.truncate(false) .truncate(false)
.create(true) .create(true)
.open(&dest) .open(dest)
.unwrap(); .unwrap();
} }
}; };
@ -1630,7 +1630,7 @@ fn copy_helper(
fn copy_fifo(dest: &Path, overwrite: OverwriteMode) -> CopyResult<()> { fn copy_fifo(dest: &Path, overwrite: OverwriteMode) -> CopyResult<()> {
if dest.exists() { if dest.exists() {
overwrite.verify(dest)?; overwrite.verify(dest)?;
fs::remove_file(&dest)?; fs::remove_file(dest)?;
} }
let name = CString::new(dest.as_os_str().as_bytes()).unwrap(); let name = CString::new(dest.as_os_str().as_bytes()).unwrap();
@ -1647,7 +1647,7 @@ fn copy_link(
symlinked_files: &mut HashSet<FileInformation>, symlinked_files: &mut HashSet<FileInformation>,
) -> CopyResult<()> { ) -> CopyResult<()> {
// Here, we will copy the symlink itself (actually, just recreate it) // Here, we will copy the symlink itself (actually, just recreate it)
let link = fs::read_link(&source)?; let link = fs::read_link(source)?;
let dest: Cow<'_, Path> = if dest.is_dir() { let dest: Cow<'_, Path> = if dest.is_dir() {
match source.file_name() { match source.file_name() {
Some(name) => dest.join(name).into(), Some(name) => dest.join(name).into(),
@ -1695,8 +1695,8 @@ pub fn verify_target_type(target: &Path, target_type: &TargetType) -> CopyResult
/// ).unwrap() == Path::new("target/c.txt")) /// ).unwrap() == Path::new("target/c.txt"))
/// ``` /// ```
pub fn localize_to_target(root: &Path, source: &Path, target: &Path) -> CopyResult<PathBuf> { pub fn localize_to_target(root: &Path, source: &Path, target: &Path) -> CopyResult<PathBuf> {
let local_to_root = source.strip_prefix(&root)?; let local_to_root = source.strip_prefix(root)?;
Ok(target.join(&local_to_root)) Ok(target.join(local_to_root))
} }
pub fn path_has_prefix(p1: &Path, p2: &Path) -> io::Result<bool> { pub fn path_has_prefix(p1: &Path, p2: &Path) -> io::Result<bool> {

View file

@ -368,7 +368,7 @@ fn cut_files(mut filenames: Vec<String>, mode: &Mode) -> UResult<()> {
continue; continue;
} }
show_if_err!(File::open(&path) show_if_err!(File::open(path)
.map_err_context(|| filename.maybe_quote().to_string()) .map_err_context(|| filename.maybe_quote().to_string())
.and_then(|file| { .and_then(|file| {
match &mode { match &mode {

View file

@ -492,7 +492,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
let exclude_from_iterator = matches let exclude_from_iterator = matches
.get_many::<String>(options::EXCLUDE_FROM) .get_many::<String>(options::EXCLUDE_FROM)
.unwrap_or_default() .unwrap_or_default()
.flat_map(|f| file_as_vec(&f)); .flat_map(file_as_vec);
let excludes_iterator = matches let excludes_iterator = matches
.get_many::<String>(options::EXCLUDE) .get_many::<String>(options::EXCLUDE)
@ -913,7 +913,7 @@ impl FromStr for Threshold {
type Err = ParseSizeError; type Err = ParseSizeError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
let offset = if s.starts_with(&['-', '+'][..]) { 1 } else { 0 }; let offset = usize::from(s.starts_with(&['-', '+'][..]));
let size = parse_size(&s[offset..])?; let size = parse_size(&s[offset..])?;

View file

@ -505,11 +505,7 @@ fn prefix_operator_substr(values: &[String]) -> String {
} }
fn bool_as_int(b: bool) -> u8 { fn bool_as_int(b: bool) -> u8 {
if b { u8::from(b)
1
} else {
0
}
} }
fn bool_as_string(b: bool) -> String { fn bool_as_string(b: bool) -> String {
if b { if b {

View file

@ -275,7 +275,7 @@ impl Params {
// For example, if `tmpdir` is "a/b" and the template is "c/dXXX", // For example, if `tmpdir` is "a/b" and the template is "c/dXXX",
// then `prefix` is "a/b/c/d". // then `prefix` is "a/b/c/d".
let tmpdir = options.tmpdir; let tmpdir = options.tmpdir;
let prefix_from_option = tmpdir.clone().unwrap_or_else(|| "".to_string()); let prefix_from_option = tmpdir.clone().unwrap_or_default();
let prefix_from_template = &options.template[..i]; let prefix_from_template = &options.template[..i];
let prefix = Path::new(&prefix_from_option) let prefix = Path::new(&prefix_from_option)
.join(prefix_from_template) .join(prefix_from_template)
@ -311,7 +311,7 @@ impl Params {
// //
// For example, if the suffix command-line argument is ".txt" and // For example, if the suffix command-line argument is ".txt" and
// the template is "XXXabc", then `suffix` is "abc.txt". // the template is "XXXabc", then `suffix` is "abc.txt".
let suffix_from_option = options.suffix.unwrap_or_else(|| "".to_string()); let suffix_from_option = options.suffix.unwrap_or_default();
let suffix_from_template = &options.template[j..]; let suffix_from_template = &options.template[j..];
let suffix = format!("{}{}", suffix_from_template, suffix_from_option); let suffix = format!("{}{}", suffix_from_template, suffix_from_option);
if suffix.contains(MAIN_SEPARATOR) { if suffix.contains(MAIN_SEPARATOR) {
@ -484,7 +484,7 @@ pub fn dry_exec(tmpdir: &str, prefix: &str, rand: usize, suffix: &str) -> UResul
fn make_temp_dir(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> { fn make_temp_dir(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> {
let mut builder = Builder::new(); let mut builder = Builder::new();
builder.prefix(prefix).rand_bytes(rand).suffix(suffix); builder.prefix(prefix).rand_bytes(rand).suffix(suffix);
match builder.tempdir_in(&dir) { match builder.tempdir_in(dir) {
Ok(d) => { Ok(d) => {
// `into_path` consumes the TempDir without removing it // `into_path` consumes the TempDir without removing it
let path = d.into_path(); let path = d.into_path();
@ -516,7 +516,7 @@ fn make_temp_dir(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult<
fn make_temp_file(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> { fn make_temp_file(dir: &str, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> {
let mut builder = Builder::new(); let mut builder = Builder::new();
builder.prefix(prefix).rand_bytes(rand).suffix(suffix); builder.prefix(prefix).rand_bytes(rand).suffix(suffix);
match builder.tempfile_in(&dir) { match builder.tempfile_in(dir) {
// `keep` ensures that the file is not deleted // `keep` ensures that the file is not deleted
Ok(named_tempfile) => match named_tempfile.keep() { Ok(named_tempfile) => match named_tempfile.keep() {
Ok((_, pathbuf)) => Ok(pathbuf), Ok((_, pathbuf)) => Ok(pathbuf),

View file

@ -453,7 +453,7 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
let path_symlink_points_to = fs::read_link(from)?; let path_symlink_points_to = fs::read_link(from)?;
#[cfg(unix)] #[cfg(unix)]
{ {
unix::fs::symlink(&path_symlink_points_to, &to).and_then(|_| fs::remove_file(&from))?; unix::fs::symlink(&path_symlink_points_to, to).and_then(|_| fs::remove_file(from))?;
} }
#[cfg(windows)] #[cfg(windows)]
{ {

View file

@ -279,7 +279,7 @@ fn nl<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UResult<()> {
// If we have already seen three groups (corresponding to // If we have already seen three groups (corresponding to
// a header) or the current char does not form part of // a header) or the current char does not form part of
// a new group, then this line is not a segment indicator. // a new group, then this line is not a segment indicator.
if matched_groups >= 3 || settings.section_delimiter[if odd { 1 } else { 0 }] != c { if matched_groups >= 3 || settings.section_delimiter[usize::from(odd)] != c {
matched_groups = 0; matched_groups = 0;
break; break;
} }

View file

@ -1086,7 +1086,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let mut files = Vec::new(); let mut files = Vec::new();
for path in &files0_from { for path in &files0_from {
let reader = open(&path)?; let reader = open(path)?;
let buf_reader = BufReader::new(reader); let buf_reader = BufReader::new(reader);
for line in buf_reader.split(b'\0').flatten() { for line in buf_reader.split(b'\0').flatten() {
files.push(OsString::from( files.push(OsString::from(

View file

@ -80,7 +80,7 @@ impl TmpDirWrapper {
/// Remove the directory at `path` by deleting its child files and then itself. /// Remove the directory at `path` by deleting its child files and then itself.
/// Errors while deleting child files are ignored. /// Errors while deleting child files are ignored.
fn remove_tmp_dir(path: &Path) -> std::io::Result<()> { fn remove_tmp_dir(path: &Path) -> std::io::Result<()> {
if let Ok(read_dir) = std::fs::read_dir(&path) { if let Ok(read_dir) = std::fs::read_dir(path) {
for file in read_dir.flatten() { for file in read_dir.flatten() {
// if we fail to delete the file here it was probably deleted by another thread // if we fail to delete the file here it was probably deleted by another thread
// in the meantime, but that's ok. // in the meantime, but that's ok.

View file

@ -56,7 +56,7 @@ impl Drop for WithEnvVarSet {
/// Restore previous value now that this is being dropped by context /// Restore previous value now that this is being dropped by context
fn drop(&mut self) { fn drop(&mut self) {
if let Ok(ref prev_value) = self._previous_var_value { if let Ok(ref prev_value) = self._previous_var_value {
env::set_var(&self._previous_var_key, &prev_value); env::set_var(&self._previous_var_key, prev_value);
} else { } else {
env::remove_var(&self._previous_var_key); env::remove_var(&self._previous_var_key);
} }

View file

@ -207,7 +207,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.short(options::INPUT_SHORT) .short(options::INPUT_SHORT)
.help("adjust standard input stream buffering") .help("adjust standard input stream buffering")
.value_name("MODE") .value_name("MODE")
.required_unless_present_any(&[options::OUTPUT, options::ERROR]), .required_unless_present_any([options::OUTPUT, options::ERROR]),
) )
.arg( .arg(
Arg::new(options::OUTPUT) Arg::new(options::OUTPUT)
@ -215,7 +215,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.short(options::OUTPUT_SHORT) .short(options::OUTPUT_SHORT)
.help("adjust standard output stream buffering") .help("adjust standard output stream buffering")
.value_name("MODE") .value_name("MODE")
.required_unless_present_any(&[options::INPUT, options::ERROR]), .required_unless_present_any([options::INPUT, options::ERROR]),
) )
.arg( .arg(
Arg::new(options::ERROR) Arg::new(options::ERROR)
@ -223,7 +223,7 @@ pub fn uu_app<'a>() -> Command<'a> {
.short(options::ERROR_SHORT) .short(options::ERROR_SHORT)
.help("adjust standard error stream buffering") .help("adjust standard error stream buffering")
.value_name("MODE") .value_name("MODE")
.required_unless_present_any(&[options::INPUT, options::OUTPUT]), .required_unless_present_any([options::INPUT, options::OUTPUT]),
) )
.arg( .arg(
Arg::new(options::COMMAND) Arg::new(options::COMMAND)

View file

@ -122,7 +122,7 @@ impl FileHandling {
*/ */
self.get_mut(path) self.get_mut(path)
.reader .reader
.replace(Box::new(BufReader::new(File::open(&path)?))); .replace(Box::new(BufReader::new(File::open(path)?)));
Ok(()) Ok(())
} }

View file

@ -155,7 +155,7 @@ fn tail_file(
watcher_service.add_bad_path(path, input.display_name.as_str(), false)?; watcher_service.add_bad_path(path, input.display_name.as_str(), false)?;
} else if input.is_tailable() { } else if input.is_tailable() {
let metadata = path.metadata().ok(); let metadata = path.metadata().ok();
match File::open(&path) { match File::open(path) {
Ok(mut file) => { Ok(mut file) => {
input_service.print_header(input); input_service.print_header(input);
let mut reader; let mut reader;

View file

@ -220,7 +220,7 @@ fn open(path: &str) -> BufReader<Box<dyn Read + 'static>> {
if path == "-" { if path == "-" {
BufReader::new(Box::new(stdin()) as Box<dyn Read>) BufReader::new(Box::new(stdin()) as Box<dyn Read>)
} else { } else {
file_buf = match File::open(&path) { file_buf = match File::open(path) {
Ok(a) => a, Ok(a) => a,
Err(e) => crash!(1, "{}: {}", path.maybe_quote(), e), Err(e) => crash!(1, "{}: {}", path.maybe_quote(), e),
}; };

View file

@ -424,7 +424,7 @@ fn open_input_file(in_file_name: &str) -> UResult<BufReader<Box<dyn Read + 'stat
Box::new(stdin()) as Box<dyn Read> Box::new(stdin()) as Box<dyn Read>
} else { } else {
let path = Path::new(in_file_name); let path = Path::new(in_file_name);
let in_file = File::open(&path) let in_file = File::open(path)
.map_err_context(|| format!("Could not open {}", in_file_name.maybe_quote()))?; .map_err_context(|| format!("Could not open {}", in_file_name.maybe_quote()))?;
Box::new(in_file) as Box<dyn Read> Box::new(in_file) as Box<dyn Read>
}; };
@ -436,7 +436,7 @@ fn open_output_file(out_file_name: &str) -> UResult<BufWriter<Box<dyn Write + 's
Box::new(stdout()) as Box<dyn Write> Box::new(stdout()) as Box<dyn Write>
} else { } else {
let path = Path::new(out_file_name); let path = Path::new(out_file_name);
let out_file = File::create(&path) let out_file = File::create(path)
.map_err_context(|| format!("Could not create {}", out_file_name.maybe_quote()))?; .map_err_context(|| format!("Could not create {}", out_file_name.maybe_quote()))?;
Box::new(out_file) as Box<dyn Write> Box::new(out_file) as Box<dyn Write>
}; };

View file

@ -355,7 +355,7 @@ pub fn canonicalize<P: AsRef<Path>>(
followed_symlinks += 1; followed_symlinks += 1;
} else { } else {
let file_info = let file_info =
FileInformation::from_path(&result.parent().unwrap(), false).unwrap(); FileInformation::from_path(result.parent().unwrap(), false).unwrap();
let mut path_to_follow = PathBuf::new(); let mut path_to_follow = PathBuf::new();
for part in &parts { for part in &parts {
path_to_follow.push(part.as_os_str()); path_to_follow.push(part.as_os_str());

View file

@ -76,9 +76,10 @@ fn test_wrap() {
#[test] #[test]
fn test_wrap_no_arg() { fn test_wrap_no_arg() {
for wrap_param in ["-w", "--wrap"] { for wrap_param in ["-w", "--wrap"] {
new_ucmd!().arg(wrap_param).fails().stderr_contains( new_ucmd!()
&"The argument '--wrap <wrap>' requires a value but none was supplied", .arg(wrap_param)
); .fails()
.stderr_contains("The argument '--wrap <wrap>' requires a value but none was supplied");
} }
} }

View file

@ -8,7 +8,7 @@ use std::ffi::OsStr;
fn test_help() { fn test_help() {
for help_flg in ["-h", "--help"] { for help_flg in ["-h", "--help"] {
new_ucmd!() new_ucmd!()
.arg(&help_flg) .arg(help_flg)
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout_contains("USAGE:"); .stdout_contains("USAGE:");
@ -19,7 +19,7 @@ fn test_help() {
fn test_version() { fn test_version() {
for version_flg in ["-V", "--version"] { for version_flg in ["-V", "--version"] {
assert!(new_ucmd!() assert!(new_ucmd!()
.arg(&version_flg) .arg(version_flg)
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout_str() .stdout_str()

View file

@ -380,7 +380,7 @@ fn test_chmod_non_existing_file() {
.arg("-r,a+w") .arg("-r,a+w")
.arg("does-not-exist") .arg("does-not-exist")
.fails() .fails()
.stderr_contains(&"cannot access 'does-not-exist': No such file or directory"); .stderr_contains("cannot access 'does-not-exist': No such file or directory");
} }
#[test] #[test]
@ -403,7 +403,7 @@ fn test_chmod_preserve_root() {
.arg("755") .arg("755")
.arg("/") .arg("/")
.fails() .fails()
.stderr_contains(&"chmod: it is dangerous to operate recursively on '/'"); .stderr_contains("chmod: it is dangerous to operate recursively on '/'");
} }
#[test] #[test]

View file

@ -107,7 +107,7 @@ fn test_chown_only_owner() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.run(); .run();
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
// try to change to another existing user, e.g. 'root' // try to change to another existing user, e.g. 'root'
scene scene
@ -116,7 +116,7 @@ fn test_chown_only_owner() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -142,7 +142,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.succeeds() .succeeds()
.stderr_contains(&"retained as"); .stderr_contains("retained as");
scene scene
.ucmd() .ucmd()
@ -150,7 +150,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.succeeds() .succeeds()
.stderr_contains(&"retained as"); .stderr_contains("retained as");
scene scene
.ucmd() .ucmd()
@ -158,7 +158,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -179,7 +179,7 @@ fn test_chown_only_colon() {
if skipping_test_is_okay(&result, "No such id") { if skipping_test_is_okay(&result, "No such id") {
return; return;
} }
result.stderr_contains(&"retained as"); // TODO: verbose is not printed to stderr in GNU chown result.stderr_contains("retained as"); // TODO: verbose is not printed to stderr in GNU chown
// test chown : file.txt // test chown : file.txt
// expected: // expected:
@ -192,7 +192,7 @@ fn test_chown_only_colon() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"invalid group: '::'"); .stderr_contains("invalid group: '::'");
scene scene
.ucmd() .ucmd()
@ -200,7 +200,7 @@ fn test_chown_only_colon() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"invalid group: '..'"); .stderr_contains("invalid group: '..'");
} }
#[test] #[test]
@ -251,7 +251,7 @@ fn test_chown_owner_group() {
if skipping_test_is_okay(&result, "chown: invalid group:") { if skipping_test_is_okay(&result, "chown: invalid group:") {
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
scene scene
.ucmd() .ucmd()
@ -259,7 +259,7 @@ fn test_chown_owner_group() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"invalid group"); .stderr_contains("invalid group");
scene scene
.ucmd() .ucmd()
@ -267,7 +267,7 @@ fn test_chown_owner_group() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"invalid group"); .stderr_contains("invalid group");
// TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root' // TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root'
#[cfg(any(windows, all(unix, not(target_os = "macos"))))] #[cfg(any(windows, all(unix, not(target_os = "macos"))))]
@ -277,7 +277,7 @@ fn test_chown_owner_group() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -316,7 +316,7 @@ fn test_chown_various_input() {
if skipping_test_is_okay(&result, "chown: invalid group:") { if skipping_test_is_okay(&result, "chown: invalid group:") {
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
// check that username.groupname is understood // check that username.groupname is understood
let result = scene let result = scene
@ -328,7 +328,7 @@ fn test_chown_various_input() {
if skipping_test_is_okay(&result, "chown: invalid group:") { if skipping_test_is_okay(&result, "chown: invalid group:") {
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
// Fails as user.name doesn't exist in the CI // Fails as user.name doesn't exist in the CI
// but it is valid // but it is valid
@ -338,7 +338,7 @@ fn test_chown_various_input() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"chown: invalid user: 'user.name:groupname'"); .stderr_contains("chown: invalid user: 'user.name:groupname'");
} }
#[test] #[test]
@ -377,7 +377,7 @@ fn test_chown_only_group() {
// With mac into the CI, we can get this answer // With mac into the CI, we can get this answer
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
result.success(); result.success();
scene scene
@ -386,7 +386,7 @@ fn test_chown_only_group() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -412,7 +412,7 @@ fn test_chown_only_user_id() {
// stderr: "chown: invalid user: '1001' // stderr: "chown: invalid user: '1001'
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
scene scene
.ucmd() .ucmd()
@ -420,7 +420,7 @@ fn test_chown_only_user_id() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
/// Test for setting the owner to a user ID for a user that does not exist. /// Test for setting the owner to a user ID for a user that does not exist.
@ -475,7 +475,7 @@ fn test_chown_only_group_id() {
// With mac into the CI, we can get this answer // With mac into the CI, we can get this answer
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
// Apparently on CI "macos-latest, x86_64-apple-darwin, feat_os_macos" // Apparently on CI "macos-latest, x86_64-apple-darwin, feat_os_macos"
// the process has the rights to change from runner:staff to runner:wheel // the process has the rights to change from runner:staff to runner:wheel
@ -486,7 +486,7 @@ fn test_chown_only_group_id() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
/// Test for setting the group to a group ID for a group that does not exist. /// Test for setting the group to a group ID for a group that does not exist.
@ -547,7 +547,7 @@ fn test_chown_owner_group_id() {
// stderr: "chown: invalid user: '1001:116' // stderr: "chown: invalid user: '1001:116'
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
let result = scene let result = scene
.ucmd() .ucmd()
@ -560,7 +560,7 @@ fn test_chown_owner_group_id() {
// stderr: "chown: invalid user: '1001.116' // stderr: "chown: invalid user: '1001.116'
return; return;
} }
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
scene scene
.ucmd() .ucmd()
@ -568,7 +568,7 @@ fn test_chown_owner_group_id() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -603,7 +603,7 @@ fn test_chown_owner_group_mix() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.run(); .run();
result.stderr_contains(&"retained as"); result.stderr_contains("retained as");
// TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root' // TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root'
#[cfg(any(windows, all(unix, not(target_os = "macos"))))] #[cfg(any(windows, all(unix, not(target_os = "macos"))))]
@ -613,7 +613,7 @@ fn test_chown_owner_group_mix() {
.arg("--verbose") .arg("--verbose")
.arg(file1) .arg(file1)
.fails() .fails()
.stderr_contains(&"failed to change"); .stderr_contains("failed to change");
} }
#[test] #[test]
@ -643,8 +643,8 @@ fn test_chown_recursive() {
.arg("a") .arg("a")
.arg("z") .arg("z")
.run(); .run();
result.stderr_contains(&"ownership of 'a/a' retained as"); result.stderr_contains("ownership of 'a/a' retained as");
result.stderr_contains(&"ownership of 'z/y' retained as"); result.stderr_contains("ownership of 'z/y' retained as");
} }
#[test] #[test]
@ -665,7 +665,7 @@ fn test_root_preserve() {
.arg(user_name) .arg(user_name)
.arg("/") .arg("/")
.fails(); .fails();
result.stderr_contains(&"chown: it is dangerous to operate recursively"); result.stderr_contains("chown: it is dangerous to operate recursively");
} }
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]

View file

@ -352,7 +352,7 @@ fn test_install_target_new_file_failing_nonexistent_parent() {
ucmd.arg(file1) ucmd.arg(file1)
.arg(format!("{}/{}", dir, file2)) .arg(format!("{}/{}", dir, file2))
.fails() .fails()
.stderr_contains(&"No such file or directory"); .stderr_contains("No such file or directory");
} }
#[test] #[test]

View file

@ -561,8 +561,8 @@ fn test_ls_a() {
.arg("-a") .arg("-a")
.arg("-1") .arg("-1")
.succeeds() .succeeds()
.stdout_contains(&".test-1") .stdout_contains(".test-1")
.stdout_contains(&"..") .stdout_contains("..")
.stdout_matches(&re_pwd); .stdout_matches(&re_pwd);
scene scene
@ -590,8 +590,8 @@ fn test_ls_a() {
.arg("-1") .arg("-1")
.arg("some-dir") .arg("some-dir")
.succeeds() .succeeds()
.stdout_contains(&".test-2") .stdout_contains(".test-2")
.stdout_contains(&"..") .stdout_contains("..")
.no_stderr() .no_stderr()
.stdout_matches(&re_pwd); .stdout_matches(&re_pwd);
@ -1821,7 +1821,7 @@ fn test_ls_files_dirs() {
.ucmd() .ucmd()
.arg("doesntexist") .arg("doesntexist")
.fails() .fails()
.stderr_contains(&"'doesntexist': No such file or directory"); .stderr_contains("'doesntexist': No such file or directory");
// One exists, the other doesn't // One exists, the other doesn't
scene scene
@ -1829,8 +1829,8 @@ fn test_ls_files_dirs() {
.arg("a") .arg("a")
.arg("doesntexist") .arg("doesntexist")
.fails() .fails()
.stderr_contains(&"'doesntexist': No such file or directory") .stderr_contains("'doesntexist': No such file or directory")
.stdout_contains(&"a:"); .stdout_contains("a:");
} }
#[test] #[test]
@ -1851,7 +1851,7 @@ fn test_ls_recursive() {
.arg("z") .arg("z")
.arg("-R") .arg("-R")
.succeeds() .succeeds()
.stdout_contains(&"z:"); .stdout_contains("z:");
let result = scene let result = scene
.ucmd() .ucmd()
.arg("--color=never") .arg("--color=never")
@ -1861,7 +1861,7 @@ fn test_ls_recursive() {
.succeeds(); .succeeds();
#[cfg(not(windows))] #[cfg(not(windows))]
result.stdout_contains(&"a/b:\nb"); result.stdout_contains("a/b:\nb");
#[cfg(windows)] #[cfg(windows)]
result.stdout_contains(&"a\\b:\nb"); result.stdout_contains(&"a\\b:\nb");
} }
@ -2014,7 +2014,7 @@ fn test_ls_indicator_style() {
"-p", "-p",
] { ] {
// Verify that classify and file-type both contain indicators for symlinks. // Verify that classify and file-type both contain indicators for symlinks.
scene.ucmd().arg(opt).succeeds().stdout_contains(&"/"); scene.ucmd().arg(opt).succeeds().stdout_contains("/");
} }
// Classify, Indicator options should not contain any indicators when value is none. // Classify, Indicator options should not contain any indicators when value is none.
@ -2030,9 +2030,9 @@ fn test_ls_indicator_style() {
.ucmd() .ucmd()
.arg(opt) .arg(opt)
.succeeds() .succeeds()
.stdout_does_not_contain(&"/") .stdout_does_not_contain("/")
.stdout_does_not_contain(&"@") .stdout_does_not_contain("@")
.stdout_does_not_contain(&"|"); .stdout_does_not_contain("|");
} }
// Classify and File-Type all contain indicators for pipes and links. // Classify and File-Type all contain indicators for pipes and links.
@ -2043,8 +2043,8 @@ fn test_ls_indicator_style() {
.ucmd() .ucmd()
.arg(format!("--indicator-style={}", opt)) .arg(format!("--indicator-style={}", opt))
.succeeds() .succeeds()
.stdout_contains(&"@") .stdout_contains("@")
.stdout_contains(&"|"); .stdout_contains("|");
} }
// Test sockets. Because the canonical way of making sockets to test is with // Test sockets. Because the canonical way of making sockets to test is with
@ -2631,7 +2631,7 @@ fn test_ls_ignore_hide() {
.arg("--ignore=READ[ME") .arg("--ignore=READ[ME")
.arg("-1") .arg("-1")
.succeeds() .succeeds()
.stderr_contains(&"Invalid pattern") .stderr_contains("Invalid pattern")
.stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n"); .stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n");
scene scene
@ -2639,7 +2639,7 @@ fn test_ls_ignore_hide() {
.arg("--hide=READ[ME") .arg("--hide=READ[ME")
.arg("-1") .arg("-1")
.succeeds() .succeeds()
.stderr_contains(&"Invalid pattern") .stderr_contains("Invalid pattern")
.stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n"); .stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n");
} }

View file

@ -67,7 +67,7 @@ fn test_mknod_fifo_invalid_extra_operand() {
.arg("1") .arg("1")
.arg("2") .arg("2")
.fails() .fails()
.stderr_contains(&"Fifos do not have major and minor device numbers"); .stderr_contains("Fifos do not have major and minor device numbers");
} }
#[test] #[test]
@ -78,28 +78,28 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("c") .arg("c")
.fails() .fails()
.status_code(1) .status_code(1)
.stderr_contains(&"Special files require major and minor device numbers."); .stderr_contains("Special files require major and minor device numbers.");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
.arg("c") .arg("c")
.arg("1") .arg("1")
.fails() .fails()
.status_code(1) .status_code(1)
.stderr_contains(&"Special files require major and minor device numbers."); .stderr_contains("Special files require major and minor device numbers.");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
.arg("c") .arg("c")
.arg("1") .arg("1")
.arg("c") .arg("c")
.fails() .fails()
.stderr_contains(&"Invalid value \"c\" for '<MINOR>'"); .stderr_contains("Invalid value \"c\" for '<MINOR>'");
new_ucmd!() new_ucmd!()
.arg("test_file") .arg("test_file")
.arg("c") .arg("c")
.arg("c") .arg("c")
.arg("1") .arg("1")
.fails() .fails()
.stderr_contains(&"Invalid value \"c\" for '<MAJOR>'"); .stderr_contains("Invalid value \"c\" for '<MAJOR>'");
} }
#[test] #[test]
@ -109,7 +109,7 @@ fn test_mknod_invalid_arg() {
.arg("--foo") .arg("--foo")
.fails() .fails()
.no_stdout() .no_stdout()
.stderr_contains(&"Found argument '--foo' which wasn't expected"); .stderr_contains("Found argument '--foo' which wasn't expected");
} }
#[test] #[test]
@ -123,5 +123,5 @@ fn test_mknod_invalid_mode() {
.fails() .fails()
.no_stdout() .no_stdout()
.status_code(1) .status_code(1)
.stderr_contains(&"invalid mode"); .stderr_contains("invalid mode");
} }

View file

@ -81,7 +81,7 @@ fn test_2files() {
// spell-checker:disable-next-line // spell-checker:disable-next-line
for (path, data) in [(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] { for (path, data) in [(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
let mut f = File::create(&path).unwrap(); let mut f = File::create(path).unwrap();
assert!( assert!(
f.write_all(data.as_bytes()).is_ok(), f.write_all(data.as_bytes()).is_ok(),
"Test setup failed - could not write file" "Test setup failed - could not write file"
@ -133,7 +133,7 @@ fn test_from_mixed() {
// spell-checker:disable-next-line // spell-checker:disable-next-line
let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n"); let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
for (path, data) in [(&file1, data1), (&file3, data3)] { for (path, data) in [(&file1, data1), (&file3, data3)] {
let mut f = File::create(&path).unwrap(); let mut f = File::create(path).unwrap();
assert!( assert!(
f.write_all(data.as_bytes()).is_ok(), f.write_all(data.as_bytes()).is_ok(),
"Test setup failed - could not write file" "Test setup failed - could not write file"

View file

@ -282,7 +282,7 @@ fn test_filter_with_env_var_set() {
RandomFile::new(&at, name).add_lines(n_lines); RandomFile::new(&at, name).add_lines(n_lines);
let env_var_value = "some-value"; let env_var_value = "some-value";
env::set_var("FILE", &env_var_value); env::set_var("FILE", env_var_value);
ucmd.args(&[format!("--filter={}", "cat > $FILE").as_str(), name]) ucmd.args(&[format!("--filter={}", "cat > $FILE").as_str(), name])
.succeeds(); .succeeds();

View file

@ -78,7 +78,7 @@ fn test_tee_no_more_writeable_1() {
.pipe_in(&content[..]) .pipe_in(&content[..])
.fails() .fails()
.stdout_contains(&content) .stdout_contains(&content)
.stderr_contains(&"No space left on device"); .stderr_contains("No space left on device");
assert_eq!(at.read(file_out), content); assert_eq!(at.read(file_out), content);
} }

View file

@ -31,7 +31,7 @@ fn test_count_bytes_large_stdin() {
.args(&["-c"]) .args(&["-c"])
.pipe_in(data) .pipe_in(data)
.succeeds() .succeeds()
.stdout_is_bytes(&expected.as_bytes()); .stdout_is_bytes(expected.as_bytes());
} }
} }

View file

@ -183,25 +183,25 @@ mod tests {
#[test] #[test]
fn test_random_string_generate() { fn test_random_string_generate() {
let random_string = RandomString::generate(&AlphanumericNewline, 0); let random_string = RandomString::generate(AlphanumericNewline, 0);
assert_eq!(0, random_string.len()); assert_eq!(0, random_string.len());
let random_string = RandomString::generate(&AlphanumericNewline, 1); let random_string = RandomString::generate(AlphanumericNewline, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
let random_string = RandomString::generate(&AlphanumericNewline, 100); let random_string = RandomString::generate(AlphanumericNewline, 100);
assert_eq!(100, random_string.len()); assert_eq!(100, random_string.len());
} }
#[test] #[test]
fn test_random_string_generate_with_delimiter_when_length_is_zero() { fn test_random_string_generate_with_delimiter_when_length_is_zero() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 0); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 0);
assert_eq!(0, random_string.len()); assert_eq!(0, random_string.len());
} }
#[test] #[test]
fn test_random_string_generate_with_delimiter_when_num_delimiter_is_greater_than_length() { fn test_random_string_generate_with_delimiter_when_num_delimiter_is_greater_than_length() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 1); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
assert!(random_string.as_bytes().contains(&0)); assert!(random_string.as_bytes().contains(&0));
assert!(random_string.as_bytes().ends_with(&[0])); assert!(random_string.as_bytes().ends_with(&[0]));
@ -209,7 +209,7 @@ mod tests {
#[test] #[test]
fn test_random_string_generate_with_delimiter_should_end_with_delimiter() { fn test_random_string_generate_with_delimiter_should_end_with_delimiter() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 1); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -217,7 +217,7 @@ mod tests {
); );
assert!(random_string.as_bytes().ends_with(&[0])); assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 1); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -225,7 +225,7 @@ mod tests {
); );
assert!(random_string.as_bytes().ends_with(&[0])); assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 2); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 2);
assert_eq!(2, random_string.len()); assert_eq!(2, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -233,7 +233,7 @@ mod tests {
); );
assert!(random_string.as_bytes().ends_with(&[0])); assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, true, 2); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, true, 2);
assert_eq!(2, random_string.len()); assert_eq!(2, random_string.len());
assert_eq!( assert_eq!(
2, 2,
@ -241,7 +241,7 @@ mod tests {
); );
assert!(random_string.as_bytes().ends_with(&[0])); assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 3); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 3);
assert_eq!(3, random_string.len()); assert_eq!(3, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -252,21 +252,21 @@ mod tests {
#[test] #[test]
fn test_random_string_generate_with_delimiter_should_not_end_with_delimiter() { fn test_random_string_generate_with_delimiter_should_not_end_with_delimiter() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 1); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
assert_eq!( assert_eq!(
0, 0,
random_string.as_bytes().iter().filter(|p| **p == 0).count() random_string.as_bytes().iter().filter(|p| **p == 0).count()
); );
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, true, 1); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, true, 1);
assert_eq!(1, random_string.len()); assert_eq!(1, random_string.len());
assert_eq!( assert_eq!(
0, 0,
random_string.as_bytes().iter().filter(|p| **p == 0).count() random_string.as_bytes().iter().filter(|p| **p == 0).count()
); );
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 2); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 2);
assert_eq!(2, random_string.len()); assert_eq!(2, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -274,7 +274,7 @@ mod tests {
); );
assert!(!random_string.as_bytes().ends_with(&[0])); assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 3); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 3);
assert_eq!(3, random_string.len()); assert_eq!(3, random_string.len());
assert_eq!( assert_eq!(
1, 1,
@ -282,7 +282,7 @@ mod tests {
); );
assert!(!random_string.as_bytes().ends_with(&[0])); assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 3); let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 3);
assert_eq!(3, random_string.len()); assert_eq!(3, random_string.len());
assert_eq!( assert_eq!(
2, 2,
@ -294,7 +294,7 @@ mod tests {
#[test] #[test]
fn test_generate_with_delimiter_with_greater_length() { fn test_generate_with_delimiter_with_greater_length() {
let random_string = let random_string =
RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, false, 1000); RandomString::generate_with_delimiter(Alphanumeric, 0, 100, false, 1000);
assert_eq!(1000, random_string.len()); assert_eq!(1000, random_string.len());
assert_eq!( assert_eq!(
100, 100,
@ -302,8 +302,7 @@ mod tests {
); );
assert!(!random_string.as_bytes().ends_with(&[0])); assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string = let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 100, true, 1000);
RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, true, 1000);
assert_eq!(1000, random_string.len()); assert_eq!(1000, random_string.len());
assert_eq!( assert_eq!(
100, 100,
@ -325,7 +324,7 @@ mod tests {
let length = 8192 * 3 + 1; let length = 8192 * 3 + 1;
let random_string = let random_string =
RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 100, true, length); RandomString::generate_with_delimiter(Alphanumeric, b'\n', 100, true, length);
assert_eq!(length, random_string.len()); assert_eq!(length, random_string.len());
assert_eq!( assert_eq!(
100, 100,

View file

@ -710,7 +710,7 @@ impl AtPath {
"symlink", "symlink",
&format!("{},{}", &original, &self.plus_as_string(link)), &format!("{},{}", &original, &self.plus_as_string(link)),
); );
symlink_file(&original, &self.plus(link)).unwrap(); symlink_file(original, &self.plus(link)).unwrap();
} }
pub fn symlink_dir(&self, original: &str, link: &str) { pub fn symlink_dir(&self, original: &str, link: &str) {
@ -732,7 +732,7 @@ impl AtPath {
"symlink", "symlink",
&format!("{},{}", &original, &self.plus_as_string(link)), &format!("{},{}", &original, &self.plus_as_string(link)),
); );
symlink_dir(&original, &self.plus(link)).unwrap(); symlink_dir(original, &self.plus(link)).unwrap();
} }
pub fn is_symlink(&self, path: &str) -> bool { pub fn is_symlink(&self, path: &str) -> bool {
@ -1445,7 +1445,7 @@ pub fn run_ucmd_as_root(
log_info("run", "sudo -E --non-interactive whoami"); log_info("run", "sudo -E --non-interactive whoami");
match Command::new("sudo") match Command::new("sudo")
.env("LC_ALL", "C") .env("LC_ALL", "C")
.args(&["-E", "--non-interactive", "whoami"]) .args(["-E", "--non-interactive", "whoami"])
.output() .output()
{ {
Ok(output) if String::from_utf8_lossy(&output.stdout).eq("root\n") => { Ok(output) if String::from_utf8_lossy(&output.stdout).eq("root\n") => {
@ -1833,7 +1833,7 @@ mod tests {
// Skip test if we can't guarantee non-interactive `sudo`, or if we're not "root" // Skip test if we can't guarantee non-interactive `sudo`, or if we're not "root"
if let Ok(output) = Command::new("sudo") if let Ok(output) = Command::new("sudo")
.env("LC_ALL", "C") .env("LC_ALL", "C")
.args(&["-E", "--non-interactive", "whoami"]) .args(["-E", "--non-interactive", "whoami"])
.output() .output()
{ {
if output.status.success() && String::from_utf8_lossy(&output.stdout).eq("root\n") { if output.status.success() && String::from_utf8_lossy(&output.stdout).eq("root\n") {