mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Merge pull request #6505 from Its-Just-Nans/fix-clippy-errors
Fix clippy errors
This commit is contained in:
commit
9c0f2f84ab
40 changed files with 1341 additions and 901 deletions
|
@ -1,2 +1,4 @@
|
||||||
msrv = "1.70.0"
|
msrv = "1.70.0"
|
||||||
cognitive-complexity-threshold = 24
|
cognitive-complexity-threshold = 24
|
||||||
|
missing-docs-in-crate-items = true
|
||||||
|
check-private-items = true
|
||||||
|
|
|
@ -155,3 +155,7 @@ retval
|
||||||
subdir
|
subdir
|
||||||
val
|
val
|
||||||
vals
|
vals
|
||||||
|
|
||||||
|
# * clippy
|
||||||
|
uninlined
|
||||||
|
nonminimal
|
||||||
|
|
|
@ -556,3 +556,12 @@ inherits = "release"
|
||||||
opt-level = "z"
|
opt-level = "z"
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
strip = true
|
strip = true
|
||||||
|
|
||||||
|
[lints.clippy]
|
||||||
|
multiple_crate_versions = { level = "allow", priority = 1 }
|
||||||
|
cargo_common_metadata = { level = "allow", priority = 1 }
|
||||||
|
uninlined_format_args = { level = "allow", priority = 1 }
|
||||||
|
missing_panics_doc = { level = "allow", priority = 1 }
|
||||||
|
all = "deny"
|
||||||
|
cargo = "warn"
|
||||||
|
pedantic = "deny"
|
||||||
|
|
9
build.rs
9
build.rs
|
@ -11,14 +11,14 @@ use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
if let Ok(profile) = env::var("PROFILE") {
|
|
||||||
println!("cargo:rustc-cfg=build={profile:?}");
|
|
||||||
}
|
|
||||||
|
|
||||||
const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_";
|
const ENV_FEATURE_PREFIX: &str = "CARGO_FEATURE_";
|
||||||
const FEATURE_PREFIX: &str = "feat_";
|
const FEATURE_PREFIX: &str = "feat_";
|
||||||
const OVERRIDE_PREFIX: &str = "uu_";
|
const OVERRIDE_PREFIX: &str = "uu_";
|
||||||
|
|
||||||
|
if let Ok(profile) = env::var("PROFILE") {
|
||||||
|
println!("cargo:rustc-cfg=build={profile:?}");
|
||||||
|
}
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
|
||||||
let mut crates = Vec::new();
|
let mut crates = Vec::new();
|
||||||
|
@ -46,6 +46,7 @@ pub fn main() {
|
||||||
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
|
"type UtilityMap<T> = phf::OrderedMap<&'static str, (fn(T) -> i32, fn() -> Command)>;\n\
|
||||||
\n\
|
\n\
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
|
#[allow(clippy::unreadable_literal)]
|
||||||
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
|
fn util_map<T: uucore::Args>() -> UtilityMap<T> {\n"
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,6 +34,8 @@ fn usage<T>(utils: &UtilityMap<T>, name: &str) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the binary path cannot be determined
|
||||||
fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
|
fn binary_path(args: &mut impl Iterator<Item = OsString>) -> PathBuf {
|
||||||
match args.next() {
|
match args.next() {
|
||||||
Some(ref s) if !s.is_empty() => PathBuf::from(s),
|
Some(ref s) if !s.is_empty() => PathBuf::from(s),
|
||||||
|
@ -85,9 +87,8 @@ fn main() {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let util = match util_os.to_str() {
|
let Some(util) = util_os.to_str() else {
|
||||||
Some(util) => util,
|
not_found(&util_os)
|
||||||
None => not_found(&util_os),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match util {
|
match util {
|
||||||
|
@ -113,9 +114,8 @@ fn main() {
|
||||||
if util == "--help" || util == "-h" {
|
if util == "--help" || util == "-h" {
|
||||||
// see if they want help on a specific util
|
// see if they want help on a specific util
|
||||||
if let Some(util_os) = args.next() {
|
if let Some(util_os) = args.next() {
|
||||||
let util = match util_os.to_str() {
|
let Some(util) = util_os.to_str() else {
|
||||||
Some(util) => util,
|
not_found(&util_os)
|
||||||
None => not_found(&util_os),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match utils.get(util) {
|
match utils.get(util) {
|
||||||
|
@ -145,6 +145,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prints completions for the utility in the first parameter for the shell in the second parameter to stdout
|
/// Prints completions for the utility in the first parameter for the shell in the second parameter to stdout
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_completions<T: uucore::Args>(
|
fn gen_completions<T: uucore::Args>(
|
||||||
args: impl Iterator<Item = OsString>,
|
args: impl Iterator<Item = OsString>,
|
||||||
util_map: &UtilityMap<T>,
|
util_map: &UtilityMap<T>,
|
||||||
|
@ -183,6 +185,8 @@ fn gen_completions<T: uucore::Args>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate the manpage for the utility in the first parameter
|
/// Generate the manpage for the utility in the first parameter
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_manpage<T: uucore::Args>(
|
fn gen_manpage<T: uucore::Args>(
|
||||||
args: impl Iterator<Item = OsString>,
|
args: impl Iterator<Item = OsString>,
|
||||||
util_map: &UtilityMap<T>,
|
util_map: &UtilityMap<T>,
|
||||||
|
@ -215,6 +219,8 @@ fn gen_manpage<T: uucore::Args>(
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the utility map is empty
|
||||||
fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> Command {
|
fn gen_coreutils_app<T: uucore::Args>(util_map: &UtilityMap<T>) -> Command {
|
||||||
let mut command = Command::new("coreutils");
|
let mut command = Command::new("coreutils");
|
||||||
for (name, (_, sub_app)) in util_map {
|
for (name, (_, sub_app)) in util_map {
|
||||||
|
|
|
@ -13,6 +13,9 @@ use zip::ZipArchive;
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
include!(concat!(env!("OUT_DIR"), "/uutils_map.rs"));
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let mut tldr_zip = File::open("docs/tldr.zip")
|
let mut tldr_zip = File::open("docs/tldr.zip")
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -170,6 +173,8 @@ struct MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> MDWriter<'a, 'b> {
|
impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn markdown(&mut self) -> io::Result<()> {
|
fn markdown(&mut self) -> io::Result<()> {
|
||||||
write!(self.w, "# {}\n\n", self.name)?;
|
write!(self.w, "# {}\n\n", self.name)?;
|
||||||
self.additional()?;
|
self.additional()?;
|
||||||
|
@ -180,6 +185,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
self.examples()
|
self.examples()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn additional(&mut self) -> io::Result<()> {
|
fn additional(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<div class=\"additional\">")?;
|
writeln!(self.w, "<div class=\"additional\">")?;
|
||||||
self.platforms()?;
|
self.platforms()?;
|
||||||
|
@ -187,6 +194,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
writeln!(self.w, "</div>")
|
writeln!(self.w, "</div>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn platforms(&mut self) -> io::Result<()> {
|
fn platforms(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<div class=\"platforms\">")?;
|
writeln!(self.w, "<div class=\"platforms\">")?;
|
||||||
for (feature, icon) in [
|
for (feature, icon) in [
|
||||||
|
@ -209,6 +218,10 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the version is not found.
|
||||||
fn version(&mut self) -> io::Result<()> {
|
fn version(&mut self) -> io::Result<()> {
|
||||||
writeln!(
|
writeln!(
|
||||||
self.w,
|
self.w,
|
||||||
|
@ -217,6 +230,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn usage(&mut self) -> io::Result<()> {
|
fn usage(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
let usage = uuhelp_parser::parse_usage(markdown);
|
let usage = uuhelp_parser::parse_usage(markdown);
|
||||||
|
@ -230,6 +245,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn about(&mut self) -> io::Result<()> {
|
fn about(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
writeln!(self.w, "{}", uuhelp_parser::parse_about(markdown))
|
writeln!(self.w, "{}", uuhelp_parser::parse_about(markdown))
|
||||||
|
@ -238,6 +255,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn after_help(&mut self) -> io::Result<()> {
|
fn after_help(&mut self) -> io::Result<()> {
|
||||||
if let Some(markdown) = &self.markdown {
|
if let Some(markdown) = &self.markdown {
|
||||||
if let Some(after_help) = uuhelp_parser::parse_section("after help", markdown) {
|
if let Some(after_help) = uuhelp_parser::parse_section("after help", markdown) {
|
||||||
|
@ -248,6 +267,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn examples(&mut self) -> io::Result<()> {
|
fn examples(&mut self) -> io::Result<()> {
|
||||||
if let Some(zip) = self.tldr_zip {
|
if let Some(zip) = self.tldr_zip {
|
||||||
let content = if let Some(f) =
|
let content = if let Some(f) =
|
||||||
|
@ -292,6 +313,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Errors
|
||||||
|
/// Returns an error if the writer fails.
|
||||||
fn options(&mut self) -> io::Result<()> {
|
fn options(&mut self) -> io::Result<()> {
|
||||||
writeln!(self.w, "<h2>Options</h2>")?;
|
writeln!(self.w, "<h2>Options</h2>")?;
|
||||||
write!(self.w, "<dl>")?;
|
write!(self.w, "<dl>")?;
|
||||||
|
@ -354,6 +377,8 @@ impl<'a, 'b> MDWriter<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Panics
|
||||||
|
/// Panics if the archive is not ok
|
||||||
fn get_zip_content(archive: &mut ZipArchive<impl Read + Seek>, name: &str) -> Option<String> {
|
fn get_zip_content(archive: &mut ZipArchive<impl Read + Seek>, name: &str) -> Option<String> {
|
||||||
let mut s = String::new();
|
let mut s = String::new();
|
||||||
archive.by_name(name).ok()?.read_to_string(&mut s).unwrap();
|
archive.by_name(name).ok()?.read_to_string(&mut s).unwrap();
|
||||||
|
|
|
@ -198,6 +198,8 @@ extern "C" {
|
||||||
target_os = "freebsd",
|
target_os = "freebsd",
|
||||||
target_os = "openbsd"
|
target_os = "openbsd"
|
||||||
))]
|
))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it dereferences a raw pointer.
|
||||||
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int {
|
unsafe fn _vprocmgr_detach_from_console(_: u32) -> *const libc::c_int {
|
||||||
std::ptr::null()
|
std::ptr::null()
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ mod platform {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::sync` or `libc::syscall` which are unsafe.
|
||||||
pub unsafe fn do_sync() -> isize {
|
pub unsafe fn do_sync() -> isize {
|
||||||
// see https://github.com/rust-lang/libc/pull/2161
|
// see https://github.com/rust-lang/libc/pull/2161
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
|
@ -46,6 +48,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::syscall` which is unsafe.
|
||||||
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
let f = File::open(path).unwrap();
|
let f = File::open(path).unwrap();
|
||||||
|
@ -56,6 +60,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `libc::syscall` which is unsafe.
|
||||||
pub unsafe fn do_fdatasync(files: Vec<String>) -> isize {
|
pub unsafe fn do_fdatasync(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
let f = File::open(path).unwrap();
|
let f = File::open(path).unwrap();
|
||||||
|
@ -81,6 +87,8 @@ mod platform {
|
||||||
};
|
};
|
||||||
use windows_sys::Win32::System::WindowsProgramming::DRIVE_FIXED;
|
use windows_sys::Win32::System::WindowsProgramming::DRIVE_FIXED;
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn flush_volume(name: &str) {
|
unsafe fn flush_volume(name: &str) {
|
||||||
let name_wide = name.to_wide_null();
|
let name_wide = name.to_wide_null();
|
||||||
if GetDriveTypeW(name_wide.as_ptr()) == DRIVE_FIXED {
|
if GetDriveTypeW(name_wide.as_ptr()) == DRIVE_FIXED {
|
||||||
|
@ -99,6 +107,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn find_first_volume() -> (String, HANDLE) {
|
unsafe fn find_first_volume() -> (String, HANDLE) {
|
||||||
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
||||||
let handle = FindFirstVolumeW(name.as_mut_ptr(), name.len() as u32);
|
let handle = FindFirstVolumeW(name.as_mut_ptr(), name.len() as u32);
|
||||||
|
@ -108,6 +118,8 @@ mod platform {
|
||||||
(String::from_wide_null(&name), handle)
|
(String::from_wide_null(&name), handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls an unsafe function.
|
||||||
unsafe fn find_all_volumes() -> Vec<String> {
|
unsafe fn find_all_volumes() -> Vec<String> {
|
||||||
let (first_volume, next_volume_handle) = find_first_volume();
|
let (first_volume, next_volume_handle) = find_first_volume();
|
||||||
let mut volumes = vec![first_volume];
|
let mut volumes = vec![first_volume];
|
||||||
|
@ -127,6 +139,8 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `find_all_volumes` which is unsafe.
|
||||||
pub unsafe fn do_sync() -> isize {
|
pub unsafe fn do_sync() -> isize {
|
||||||
let volumes = find_all_volumes();
|
let volumes = find_all_volumes();
|
||||||
for vol in &volumes {
|
for vol in &volumes {
|
||||||
|
@ -135,6 +149,8 @@ mod platform {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
|
/// This function is unsafe because it calls `find_all_volumes` which is unsafe.
|
||||||
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
pub unsafe fn do_syncfs(files: Vec<String>) -> isize {
|
||||||
for path in files {
|
for path in files {
|
||||||
flush_volume(
|
flush_volume(
|
||||||
|
|
|
@ -161,7 +161,9 @@ pub struct Passwd {
|
||||||
pub expiration: time_t,
|
pub expiration: time_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// SAFETY: ptr must point to a valid C string.
|
/// # Safety
|
||||||
|
/// ptr must point to a valid C string.
|
||||||
|
///
|
||||||
/// Returns None if ptr is null.
|
/// Returns None if ptr is null.
|
||||||
unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
|
@ -172,7 +174,8 @@ unsafe fn cstr2string(ptr: *const c_char) -> Option<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Passwd {
|
impl Passwd {
|
||||||
/// SAFETY: All the pointed-to strings must be valid and not change while
|
/// # Safety
|
||||||
|
/// All the pointed-to strings must be valid and not change while
|
||||||
/// the function runs. That means PW_LOCK must be held.
|
/// the function runs. That means PW_LOCK must be held.
|
||||||
unsafe fn from_raw(raw: passwd) -> Self {
|
unsafe fn from_raw(raw: passwd) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -246,7 +249,8 @@ pub struct Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Group {
|
impl Group {
|
||||||
/// SAFETY: gr_name must be valid and not change while
|
/// # Safety
|
||||||
|
/// gr_name must be valid and not change while
|
||||||
/// the function runs. That means PW_LOCK must be held.
|
/// the function runs. That means PW_LOCK must be held.
|
||||||
unsafe fn from_raw(raw: group) -> Self {
|
unsafe fn from_raw(raw: group) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -485,7 +485,7 @@ fn test_dev_random() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reading from /dev/full should return an infinite amount of zero bytes.
|
/// Reading from /dev/full should return an infinite amount of zero bytes.
|
||||||
/// Wikipedia says there is support on Linux, FreeBSD, and NetBSD.
|
/// Wikipedia says there is support on Linux, FreeBSD, and `NetBSD`.
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||||
fn test_dev_full() {
|
fn test_dev_full() {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore (jargon) xattributes
|
// spell-checker:ignore (jargon) xattributes
|
||||||
|
#![allow(clippy::missing_errors_doc, clippy::similar_names)]
|
||||||
#![cfg(feature = "feat_selinux")]
|
#![cfg(feature = "feat_selinux")]
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
use crate::common::util::{AtPath, TestScenario, UCommand};
|
use crate::common::util::{AtPath, TestScenario, UCommand};
|
||||||
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
|
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
|
||||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||||
|
@ -32,12 +33,14 @@ fn make_file(file: &str, mode: u32) {
|
||||||
fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
|
fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
|
||||||
make_file(&at.plus_as_string(TEST_FILE), test.before);
|
make_file(&at.plus_as_string(TEST_FILE), test.before);
|
||||||
let perms = at.metadata(TEST_FILE).permissions().mode();
|
let perms = at.metadata(TEST_FILE).permissions().mode();
|
||||||
if perms != test.before {
|
|
||||||
panic!(
|
assert!(
|
||||||
"{}: expected: {:o} got: {:o}",
|
perms == test.before,
|
||||||
"setting permissions on test files before actual test run failed", test.after, perms
|
"{}: expected: {:o} got: {:o}",
|
||||||
);
|
"setting permissions on test files before actual test run failed",
|
||||||
}
|
test.after,
|
||||||
|
perms
|
||||||
|
);
|
||||||
|
|
||||||
for arg in &test.args {
|
for arg in &test.args {
|
||||||
ucmd.arg(arg);
|
ucmd.arg(arg);
|
||||||
|
@ -52,9 +55,13 @@ fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let perms = at.metadata(TEST_FILE).permissions().mode();
|
let perms = at.metadata(TEST_FILE).permissions().mode();
|
||||||
if perms != test.after {
|
assert!(
|
||||||
panic!("{}: expected: {:o} got: {:o}", ucmd, test.after, perms);
|
perms == test.after,
|
||||||
}
|
"{}: expected: {:o} got: {:o}",
|
||||||
|
ucmd,
|
||||||
|
test.after,
|
||||||
|
perms
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_tests(tests: Vec<TestCase>) {
|
fn run_tests(tests: Vec<TestCase>) {
|
||||||
|
@ -128,6 +135,7 @@ fn test_chmod_octal() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::unreadable_literal)]
|
#[allow(clippy::unreadable_literal)]
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
// spell-checker:disable-next-line
|
// spell-checker:disable-next-line
|
||||||
fn test_chmod_ugoa() {
|
fn test_chmod_ugoa() {
|
||||||
let tests = vec![
|
let tests = vec![
|
||||||
|
|
|
@ -29,9 +29,8 @@ fn skipping_test_is_okay(result: &CmdResult, needle: &str) -> bool {
|
||||||
if is_ci() && result.stderr_str().contains(needle) {
|
if is_ci() && result.stderr_str().contains(needle) {
|
||||||
println!("test skipped:");
|
println!("test skipped:");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
result.success();
|
|
||||||
}
|
}
|
||||||
|
result.success();
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -2328,9 +2328,9 @@ fn test_closes_file_descriptors() {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_sparse_never_empty() {
|
fn test_cp_sparse_never_empty() {
|
||||||
|
const BUFFER_SIZE: usize = 4096 * 4;
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 4096 * 4;
|
|
||||||
let buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
let buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
||||||
|
|
||||||
at.make_file("src_file1");
|
at.make_file("src_file1");
|
||||||
|
@ -2348,10 +2348,10 @@ fn test_cp_sparse_never_empty() {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_sparse_always_empty() {
|
fn test_cp_sparse_always_empty() {
|
||||||
|
const BUFFER_SIZE: usize = 4096 * 4;
|
||||||
for argument in ["--sparse=always", "--sparse=alway", "--sparse=al"] {
|
for argument in ["--sparse=always", "--sparse=alway", "--sparse=al"] {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 4096 * 4;
|
|
||||||
let buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
let buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
||||||
|
|
||||||
at.make_file("src_file1");
|
at.make_file("src_file1");
|
||||||
|
@ -2368,9 +2368,9 @@ fn test_cp_sparse_always_empty() {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_sparse_always_non_empty() {
|
fn test_cp_sparse_always_non_empty() {
|
||||||
|
const BUFFER_SIZE: usize = 4096 * 16 + 3;
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
const BUFFER_SIZE: usize = 4096 * 16 + 3;
|
|
||||||
let mut buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
let mut buf: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
||||||
let blocks_to_touch = [buf.len() / 3, 2 * (buf.len() / 3)];
|
let blocks_to_touch = [buf.len() / 3, 2 * (buf.len() / 3)];
|
||||||
|
|
||||||
|
@ -2438,12 +2438,11 @@ fn test_cp_sparse_never_reflink_always() {
|
||||||
#[cfg(feature = "truncate")]
|
#[cfg(feature = "truncate")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_reflink_always_override() {
|
fn test_cp_reflink_always_override() {
|
||||||
let scene = TestScenario::new(util_name!());
|
|
||||||
|
|
||||||
const DISK: &str = "disk.img";
|
const DISK: &str = "disk.img";
|
||||||
const ROOTDIR: &str = "disk_root/";
|
const ROOTDIR: &str = "disk_root/";
|
||||||
const USERDIR: &str = "dir/";
|
const USERDIR: &str = "dir/";
|
||||||
const MOUNTPOINT: &str = "mountpoint/";
|
const MOUNTPOINT: &str = "mountpoint/";
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
||||||
let src1_path: &str = &[MOUNTPOINT, USERDIR, "src1"].concat();
|
let src1_path: &str = &[MOUNTPOINT, USERDIR, "src1"].concat();
|
||||||
let src2_path: &str = &[MOUNTPOINT, USERDIR, "src2"].concat();
|
let src2_path: &str = &[MOUNTPOINT, USERDIR, "src2"].concat();
|
||||||
|
@ -2575,12 +2574,12 @@ fn test_no_preserve_mode() {
|
||||||
let umask: u16 = 0o022;
|
let umask: u16 = 0o022;
|
||||||
ucmd.arg("file")
|
ucmd.arg("file")
|
||||||
.arg("dest")
|
.arg("dest")
|
||||||
.umask(umask as libc::mode_t)
|
.umask(libc::mode_t::from(umask))
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.no_stderr()
|
.no_stderr()
|
||||||
.no_stdout();
|
.no_stdout();
|
||||||
// remove sticky bit, setuid and setgid bit; apply umask
|
// remove sticky bit, setuid and setgid bit; apply umask
|
||||||
let expected_perms = PERMS_ALL & !0o7000 & !umask as u32;
|
let expected_perms = PERMS_ALL & !0o7000 & u32::from(!umask);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.plus("dest").metadata().unwrap().mode() & 0o7777,
|
at.plus("dest").metadata().unwrap().mode() & 0o7777,
|
||||||
expected_perms
|
expected_perms
|
||||||
|
@ -5507,16 +5506,17 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
|
||||||
let start_time = std::time::Instant::now();
|
let start_time = std::time::Instant::now();
|
||||||
// wait for cp to create dirs
|
// wait for cp to create dirs
|
||||||
loop {
|
loop {
|
||||||
if start_time.elapsed() >= timeout {
|
assert!(
|
||||||
panic!("timed out: cp took too long to create destination directory")
|
start_time.elapsed() < timeout,
|
||||||
}
|
"timed out: cp took too long to create destination directory"
|
||||||
|
);
|
||||||
if at.dir_exists(&format!("{}/{}", DEST_DIR, SRC_DIR)) {
|
if at.dir_exists(&format!("{}/{}", DEST_DIR, SRC_DIR)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::thread::sleep(Duration::from_millis(100));
|
std::thread::sleep(Duration::from_millis(100));
|
||||||
}
|
}
|
||||||
let mode = at.metadata(&format!("{}/{}", DEST_DIR, SRC_DIR)).mode();
|
let mode = at.metadata(&format!("{}/{}", DEST_DIR, SRC_DIR)).mode();
|
||||||
#[allow(clippy::unnecessary_cast)]
|
#[allow(clippy::unnecessary_cast, clippy::cast_lossless)]
|
||||||
let mask = if attr == "mode" {
|
let mask = if attr == "mode" {
|
||||||
libc::S_IWGRP | libc::S_IWOTH
|
libc::S_IWGRP | libc::S_IWOTH
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -273,7 +273,7 @@ fn test_date_set_mac_unavailable() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
/// TODO: expected to fail currently; change to succeeds() when required.
|
/// TODO: expected to fail currently; change to `succeeds()` when required.
|
||||||
fn test_date_set_valid_2() {
|
fn test_date_set_valid_2() {
|
||||||
if geteuid() == 0 {
|
if geteuid() == 0 {
|
||||||
let result = new_ucmd!()
|
let result = new_ucmd!()
|
||||||
|
@ -298,10 +298,11 @@ fn test_date_for_invalid_file() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_date_for_no_permission_file() {
|
fn test_date_for_no_permission_file() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
use std::os::unix::fs::PermissionsExt;
|
||||||
const FILE: &str = "file-no-perm-1";
|
const FILE: &str = "file-no-perm-1";
|
||||||
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
let file = std::fs::OpenOptions::new()
|
let file = std::fs::OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
.truncate(true)
|
.truncate(true)
|
||||||
|
@ -338,7 +339,7 @@ fn test_date_for_file() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
/// TODO: expected to fail currently; change to succeeds() when required.
|
/// TODO: expected to fail currently; change to `succeeds()` when required.
|
||||||
fn test_date_set_valid_3() {
|
fn test_date_set_valid_3() {
|
||||||
if geteuid() == 0 {
|
if geteuid() == 0 {
|
||||||
let result = new_ucmd!()
|
let result = new_ucmd!()
|
||||||
|
@ -352,7 +353,7 @@ fn test_date_set_valid_3() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
/// TODO: expected to fail currently; change to succeeds() when required.
|
/// TODO: expected to fail currently; change to `succeeds()` when required.
|
||||||
fn test_date_set_valid_4() {
|
fn test_date_set_valid_4() {
|
||||||
if geteuid() == 0 {
|
if geteuid() == 0 {
|
||||||
let result = new_ucmd!()
|
let result = new_ucmd!()
|
||||||
|
@ -422,8 +423,8 @@ fn test_date_overflow() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_date_parse_from_format() {
|
fn test_date_parse_from_format() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
|
||||||
const FILE: &str = "file-with-dates";
|
const FILE: &str = "file-with-dates";
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
|
||||||
at.write(
|
at.write(
|
||||||
FILE,
|
FILE,
|
||||||
|
|
|
@ -3,6 +3,13 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore udev pcent iuse itotal iused ipcent
|
// spell-checker:ignore udev pcent iuse itotal iused ipcent
|
||||||
|
#![allow(
|
||||||
|
clippy::similar_names,
|
||||||
|
clippy::cast_possible_truncation,
|
||||||
|
clippy::cast_sign_loss,
|
||||||
|
clippy::float_cmp
|
||||||
|
)]
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
|
|
|
@ -200,15 +200,15 @@ TERM {term_pattern}
|
||||||
.no_stderr();
|
.no_stderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
let expectation_if_match = r#"
|
let expectation_if_match = r"
|
||||||
LS_COLORS='*.term_matching=00;38;5;61:';
|
LS_COLORS='*.term_matching=00;38;5;61:';
|
||||||
export LS_COLORS
|
export LS_COLORS
|
||||||
"#
|
"
|
||||||
.trim_start();
|
.trim_start();
|
||||||
let expectation_if_no_match = r#"
|
let expectation_if_no_match = r"
|
||||||
LS_COLORS='';
|
LS_COLORS='';
|
||||||
export LS_COLORS
|
export LS_COLORS
|
||||||
"#
|
"
|
||||||
.trim_start();
|
.trim_start();
|
||||||
|
|
||||||
// sanity checks
|
// sanity checks
|
||||||
|
|
|
@ -545,7 +545,7 @@ fn test_du_h_flag_empty_file() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_du_h_precision() {
|
fn test_du_h_precision() {
|
||||||
let test_cases = [
|
let test_cases = [
|
||||||
(133456345, "128M"),
|
(133_456_345, "128M"),
|
||||||
(12 * 1024 * 1024, "12M"),
|
(12 * 1024 * 1024, "12M"),
|
||||||
(8500, "8.4K"),
|
(8500, "8.4K"),
|
||||||
];
|
];
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD
|
// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD
|
||||||
|
#![allow(clippy::missing_errors_doc)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -555,28 +556,28 @@ fn test_env_parsing_errors() {
|
||||||
.stderr_is("env: invalid sequence '\\a' in -S\n");
|
.stderr_is("env: invalid sequence '\\a' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S\|\&\;"#) // no quotes, invalid escape sequence |
|
.arg(r"-S\|\&\;") // no quotes, invalid escape sequence |
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\|' in -S\n");
|
.stderr_is("env: invalid sequence '\\|' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S\<\&\;"#) // no quotes, invalid escape sequence <
|
.arg(r"-S\<\&\;") // no quotes, invalid escape sequence <
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\<' in -S\n");
|
.stderr_is("env: invalid sequence '\\<' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S\>\&\;"#) // no quotes, invalid escape sequence >
|
.arg(r"-S\>\&\;") // no quotes, invalid escape sequence >
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\>' in -S\n");
|
.stderr_is("env: invalid sequence '\\>' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S\`\&\;"#) // no quotes, invalid escape sequence `
|
.arg(r"-S\`\&\;") // no quotes, invalid escape sequence `
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
|
@ -590,14 +591,14 @@ fn test_env_parsing_errors() {
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S'\`\&\;'"#) // single quotes, invalid escape sequence `
|
.arg(r"-S'\`\&\;'") // single quotes, invalid escape sequence `
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S\`"#) // ` escaped without quotes
|
.arg(r"-S\`") // ` escaped without quotes
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
|
@ -611,14 +612,14 @@ fn test_env_parsing_errors() {
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.arg(r#"-S'\`'"#) // ` escaped in single quotes
|
.arg(r"-S'\`'") // ` escaped in single quotes
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
.stderr_is("env: invalid sequence '\\`' in -S\n");
|
||||||
|
|
||||||
ts.ucmd()
|
ts.ucmd()
|
||||||
.args(&[r#"-S\🦉"#]) // ` escaped in single quotes
|
.args(&[r"-S\🦉"]) // ` escaped in single quotes
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(125)
|
.code_is(125)
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
|
@ -1068,11 +1069,11 @@ mod tests_split_iterator {
|
||||||
#[test]
|
#[test]
|
||||||
fn split_single_quotes() {
|
fn split_single_quotes() {
|
||||||
split_ok(&[
|
split_ok(&[
|
||||||
(r#"''"#, &[r#""#]),
|
(r"''", &[r""]),
|
||||||
(r#"'a'"#, &[r#"a"#]),
|
(r"'a'", &[r"a"]),
|
||||||
(r#"'\\'"#, &[r#"\"#]),
|
(r"'\\'", &[r"\"]),
|
||||||
(r#"' \\ '"#, &[r#" \ "#]),
|
(r"' \\ '", &[r" \ "]),
|
||||||
(r#"'#'"#, &[r#"#"#]),
|
(r"'#'", &[r"#"]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1094,12 +1095,12 @@ mod tests_split_iterator {
|
||||||
#[test]
|
#[test]
|
||||||
fn split_unquoted() {
|
fn split_unquoted() {
|
||||||
split_ok(&[
|
split_ok(&[
|
||||||
(r#"\\|\\&\\;"#, &[r#"\|\&\;"#]),
|
(r"\\|\\&\\;", &[r"\|\&\;"]),
|
||||||
(r#"\\<\\>"#, &[r#"\<\>"#]),
|
(r"\\<\\>", &[r"\<\>"]),
|
||||||
(r#"\\(\\)"#, &[r#"\(\)"#]),
|
(r"\\(\\)", &[r"\(\)"]),
|
||||||
(r#"\$"#, &[r#"$"#]),
|
(r"\$", &[r"$"]),
|
||||||
(r#"\""#, &[r#"""#]),
|
(r#"\""#, &[r#"""#]),
|
||||||
(r#"\'"#, &[r#"'"#]),
|
(r"\'", &[r"'"]),
|
||||||
("\\\n", &[]),
|
("\\\n", &[]),
|
||||||
(" \\\n \n", &[]),
|
(" \\\n \n", &[]),
|
||||||
("a\nb\nc", &["a", "b", "c"]),
|
("a\nb\nc", &["a", "b", "c"]),
|
||||||
|
@ -1179,7 +1180,7 @@ mod tests_split_iterator {
|
||||||
Err(ParseError::InvalidSequenceBackslashXInMinusS { pos: 2, c: 'a' })
|
Err(ParseError::InvalidSequenceBackslashXInMinusS { pos: 2, c: 'a' })
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
split(r#"\🦉"#),
|
split(r"\🦉"),
|
||||||
Err(ParseError::InvalidSequenceBackslashXInMinusS {
|
Err(ParseError::InvalidSequenceBackslashXInMinusS {
|
||||||
pos: 1,
|
pos: 1,
|
||||||
c: '\u{FFFD}'
|
c: '\u{FFFD}'
|
||||||
|
@ -1190,9 +1191,9 @@ mod tests_split_iterator {
|
||||||
#[test]
|
#[test]
|
||||||
fn split_comments() {
|
fn split_comments() {
|
||||||
split_ok(&[
|
split_ok(&[
|
||||||
(r#" x # comment "#, &["x"]),
|
(r" x # comment ", &["x"]),
|
||||||
(r#" w1#w2 "#, &["w1#w2"]),
|
(r" w1#w2 ", &["w1#w2"]),
|
||||||
(r#"'not really a # comment'"#, &["not really a # comment"]),
|
(r"'not really a # comment'", &["not really a # comment"]),
|
||||||
(" a # very long comment \n b # another comment", &["a", "b"]),
|
(" a # very long comment \n b # another comment", &["a", "b"]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -16,11 +16,12 @@ fn test_invalid_arg() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
#[allow(unused_mut)]
|
||||||
fn test_id_no_specified_user() {
|
fn test_id_no_specified_user() {
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let result = ts.ucmd().run();
|
let result = ts.ucmd().run();
|
||||||
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
let exp_result = unwrap_or_return!(expected_result(&ts, &[]));
|
||||||
let mut _exp_stdout = exp_result.stdout_str().to_string();
|
let mut exp_stdout = exp_result.stdout_str().to_string();
|
||||||
|
|
||||||
#[cfg(not(feature = "feat_selinux"))]
|
#[cfg(not(feature = "feat_selinux"))]
|
||||||
{
|
{
|
||||||
|
@ -29,12 +30,12 @@ fn test_id_no_specified_user() {
|
||||||
// uid=1001(runner) gid=121(docker) groups=121(docker),4(adm),101(systemd-journal) \
|
// uid=1001(runner) gid=121(docker) groups=121(docker),4(adm),101(systemd-journal) \
|
||||||
// context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
|
// context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
|
||||||
if let Some(context_offset) = exp_result.stdout_str().find(" context=") {
|
if let Some(context_offset) = exp_result.stdout_str().find(" context=") {
|
||||||
_exp_stdout.replace_range(context_offset.._exp_stdout.len() - 1, "");
|
exp_stdout.replace_range(context_offset..exp_stdout.len() - 1, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result
|
result
|
||||||
.stdout_is(_exp_stdout)
|
.stdout_is(exp_stdout)
|
||||||
.stderr_is(exp_result.stderr_str())
|
.stderr_is(exp_result.stderr_str())
|
||||||
.code_is(exp_result.code());
|
.code_is(exp_result.code());
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ fn test_kill_table_lists_all_vertically() {
|
||||||
let signals = command
|
let signals = command
|
||||||
.stdout_str()
|
.stdout_str()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.flat_map(|line| line.trim().split(' ').nth(1))
|
.filter_map(|line| line.trim().split(' ').nth(1))
|
||||||
.collect::<Vec<&str>>();
|
.collect::<Vec<&str>>();
|
||||||
|
|
||||||
assert!(signals.contains(&"KILL"));
|
assert!(signals.contains(&"KILL"));
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::similar_names)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff dired subdired tmpfs mdir COLORTERM mexe bcdef mfoo
|
// spell-checker:ignore (words) READMECAREFULLY birthtime doesntexist oneline somebackup lrwx somefile somegroup somehiddenbackup somehiddenfile tabsize aaaaaaaa bbbb cccc dddddddd ncccc neee naaaaa nbcdef nfffff dired subdired tmpfs mdir COLORTERM mexe bcdef mfoo
|
||||||
|
#![allow(
|
||||||
|
clippy::similar_names,
|
||||||
|
clippy::too_many_lines,
|
||||||
|
clippy::cast_possible_truncation
|
||||||
|
)]
|
||||||
|
|
||||||
#[cfg(any(unix, feature = "feat_selinux"))]
|
#[cfg(any(unix, feature = "feat_selinux"))]
|
||||||
use crate::common::util::expected_result;
|
use crate::common::util::expected_result;
|
||||||
|
@ -160,7 +165,7 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String {
|
||||||
let output = cmd.succeeds();
|
let output = cmd.succeeds();
|
||||||
let stdout_str = String::from_utf8_lossy(output.stdout());
|
let stdout_str = String::from_utf8_lossy(output.stdout());
|
||||||
println!("output of stat call ({cmd:?}):\n{stdout_str}");
|
println!("output of stat call ({cmd:?}):\n{stdout_str}");
|
||||||
let regex_str = r#"Filesystem\s+Type\s+.+[\r\n]+([^\s]+)\s+(?<fstype>[^\s]+)\s+"#;
|
let regex_str = r"Filesystem\s+Type\s+.+[\r\n]+([^\s]+)\s+(?<fstype>[^\s]+)\s+";
|
||||||
let regex = Regex::new(regex_str).unwrap();
|
let regex = Regex::new(regex_str).unwrap();
|
||||||
let m = regex.captures(&stdout_str).unwrap();
|
let m = regex.captures(&stdout_str).unwrap();
|
||||||
let fstype = m["fstype"].to_owned();
|
let fstype = m["fstype"].to_owned();
|
||||||
|
@ -1150,6 +1155,7 @@ fn test_ls_long_padding_of_size_column_with_multiple_files() {
|
||||||
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
|
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
|
#[cfg(all(feature = "ln", feature = "mkdir", feature = "touch"))]
|
||||||
|
#[allow(clippy::items_after_statements)]
|
||||||
fn test_ls_long_symlink_color() {
|
fn test_ls_long_symlink_color() {
|
||||||
// If you break this test after breaking mkdir, touch, or ln, do not be alarmed!
|
// If you break this test after breaking mkdir, touch, or ln, do not be alarmed!
|
||||||
// This test is made for ls, but it attempts to run those utils in the process.
|
// This test is made for ls, but it attempts to run those utils in the process.
|
||||||
|
@ -1378,7 +1384,7 @@ fn test_ls_long_symlink_color() {
|
||||||
|
|
||||||
/// This test is for "ls -l --color=auto|--color=always"
|
/// This test is for "ls -l --color=auto|--color=always"
|
||||||
/// We use "--color=always" as the colors are the same regardless of the color option being "auto" or "always"
|
/// We use "--color=always" as the colors are the same regardless of the color option being "auto" or "always"
|
||||||
/// tests whether the specific color of the target and the dangling_symlink are equal and checks
|
/// tests whether the specific color of the target and the `dangling_symlink` are equal and checks
|
||||||
/// whether checks whether ls outputs the correct path for the symlink and the file it points to and applies the color code to it.
|
/// whether checks whether ls outputs the correct path for the symlink and the file it points to and applies the color code to it.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ls_long_dangling_symlink_color() {
|
fn test_ls_long_dangling_symlink_color() {
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use libc::mode_t;
|
use libc::mode_t;
|
||||||
|
|
|
@ -560,8 +560,8 @@ fn test_dec_offset() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_offset() {
|
fn test_no_offset() {
|
||||||
let input = [0u8; 31];
|
|
||||||
const LINE: &str = " 00000000 00000000 00000000 00000000\n";
|
const LINE: &str = " 00000000 00000000 00000000 00000000\n";
|
||||||
|
let input = [0u8; 31];
|
||||||
let expected_output = [LINE, LINE, LINE, LINE].join("");
|
let expected_output = [LINE, LINE, LINE, LINE].join("");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
|
@ -167,9 +167,9 @@ fn test_delimiter_list_ending_with_escaped_backslash() {
|
||||||
for d in ["-d", "--delimiters"] {
|
for d in ["-d", "--delimiters"] {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let mut ins = vec![];
|
let mut ins = vec![];
|
||||||
for (i, _in) in ["a\n", "b\n"].iter().enumerate() {
|
for (i, one_in) in ["a\n", "b\n"].iter().enumerate() {
|
||||||
let file = format!("in{}", i);
|
let file = format!("in{}", i);
|
||||||
at.write(&file, _in);
|
at.write(&file, one_in);
|
||||||
ins.push(file);
|
ins.push(file);
|
||||||
}
|
}
|
||||||
ucmd.args(&[d, "\\\\"])
|
ucmd.args(&[d, "\\\\"])
|
||||||
|
@ -198,9 +198,9 @@ fn test_data() {
|
||||||
for example in EXAMPLE_DATA {
|
for example in EXAMPLE_DATA {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let mut ins = vec![];
|
let mut ins = vec![];
|
||||||
for (i, _in) in example.ins.iter().enumerate() {
|
for (i, one_in) in example.ins.iter().enumerate() {
|
||||||
let file = format!("in{i}");
|
let file = format!("in{i}");
|
||||||
at.write(&file, _in);
|
at.write(&file, one_in);
|
||||||
ins.push(file);
|
ins.push(file);
|
||||||
}
|
}
|
||||||
println!("{}", example.name);
|
println!("{}", example.name);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::stable_sort_primitive)]
|
||||||
|
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
|
|
|
@ -106,7 +106,7 @@ fn test_very_large_range() {
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(result_seq.len(), num_samples, "Miscounted output length!");
|
assert_eq!(result_seq.len(), num_samples, "Miscounted output length!");
|
||||||
assert!(
|
assert!(
|
||||||
result_seq.iter().all(|x| (0..=1234567890).contains(x)),
|
result_seq.iter().all(|x| (0..=1_234_567_890).contains(x)),
|
||||||
"Output includes element not from range: {}",
|
"Output includes element not from range: {}",
|
||||||
result.stdout_str()
|
result.stdout_str()
|
||||||
);
|
);
|
||||||
|
@ -132,7 +132,7 @@ fn test_very_large_range_offset() {
|
||||||
assert!(
|
assert!(
|
||||||
result_seq
|
result_seq
|
||||||
.iter()
|
.iter()
|
||||||
.all(|x| (1234567890..=2147483647).contains(x)),
|
.all(|x| (1_234_567_890..=2_147_483_647).contains(x)),
|
||||||
"Output includes element not from range: {}",
|
"Output includes element not from range: {}",
|
||||||
result.stdout_str()
|
result.stdout_str()
|
||||||
);
|
);
|
||||||
|
@ -234,7 +234,13 @@ fn test_range_permute_no_overflow_0_max() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_very_high_range_full() {
|
fn test_very_high_range_full() {
|
||||||
let input_seq = vec![
|
let input_seq = vec![
|
||||||
2147483641, 2147483642, 2147483643, 2147483644, 2147483645, 2147483646, 2147483647,
|
2_147_483_641,
|
||||||
|
2_147_483_642,
|
||||||
|
2_147_483_643,
|
||||||
|
2_147_483_644,
|
||||||
|
2_147_483_645,
|
||||||
|
2_147_483_646,
|
||||||
|
2_147_483_647,
|
||||||
];
|
];
|
||||||
let result = new_ucmd!().arg("-i2147483641-2147483647").succeeds();
|
let result = new_ucmd!().arg("-i2147483641-2147483647").succeeds();
|
||||||
result.no_stderr();
|
result.no_stderr();
|
||||||
|
@ -320,7 +326,7 @@ fn test_echo_multi() {
|
||||||
.stdout_str()
|
.stdout_str()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(|x| !x.is_empty())
|
.filter(|x| !x.is_empty())
|
||||||
.map(|x| x.into())
|
.map(std::convert::Into::into)
|
||||||
.collect();
|
.collect();
|
||||||
result_seq.sort_unstable();
|
result_seq.sort_unstable();
|
||||||
assert_eq!(result_seq, ["a", "b", "c"], "Output is not a permutation");
|
assert_eq!(result_seq, ["a", "b", "c"], "Output is not a permutation");
|
||||||
|
@ -335,7 +341,7 @@ fn test_echo_postfix() {
|
||||||
.stdout_str()
|
.stdout_str()
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(|x| !x.is_empty())
|
.filter(|x| !x.is_empty())
|
||||||
.map(|x| x.into())
|
.map(std::convert::Into::into)
|
||||||
.collect();
|
.collect();
|
||||||
result_seq.sort_unstable();
|
result_seq.sort_unstable();
|
||||||
assert_eq!(result_seq, ["a", "b", "c"], "Output is not a permutation");
|
assert_eq!(result_seq, ["a", "b", "c"], "Output is not a permutation");
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
// spell-checker:ignore (words) ints
|
// spell-checker:ignore (words) ints
|
||||||
|
#![allow(clippy::cast_possible_wrap)]
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
|
@ -160,9 +160,7 @@ fn test_symlinks() {
|
||||||
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !tested {
|
assert!(tested, "No symlink found to test in this environment");
|
||||||
panic!("No symlink found to test in this environment");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||||
|
|
|
@ -6,8 +6,13 @@
|
||||||
// spell-checker:ignore (ToDO) abcdefghijklmnopqrstuvwxyz efghijklmnopqrstuvwxyz vwxyz emptyfile file siette ocho nueve diez MULT
|
// spell-checker:ignore (ToDO) abcdefghijklmnopqrstuvwxyz efghijklmnopqrstuvwxyz vwxyz emptyfile file siette ocho nueve diez MULT
|
||||||
// spell-checker:ignore (libs) kqueue
|
// spell-checker:ignore (libs) kqueue
|
||||||
// spell-checker:ignore (jargon) tailable untailable datasame runneradmin tmpi
|
// spell-checker:ignore (jargon) tailable untailable datasame runneradmin tmpi
|
||||||
|
#![allow(
|
||||||
|
clippy::unicode_not_nfc,
|
||||||
|
clippy::cast_lossless,
|
||||||
|
clippy::cast_possible_truncation
|
||||||
|
)]
|
||||||
|
|
||||||
use crate::common::random::{AlphanumericNewline, RandomString};
|
use crate::common::random::{AlphanumericNewline, RandomizedString};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::common::util::expected_result;
|
use crate::common::util::expected_result;
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -192,12 +197,12 @@ fn test_nc_0_wo_follow() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(all(unix, not(target_os = "freebsd")))]
|
#[cfg(all(unix, not(target_os = "freebsd")))]
|
||||||
fn test_nc_0_wo_follow2() {
|
fn test_nc_0_wo_follow2() {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
// verify that -[nc]0 without -f, exit without reading
|
// verify that -[nc]0 without -f, exit without reading
|
||||||
|
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let at = &ts.fixtures;
|
let at = &ts.fixtures;
|
||||||
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
at.make_file("unreadable")
|
at.make_file("unreadable")
|
||||||
.set_permissions(PermissionsExt::from_mode(0o000))
|
.set_permissions(PermissionsExt::from_mode(0o000))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -220,10 +225,11 @@ fn test_nc_0_wo_follow2() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_permission_denied() {
|
fn test_permission_denied() {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let at = &ts.fixtures;
|
let at = &ts.fixtures;
|
||||||
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
at.make_file("unreadable")
|
at.make_file("unreadable")
|
||||||
.set_permissions(PermissionsExt::from_mode(0o000))
|
.set_permissions(PermissionsExt::from_mode(0o000))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -240,13 +246,14 @@ fn test_permission_denied() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_permission_denied_multiple() {
|
fn test_permission_denied_multiple() {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
let at = &ts.fixtures;
|
let at = &ts.fixtures;
|
||||||
|
|
||||||
at.touch("file1");
|
at.touch("file1");
|
||||||
at.touch("file2");
|
at.touch("file2");
|
||||||
|
|
||||||
use std::os::unix::fs::PermissionsExt;
|
|
||||||
at.make_file("unreadable")
|
at.make_file("unreadable")
|
||||||
.set_permissions(PermissionsExt::from_mode(0o000))
|
.set_permissions(PermissionsExt::from_mode(0o000))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -2804,7 +2811,7 @@ fn test_pipe_when_lines_option_given_multibyte_utf8_characters() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size_no_newline_at_eof() {
|
fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size_no_newline_at_eof() {
|
||||||
let total_lines = 1;
|
let total_lines = 1;
|
||||||
let random_string = RandomString::generate_with_delimiter(
|
let random_string = RandomizedString::generate_with_delimiter(
|
||||||
Alphanumeric,
|
Alphanumeric,
|
||||||
b'\n',
|
b'\n',
|
||||||
total_lines,
|
total_lines,
|
||||||
|
@ -2834,7 +2841,7 @@ fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size_no_newli
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size() {
|
fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size() {
|
||||||
let total_lines = 100;
|
let total_lines = 100;
|
||||||
let random_string = RandomString::generate_with_delimiter(
|
let random_string = RandomizedString::generate_with_delimiter(
|
||||||
Alphanumeric,
|
Alphanumeric,
|
||||||
b'\n',
|
b'\n',
|
||||||
total_lines,
|
total_lines,
|
||||||
|
@ -2894,7 +2901,7 @@ fn test_pipe_when_lines_option_given_input_size_is_equal_to_buffer_size() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipe_when_lines_option_given_input_size_is_one_byte_greater_than_buffer_size() {
|
fn test_pipe_when_lines_option_given_input_size_is_one_byte_greater_than_buffer_size() {
|
||||||
let total_lines = 100;
|
let total_lines = 100;
|
||||||
let random_string = RandomString::generate_with_delimiter(
|
let random_string = RandomizedString::generate_with_delimiter(
|
||||||
Alphanumeric,
|
Alphanumeric,
|
||||||
b'\n',
|
b'\n',
|
||||||
total_lines,
|
total_lines,
|
||||||
|
@ -2942,7 +2949,7 @@ fn test_pipe_when_lines_option_given_input_size_is_one_byte_greater_than_buffer_
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn test_pipe_when_lines_option_given_input_size_has_multiple_size_of_buffer_size() {
|
fn test_pipe_when_lines_option_given_input_size_has_multiple_size_of_buffer_size() {
|
||||||
let total_lines = 100;
|
let total_lines = 100;
|
||||||
let random_string = RandomString::generate_with_delimiter(
|
let random_string = RandomizedString::generate_with_delimiter(
|
||||||
Alphanumeric,
|
Alphanumeric,
|
||||||
b'\n',
|
b'\n',
|
||||||
total_lines,
|
total_lines,
|
||||||
|
@ -3134,7 +3141,7 @@ fn test_pipe_when_bytes_option_given_multibyte_utf8_characters() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipe_when_bytes_option_given_input_size_is_equal_to_buffer_size() {
|
fn test_pipe_when_bytes_option_given_input_size_is_equal_to_buffer_size() {
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE);
|
let random_string = RandomizedString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE);
|
||||||
let random_string = random_string.as_str();
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -3193,7 +3200,7 @@ fn test_pipe_when_bytes_option_given_input_size_is_equal_to_buffer_size() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pipe_when_bytes_option_given_input_size_is_one_byte_greater_than_buffer_size() {
|
fn test_pipe_when_bytes_option_given_input_size_is_one_byte_greater_than_buffer_size() {
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE + 1);
|
let random_string = RandomizedString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE + 1);
|
||||||
let random_string = random_string.as_str();
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -3248,7 +3255,7 @@ fn test_pipe_when_bytes_option_given_input_size_is_one_byte_greater_than_buffer_
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn test_pipe_when_bytes_option_given_input_size_has_multiple_size_of_buffer_size() {
|
fn test_pipe_when_bytes_option_given_input_size_has_multiple_size_of_buffer_size() {
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE * 3);
|
let random_string = RandomizedString::generate(AlphanumericNewline, CHUNK_BUFFER_SIZE * 3);
|
||||||
let random_string = random_string.as_str();
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -3364,7 +3371,7 @@ fn test_seek_bytes_forward_outside_file() {
|
||||||
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME:
|
#[cfg(all(not(target_os = "android"), not(target_os = "windows")))] // FIXME:
|
||||||
#[test]
|
#[test]
|
||||||
fn test_args_when_presume_input_pipe_given_input_is_pipe() {
|
fn test_args_when_presume_input_pipe_given_input_is_pipe() {
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
let random_string = RandomizedString::generate(AlphanumericNewline, 1000);
|
||||||
let random_string = random_string.as_str();
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
@ -3400,7 +3407,7 @@ fn test_args_when_presume_input_pipe_given_input_is_pipe() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_args_when_presume_input_pipe_given_input_is_file() {
|
fn test_args_when_presume_input_pipe_given_input_is_file() {
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, 1000);
|
let random_string = RandomizedString::generate(AlphanumericNewline, 1000);
|
||||||
let random_string = random_string.as_str();
|
let random_string = random_string.as_str();
|
||||||
|
|
||||||
let ts = TestScenario::new(util_name!());
|
let ts = TestScenario::new(util_name!());
|
||||||
|
@ -3481,7 +3488,7 @@ fn test_when_argument_file_is_a_symlink() {
|
||||||
.no_stdout()
|
.no_stdout()
|
||||||
.no_stderr();
|
.no_stderr();
|
||||||
|
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, 100);
|
let random_string = RandomizedString::generate(AlphanumericNewline, 100);
|
||||||
let result = file.write_all(random_string.as_bytes());
|
let result = file.write_all(random_string.as_bytes());
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
@ -3593,7 +3600,7 @@ fn test_when_argument_file_is_non_existent_unix_socket_address_then_error() {
|
||||||
let path = "file";
|
let path = "file";
|
||||||
let mut file = at.make_file(path);
|
let mut file = at.make_file(path);
|
||||||
|
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, 100);
|
let random_string = RandomizedString::generate(AlphanumericNewline, 100);
|
||||||
let result = file.write_all(random_string.as_bytes());
|
let result = file.write_all(random_string.as_bytes());
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::borrow_as_ptr)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
|
|
@ -677,9 +677,6 @@ fn test_file_not_owned_by_euid() {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn test_file_owned_by_egid() {
|
fn test_file_owned_by_egid() {
|
||||||
let scene = TestScenario::new(util_name!());
|
|
||||||
let at = &scene.fixtures;
|
|
||||||
|
|
||||||
// On some platforms (mostly the BSDs) the test fixture files copied to the
|
// On some platforms (mostly the BSDs) the test fixture files copied to the
|
||||||
// /tmp directory will have a different gid than the current egid (due to
|
// /tmp directory will have a different gid than the current egid (due to
|
||||||
// the sticky bit set on the /tmp directory). Fix this before running the
|
// the sticky bit set on the /tmp directory). Fix this before running the
|
||||||
|
@ -688,15 +685,17 @@ fn test_file_owned_by_egid() {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
use uucore::process::getegid;
|
use uucore::process::getegid;
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
let metadata = at.metadata("regular_file");
|
let metadata = at.metadata("regular_file");
|
||||||
let file_gid = metadata.gid();
|
let file_gid = metadata.gid();
|
||||||
let user_gid = getegid();
|
let user_gid = getegid();
|
||||||
|
|
||||||
if user_gid != file_gid {
|
if user_gid != file_gid {
|
||||||
let file_uid = metadata.uid();
|
let file_metadata_uid = metadata.uid();
|
||||||
let path = CString::new(at.plus("regular_file").as_os_str().as_bytes()).expect("bad path");
|
let path = CString::new(at.plus("regular_file").as_os_str().as_bytes()).expect("bad path");
|
||||||
let r = unsafe { libc::chown(path.as_ptr(), file_uid, user_gid) };
|
let r = unsafe { libc::chown(path.as_ptr(), file_metadata_uid, user_gid) };
|
||||||
assert_ne!(r, -1);
|
assert_ne!(r, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::cast_possible_wrap)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -357,6 +357,7 @@ struct TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
fn gnu_tests() {
|
fn gnu_tests() {
|
||||||
let cases = [
|
let cases = [
|
||||||
TestCase {
|
TestCase {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
//
|
//
|
||||||
// spell-checker:ignore bincode serde utmp runlevel testusr testx
|
// spell-checker:ignore bincode serde utmp runlevel testusr testx
|
||||||
|
#![allow(clippy::cast_possible_wrap, clippy::unreadable_literal)]
|
||||||
|
|
||||||
use crate::common::util::TestScenario;
|
use crate::common::util::TestScenario;
|
||||||
|
|
||||||
|
@ -99,6 +100,7 @@ fn test_uptime_with_non_existent_file() {
|
||||||
// This will pass
|
// This will pass
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(any(target_os = "openbsd", target_os = "macos")))]
|
#[cfg(not(any(target_os = "openbsd", target_os = "macos")))]
|
||||||
|
#[allow(clippy::too_many_lines, clippy::items_after_statements)]
|
||||||
fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
|
fn test_uptime_with_file_containing_valid_boot_time_utmpx_record() {
|
||||||
// This test will pass for freebsd but we currently don't support changing the utmpx file for
|
// This test will pass for freebsd but we currently don't support changing the utmpx file for
|
||||||
// freebsd.
|
// freebsd.
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
use crate::common::util::{vec_of_size, TestScenario};
|
use crate::common::util::{vec_of_size, TestScenario};
|
||||||
|
|
||||||
// spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars
|
// spell-checker:ignore (flags) lwmcL clmwL ; (path) bogusfile emptyfile manyemptylines moby notrailingnewline onelongemptyline onelongword weirdchars
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_invalid_arg() {
|
fn test_invalid_arg() {
|
||||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||||
|
@ -357,6 +357,19 @@ fn test_file_one_long_word() {
|
||||||
/// bytes are displayed.
|
/// bytes are displayed.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file_bytes_dictate_width() {
|
fn test_file_bytes_dictate_width() {
|
||||||
|
// . is a directory, so minimum_width should get set to 7
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const STDOUT: &str = concat!(
|
||||||
|
" 0 0 0 emptyfile.txt\n",
|
||||||
|
" 0 0 0 .\n",
|
||||||
|
" 0 0 0 total\n",
|
||||||
|
);
|
||||||
|
#[cfg(windows)]
|
||||||
|
const STDOUT: &str = concat!(
|
||||||
|
" 0 0 0 emptyfile.txt\n",
|
||||||
|
" 0 0 0 total\n",
|
||||||
|
);
|
||||||
|
|
||||||
// This file has 10,001 bytes. Five digits are required to
|
// This file has 10,001 bytes. Five digits are required to
|
||||||
// represent that. Even though the number of lines is 1 and the
|
// represent that. Even though the number of lines is 1 and the
|
||||||
// number of words is 0, each of those counts is formatted with
|
// number of words is 0, each of those counts is formatted with
|
||||||
|
@ -384,18 +397,6 @@ fn test_file_bytes_dictate_width() {
|
||||||
" 18 166 1074 total\n",
|
" 18 166 1074 total\n",
|
||||||
));
|
));
|
||||||
|
|
||||||
// . is a directory, so minimum_width should get set to 7
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
const STDOUT: &str = concat!(
|
|
||||||
" 0 0 0 emptyfile.txt\n",
|
|
||||||
" 0 0 0 .\n",
|
|
||||||
" 0 0 0 total\n",
|
|
||||||
);
|
|
||||||
#[cfg(windows)]
|
|
||||||
const STDOUT: &str = concat!(
|
|
||||||
" 0 0 0 emptyfile.txt\n",
|
|
||||||
" 0 0 0 total\n",
|
|
||||||
);
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-lwc", "emptyfile.txt", "."])
|
.args(&["-lwc", "emptyfile.txt", "."])
|
||||||
.run()
|
.run()
|
||||||
|
@ -737,6 +738,10 @@ fn files0_from_dir() {
|
||||||
concat!("wc: cannot open ", $p, " for reading: Permission denied\n")
|
concat!("wc: cannot open ", $p, " for reading: Permission denied\n")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
const DOT_ERR: &str = dir_err!("'.'");
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
const DOT_ERR: &str = dir_err!(".");
|
||||||
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--files0-from=dir with spaces"])
|
.args(&["--files0-from=dir with spaces"])
|
||||||
|
@ -744,10 +749,6 @@ fn files0_from_dir() {
|
||||||
.stderr_only(dir_err!("'dir with spaces'"));
|
.stderr_only(dir_err!("'dir with spaces'"));
|
||||||
|
|
||||||
// Those contexts have different rules about quoting in errors...
|
// Those contexts have different rules about quoting in errors...
|
||||||
#[cfg(windows)]
|
|
||||||
const DOT_ERR: &str = dir_err!("'.'");
|
|
||||||
#[cfg(not(windows))]
|
|
||||||
const DOT_ERR: &str = dir_err!(".");
|
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--files0-from=."])
|
.args(&["--files0-from=."])
|
||||||
.fails()
|
.fails()
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// file that was distributed with this source code.
|
||||||
|
#![allow(clippy::naive_bytecount)]
|
||||||
|
|
||||||
use rand::distributions::{Distribution, Uniform};
|
use rand::distributions::{Distribution, Uniform};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
@ -54,20 +55,20 @@ impl Distribution<u8> for AlphanumericNewline {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// use crate::common::random::{AlphanumericNewline, RandomString};
|
/// use crate::common::random::{AlphanumericNewline, RandomizedString};
|
||||||
/// use rand::distributions::Alphanumeric;
|
/// use rand::distributions::Alphanumeric;
|
||||||
///
|
///
|
||||||
/// // generates a 100 byte string with characters from AlphanumericNewline
|
/// // generates a 100 byte string with characters from AlphanumericNewline
|
||||||
/// let random_string = RandomString::generate(AlphanumericNewline, 100);
|
/// let random_string = RandomizedString::generate(AlphanumericNewline, 100);
|
||||||
/// assert_eq!(100, random_string.len());
|
/// assert_eq!(100, random_string.len());
|
||||||
///
|
///
|
||||||
/// // generates a 100 byte string with 10 newline characters not ending with a newline
|
/// // generates a 100 byte string with 10 newline characters not ending with a newline
|
||||||
/// let string = RandomString::generate_with_delimiter(Alphanumeric, b'\n', 10, false, 100);
|
/// let string = RandomizedString::generate_with_delimiter(Alphanumeric, b'\n', 10, false, 100);
|
||||||
/// assert_eq!(100, random_string.len());
|
/// assert_eq!(100, random_string.len());
|
||||||
/// ```
|
/// ```
|
||||||
pub struct RandomString;
|
pub struct RandomizedString;
|
||||||
|
|
||||||
impl RandomString {
|
impl RandomizedString {
|
||||||
/// Generate a random string from the given [`Distribution`] with the given `length` in bytes.
|
/// Generate a random string from the given [`Distribution`] with the given `length` in bytes.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -105,10 +106,10 @@ impl RandomString {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// use crate::common::random::{AlphanumericNewline, RandomString};
|
/// use crate::common::random::{AlphanumericNewline, RandomizedString};
|
||||||
///
|
///
|
||||||
/// // generates a 100 byte string with 10 '\0' byte characters not ending with a '\0' byte
|
/// // generates a 100 byte string with 10 '\0' byte characters not ending with a '\0' byte
|
||||||
/// let string = RandomString::generate_with_delimiter(AlphanumericNewline, 0, 10, false, 100);
|
/// let string = RandomizedString::generate_with_delimiter(AlphanumericNewline, 0, 10, false, 100);
|
||||||
/// assert_eq!(100, random_string.len());
|
/// assert_eq!(100, random_string.len());
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// 10,
|
/// 10,
|
||||||
|
@ -183,25 +184,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 = RandomizedString::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 = RandomizedString::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 = RandomizedString::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 = RandomizedString::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 = RandomizedString::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]));
|
||||||
|
@ -210,7 +211,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign
|
#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign
|
||||||
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 = RandomizedString::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,
|
||||||
|
@ -218,7 +219,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 = RandomizedString::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,
|
||||||
|
@ -226,7 +227,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 = RandomizedString::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,
|
||||||
|
@ -234,7 +235,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 = RandomizedString::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,
|
||||||
|
@ -242,7 +243,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 = RandomizedString::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,
|
||||||
|
@ -254,21 +255,21 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign
|
#[allow(clippy::cognitive_complexity)] // Ignore clippy lint of too long function sign
|
||||||
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 = RandomizedString::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 = RandomizedString::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 = RandomizedString::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,
|
||||||
|
@ -276,7 +277,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 = RandomizedString::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,
|
||||||
|
@ -284,7 +285,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 = RandomizedString::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,
|
||||||
|
@ -296,7 +297,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);
|
RandomizedString::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,
|
||||||
|
@ -304,7 +305,8 @@ 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, 100, true, 1000);
|
let random_string =
|
||||||
|
RandomizedString::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,
|
||||||
|
@ -321,12 +323,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_generate_random_strings_when_length_is_around_critical_buffer_sizes() {
|
fn test_generate_random_strings_when_length_is_around_critical_buffer_sizes() {
|
||||||
let length = 8192 * 3;
|
let length = 8192 * 3;
|
||||||
let random_string = RandomString::generate(AlphanumericNewline, length);
|
let random_string = RandomizedString::generate(AlphanumericNewline, length);
|
||||||
assert_eq!(length, random_string.len());
|
assert_eq!(length, random_string.len());
|
||||||
|
|
||||||
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);
|
RandomizedString::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,
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
//spell-checker: ignore (linux) winsize xpixel ypixel setrlimit FSIZE
|
//spell-checker: ignore (linux) winsize xpixel ypixel setrlimit FSIZE
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
#![allow(
|
||||||
|
clippy::too_many_lines,
|
||||||
|
clippy::should_panic_without_expect,
|
||||||
|
clippy::missing_errors_doc
|
||||||
|
)]
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use libc::mode_t;
|
use libc::mode_t;
|
||||||
|
@ -793,7 +798,7 @@ pub fn compare_xattrs<P: AsRef<std::path::Path>>(path1: P, path2: P) -> bool {
|
||||||
attrs.sort();
|
attrs.sort();
|
||||||
attrs
|
attrs
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|_| Vec::new())
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
get_sorted_xattrs(path1) == get_sorted_xattrs(path2)
|
get_sorted_xattrs(path1) == get_sorted_xattrs(path2)
|
||||||
|
@ -1491,7 +1496,6 @@ impl UCommand {
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn spawn_reader_thread(
|
fn spawn_reader_thread(
|
||||||
&self,
|
|
||||||
captured_output: Option<CapturedOutput>,
|
captured_output: Option<CapturedOutput>,
|
||||||
pty_fd_master: OwnedFd,
|
pty_fd_master: OwnedFd,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -1678,7 +1682,7 @@ impl UCommand {
|
||||||
slave: po_slave,
|
slave: po_slave,
|
||||||
master: po_master,
|
master: po_master,
|
||||||
} = nix::pty::openpty(&terminal_size, None).unwrap();
|
} = nix::pty::openpty(&terminal_size, None).unwrap();
|
||||||
captured_stdout = self.spawn_reader_thread(
|
captured_stdout = Self::spawn_reader_thread(
|
||||||
captured_stdout,
|
captured_stdout,
|
||||||
po_master,
|
po_master,
|
||||||
"stdout_reader".to_string(),
|
"stdout_reader".to_string(),
|
||||||
|
@ -1691,7 +1695,7 @@ impl UCommand {
|
||||||
slave: pe_slave,
|
slave: pe_slave,
|
||||||
master: pe_master,
|
master: pe_master,
|
||||||
} = nix::pty::openpty(&terminal_size, None).unwrap();
|
} = nix::pty::openpty(&terminal_size, None).unwrap();
|
||||||
captured_stderr = self.spawn_reader_thread(
|
captured_stderr = Self::spawn_reader_thread(
|
||||||
captured_stderr,
|
captured_stderr,
|
||||||
pe_master,
|
pe_master,
|
||||||
"stderr_reader".to_string(),
|
"stderr_reader".to_string(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue