mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 03:36:18 +00:00
commit
48a521224e
54 changed files with 523 additions and 203 deletions
|
@ -5,7 +5,7 @@ use std::fs::OpenOptions;
|
|||
#[cfg(unix)]
|
||||
use std::io::Read;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use rlimit::Resource;
|
||||
|
||||
#[test]
|
||||
|
@ -93,7 +93,7 @@ fn test_fifo_symlink() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_closes_file_descriptors() {
|
||||
// Each file creates a pipe, which has two file descriptors.
|
||||
// If they are not closed then five is certainly too many.
|
||||
|
@ -396,10 +396,10 @@ fn test_squeeze_blank_before_numbering() {
|
|||
#[cfg(unix)]
|
||||
fn test_dev_random() {
|
||||
let mut buf = [0; 2048];
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
const DEV_RANDOM: &str = "/dev/urandom";
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
const DEV_RANDOM: &str = "/dev/random";
|
||||
|
||||
let mut proc = new_ucmd!().args(&[DEV_RANDOM]).run_no_wait();
|
||||
|
|
|
@ -8,7 +8,7 @@ fn test_invalid_option() {
|
|||
new_ucmd!().arg("-w").arg("/").fails();
|
||||
}
|
||||
|
||||
static DIR: &str = "/tmp";
|
||||
static DIR: &str = "/dev";
|
||||
|
||||
// we should always get both arguments, regardless of whether --reference was used
|
||||
#[test]
|
||||
|
@ -49,11 +49,13 @@ fn test_invalid_group() {
|
|||
#[test]
|
||||
fn test_1() {
|
||||
if get_effective_gid() != 0 {
|
||||
new_ucmd!()
|
||||
.arg("bin")
|
||||
.arg(DIR)
|
||||
.fails()
|
||||
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
|
||||
new_ucmd!().arg("bin").arg(DIR).fails().stderr_contains(
|
||||
// linux fails with "Operation not permitted (os error 1)"
|
||||
// because of insufficient permissions,
|
||||
// android fails with "Permission denied (os error 13)"
|
||||
// because it can't resolve /proc (even though it can resolve /proc/self/)
|
||||
"chgrp: changing group of '/dev': ",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +78,7 @@ fn test_preserve_root() {
|
|||
// It's weird that on OS X, `realpath /etc/..` returns '/private'
|
||||
for d in [
|
||||
"/",
|
||||
"/////tmp///../../../../",
|
||||
"/////dev///../../../../",
|
||||
"../../../../../../../../../../../../../../",
|
||||
"./../../../../../../../../../../../../../../",
|
||||
] {
|
||||
|
@ -94,7 +96,7 @@ fn test_preserve_root_symlink() {
|
|||
let file = "test_chgrp_symlink2root";
|
||||
for d in [
|
||||
"/",
|
||||
"////tmp//../../../../",
|
||||
"////dev//../../../../",
|
||||
"..//../../..//../..//../../../../../../../../",
|
||||
".//../../../../../../..//../../../../../../../",
|
||||
] {
|
||||
|
@ -108,7 +110,7 @@ fn test_preserve_root_symlink() {
|
|||
}
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.symlink_file("///usr", file);
|
||||
at.symlink_file("///dev", file);
|
||||
ucmd.arg("--preserve-root")
|
||||
.arg("-HR")
|
||||
.arg("bin").arg(format!(".//{}/..//..//../../", file))
|
||||
|
@ -116,15 +118,12 @@ fn test_preserve_root_symlink() {
|
|||
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
|
||||
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.symlink_file("/", "/tmp/__root__");
|
||||
at.symlink_file("/", "__root__");
|
||||
ucmd.arg("--preserve-root")
|
||||
.arg("-R")
|
||||
.arg("bin").arg("/tmp/__root__/.")
|
||||
.arg("bin").arg("__root__/.")
|
||||
.fails()
|
||||
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
|
||||
|
||||
use std::fs;
|
||||
fs::remove_file("/tmp/__root__").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -156,7 +155,7 @@ fn test_reference() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
fn test_reference_multi_no_equal() {
|
||||
new_ucmd!()
|
||||
.arg("-v")
|
||||
|
@ -170,7 +169,7 @@ fn test_reference_multi_no_equal() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
fn test_reference_last() {
|
||||
new_ucmd!()
|
||||
.arg("-v")
|
||||
|
@ -212,7 +211,7 @@ fn test_big_p() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_big_h() {
|
||||
if get_effective_gid() != 0 {
|
||||
assert!(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp
|
||||
|
||||
use crate::common::util::*;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use rust_users::get_effective_uid;
|
||||
|
||||
extern crate chown;
|
||||
|
@ -617,7 +617,7 @@ fn test_root_preserve() {
|
|||
result.stderr_contains(&"chown: it is dangerous to operate recursively");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_big_p() {
|
||||
if get_effective_uid() != 0 {
|
||||
|
@ -627,7 +627,11 @@ fn test_big_p() {
|
|||
.arg("/proc/self/cwd")
|
||||
.fails()
|
||||
.stderr_contains(
|
||||
"chown: changing ownership of '/proc/self/cwd': Operation not permitted (os error 1)",
|
||||
// linux fails with "Operation not permitted (os error 1)"
|
||||
// because of insufficient permissions,
|
||||
// android fails with "Permission denied (os error 13)"
|
||||
// because it can't resolve /proc (even though it can resolve /proc/self/)
|
||||
"chown: changing ownership of '/proc/self/cwd': ",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ fn test_missing_operand() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn test_enter_chroot_fails() {
|
||||
// NOTE: since #2689 this test also ensures that we don't regress #2687
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -14,15 +14,15 @@ use std::os::unix::fs::PermissionsExt;
|
|||
#[cfg(windows)]
|
||||
use std::os::windows::fs::symlink_file;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use filetime::FileTime;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use rlimit::Resource;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::fs as std_fs;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::thread::sleep;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::time::Duration;
|
||||
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
|
@ -38,11 +38,11 @@ static TEST_COPY_FROM_FOLDER: &str = "hello_dir_with_file/";
|
|||
static TEST_COPY_FROM_FOLDER_FILE: &str = "hello_dir_with_file/hello_world.txt";
|
||||
static TEST_COPY_TO_FOLDER_NEW: &str = "hello_dir_new";
|
||||
static TEST_COPY_TO_FOLDER_NEW_FILE: &str = "hello_dir_new/hello_world.txt";
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
|
||||
static TEST_MOUNT_COPY_FROM_FOLDER: &str = "dir_with_mount";
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
|
||||
static TEST_MOUNT_MOUNTPOINT: &str = "mount";
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
|
||||
static TEST_MOUNT_OTHER_FILESYSTEM_FILE: &str = "mount/DO_NOT_copy_me.txt";
|
||||
#[cfg(unix)]
|
||||
static TEST_NONEXISTENT_FILE: &str = "nonexistent_file.txt";
|
||||
|
@ -1062,7 +1062,7 @@ fn test_cp_archive() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
fn test_cp_archive_recursive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
|
@ -1132,7 +1132,7 @@ fn test_cp_archive_recursive() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_cp_preserve_timestamps() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let ts = time::now().to_timespec();
|
||||
|
@ -1165,7 +1165,7 @@ fn test_cp_preserve_timestamps() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_cp_no_preserve_timestamps() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let ts = time::now().to_timespec();
|
||||
|
@ -1206,7 +1206,7 @@ fn test_cp_no_preserve_timestamps() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_cp_target_file_dev_null() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let file1 = "/dev/null";
|
||||
|
@ -1219,7 +1219,7 @@ fn test_cp_target_file_dev_null() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "freebsd"))]
|
||||
fn test_cp_one_file_system() {
|
||||
use crate::common::util::AtPath;
|
||||
use walkdir::WalkDir;
|
||||
|
@ -1283,7 +1283,7 @@ fn test_cp_one_file_system() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
|
||||
fn test_cp_reflink_always() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let result = ucmd
|
||||
|
@ -1301,7 +1301,7 @@ fn test_cp_reflink_always() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
|
||||
fn test_cp_reflink_auto() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
ucmd.arg("--reflink=auto")
|
||||
|
@ -1314,7 +1314,7 @@ fn test_cp_reflink_auto() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
|
||||
fn test_cp_reflink_never() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
ucmd.arg("--reflink=never")
|
||||
|
@ -1327,7 +1327,7 @@ fn test_cp_reflink_never() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos"))]
|
||||
fn test_cp_reflink_bad() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
let _result = ucmd
|
||||
|
@ -1339,7 +1339,7 @@ fn test_cp_reflink_bad() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_cp_reflink_insufficient_permission() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
|
@ -1355,7 +1355,7 @@ fn test_cp_reflink_insufficient_permission() {
|
|||
.stderr_only("cp: 'unreadable' -> 'existing_file.txt': Permission denied (os error 13)");
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_closes_file_descriptors() {
|
||||
new_ucmd!()
|
||||
|
@ -1520,6 +1520,7 @@ fn test_cp_archive_on_nonexistent_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn test_cp_link_backup() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("file2");
|
||||
|
@ -1613,6 +1614,7 @@ fn test_cp_overriding_arguments() {
|
|||
("--force", "--remove-destination"),
|
||||
("--interactive", "--no-clobber"),
|
||||
("--link", "--symbolic-link"),
|
||||
#[cfg(not(target_os = "android"))]
|
||||
("--symbolic-link", "--link"),
|
||||
("--dereference", "--no-dereference"),
|
||||
("--no-dereference", "--dereference"),
|
||||
|
|
|
@ -149,7 +149,7 @@ fn test_date_set_invalid() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
|
||||
fn test_date_set_permissions_error() {
|
||||
if !(get_effective_uid() == 0 || uucore::os::is_wsl_1()) {
|
||||
let result = new_ucmd!()
|
||||
|
|
|
@ -32,7 +32,7 @@ macro_rules! assert_fixture_exists {
|
|||
}};
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
macro_rules! assert_fixture_not_exists {
|
||||
($fname:expr) => {{
|
||||
let fpath = PathBuf::from(format!("./fixtures/dd/{}", $fname));
|
||||
|
@ -261,7 +261,7 @@ fn test_final_stats_unspec() {
|
|||
new_ucmd!().run().stderr_only(&output).success();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_excl_causes_failure_when_present() {
|
||||
let fname = "this-file-exists-excl.txt";
|
||||
|
@ -272,7 +272,7 @@ fn test_excl_causes_failure_when_present() {
|
|||
.fails();
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_noatime_does_not_update_infile_atime() {
|
||||
// NOTE: Not all environments support tracking access time. If this
|
||||
|
@ -292,7 +292,7 @@ fn test_noatime_does_not_update_infile_atime() {
|
|||
assert_eq!(pre_atime, post_atime);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_noatime_does_not_update_ofile_atime() {
|
||||
// NOTE: Not all environments support tracking access time. If this
|
||||
|
@ -312,7 +312,7 @@ fn test_noatime_does_not_update_ofile_atime() {
|
|||
assert_eq!(pre_atime, post_atime);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[test]
|
||||
fn test_nocreat_causes_failure_when_outfile_not_present() {
|
||||
let fname = "this-file-does-not-exist.txt";
|
||||
|
|
|
@ -47,7 +47,7 @@ fn test_du_basics_subdir() {
|
|||
|
||||
let result = ts.ucmd().arg(SUB_DIR).succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR]));
|
||||
if result_reference.succeeded() {
|
||||
|
@ -122,7 +122,7 @@ fn test_du_soft_link() {
|
|||
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS]));
|
||||
if result_reference.succeeded() {
|
||||
|
@ -160,6 +160,7 @@ fn _du_soft_link(s: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[test]
|
||||
fn test_du_hard_link() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
@ -213,7 +214,7 @@ fn test_du_d_flag() {
|
|||
|
||||
let result = ts.ucmd().arg("-d1").succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["-d1"]));
|
||||
if result_reference.succeeded() {
|
||||
|
@ -259,7 +260,7 @@ fn test_du_dereference() {
|
|||
|
||||
let result = ts.ucmd().arg("-L").arg(SUB_DIR_LINKS).succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["-L", SUB_DIR_LINKS]));
|
||||
|
||||
|
@ -303,13 +304,13 @@ fn test_du_inodes_basic() {
|
|||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg("--inodes").succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--inodes"]));
|
||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
_du_inodes_basic(result.stdout_str());
|
||||
}
|
||||
|
||||
|
@ -357,7 +358,7 @@ fn test_du_inodes() {
|
|||
result.stdout_contains("3\t./subdir/links\n");
|
||||
result.stdout_contains("3\t.\n");
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference =
|
||||
unwrap_or_return!(expected_result(&ts, &["--separate-dirs", "--inodes"]));
|
||||
|
@ -438,7 +439,7 @@ fn test_du_no_permission() {
|
|||
"du: cannot read directory 'subdir/links': Permission denied (os error 13)",
|
||||
);
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &[SUB_DIR_LINKS]));
|
||||
if result_reference
|
||||
|
@ -483,7 +484,7 @@ fn test_du_one_file_system() {
|
|||
|
||||
let result = ts.ucmd().arg("-x").arg(SUB_DIR).succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["-x", SUB_DIR]));
|
||||
if result_reference.succeeded() {
|
||||
|
@ -518,13 +519,13 @@ fn test_du_apparent_size() {
|
|||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg("--apparent-size").succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--apparent-size"]));
|
||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
_du_apparent_size(result.stdout_str());
|
||||
}
|
||||
|
||||
|
@ -586,7 +587,7 @@ fn test_du_bytes() {
|
|||
let ts = TestScenario::new(util_name!());
|
||||
let result = ts.ucmd().arg("--bytes").succeeds();
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
let result_reference = unwrap_or_return!(expected_result(&ts, &["--bytes"]));
|
||||
assert_eq!(result.stdout_str(), result_reference.stdout_str());
|
||||
|
@ -602,7 +603,8 @@ fn test_du_bytes() {
|
|||
not(target_vendor = "apple"),
|
||||
not(target_os = "windows"),
|
||||
not(target_os = "freebsd"),
|
||||
not(target_os = "linux")
|
||||
not(target_os = "linux"),
|
||||
not(target_os = "android"),
|
||||
))]
|
||||
result.stdout_contains("21529\t./subdir\n");
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ fn test_id_real() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "linux")))]
|
||||
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
|
||||
fn test_id_pretty_print() {
|
||||
// `-p` is BSD only and not supported on GNU's `id`
|
||||
let username = whoami();
|
||||
|
@ -159,7 +159,7 @@ fn test_id_pretty_print() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "linux")))]
|
||||
#[cfg(all(unix, not(any(target_os = "linux", target_os = "android"))))]
|
||||
fn test_id_password_style() {
|
||||
// `-P` is BSD only and not supported on GNU's `id`
|
||||
let username = whoami();
|
||||
|
@ -437,7 +437,10 @@ fn test_id_no_specified_user_posixly() {
|
|||
result.success();
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", feature = "feat_selinux"))]
|
||||
#[cfg(all(
|
||||
any(target_os = "linux", target_os = "android"),
|
||||
feature = "feat_selinux"
|
||||
))]
|
||||
{
|
||||
use selinux::{self, KernelSupport};
|
||||
if selinux::kernel_support() == KernelSupport::Unsupported {
|
||||
|
|
|
@ -6,7 +6,7 @@ use rust_users::*;
|
|||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(not(any(windows, target_os = "freebsd")))]
|
||||
use std::process::Command;
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use std::thread::sleep;
|
||||
|
||||
#[test]
|
||||
|
@ -98,7 +98,11 @@ fn test_install_ancestors_mode_directories() {
|
|||
let ancestor2 = "ancestor1/ancestor2";
|
||||
let target_dir = "ancestor1/ancestor2/target_dir";
|
||||
let directories_arg = "-d";
|
||||
let mode_arg = "--mode=700";
|
||||
let mode_arg = "--mode=200";
|
||||
let probe = "probe";
|
||||
|
||||
at.mkdir(probe);
|
||||
let default_perms = at.metadata(probe).permissions().mode();
|
||||
|
||||
ucmd.args(&[mode_arg, directories_arg, target_dir])
|
||||
.succeeds()
|
||||
|
@ -108,11 +112,11 @@ fn test_install_ancestors_mode_directories() {
|
|||
assert!(at.dir_exists(ancestor2));
|
||||
assert!(at.dir_exists(target_dir));
|
||||
|
||||
assert_ne!(0o40_700_u32, at.metadata(ancestor1).permissions().mode());
|
||||
assert_ne!(0o40_700_u32, at.metadata(ancestor2).permissions().mode());
|
||||
assert_eq!(default_perms, at.metadata(ancestor1).permissions().mode());
|
||||
assert_eq!(default_perms, at.metadata(ancestor2).permissions().mode());
|
||||
|
||||
// Expected mode only on the target_dir.
|
||||
assert_eq!(0o40_700_u32, at.metadata(target_dir).permissions().mode());
|
||||
assert_eq!(0o40_200_u32, at.metadata(target_dir).permissions().mode());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -386,7 +390,7 @@ fn test_install_copy_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_install_target_file_dev_null() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
|
@ -487,7 +491,7 @@ fn test_install_copy_then_compare_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_install_copy_then_compare_file_with_extra_mode() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
@ -549,6 +553,8 @@ const STRIP_SOURCE_FILE_SYMBOL: &str = "main";
|
|||
fn strip_source_file() -> &'static str {
|
||||
if cfg!(target_os = "macos") {
|
||||
"helloworld_macos"
|
||||
} else if cfg!(target_arch = "arm") || cfg!(target_arch = "aarch64") {
|
||||
"helloworld_android"
|
||||
} else {
|
||||
"helloworld_linux"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
#[test]
|
||||
fn test_link_existing_file() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
|
|
@ -360,7 +360,7 @@ fn test_symlink_verbose() {
|
|||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-v", file_a, file_b])
|
||||
.args(&["-s", "-v", file_a, file_b])
|
||||
.succeeds()
|
||||
.stdout_only(format!("'{}' -> '{}'\n", file_b, file_a));
|
||||
|
||||
|
@ -368,7 +368,7 @@ fn test_symlink_verbose() {
|
|||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-v", "-b", file_a, file_b])
|
||||
.args(&["-s", "-v", "-b", file_a, file_b])
|
||||
.succeeds()
|
||||
.stdout_only(format!(
|
||||
"'{}' -> '{}' (backup: '{}~')\n",
|
||||
|
@ -639,7 +639,7 @@ fn test_backup_force() {
|
|||
assert!(at.file_exists("b~"));
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["-f", "--b=simple", "a", "b"])
|
||||
.args(&["-s", "-f", "--b=simple", "a", "b"])
|
||||
.succeeds()
|
||||
.no_stderr();
|
||||
assert!(at.file_exists("a"));
|
||||
|
|
|
@ -314,7 +314,7 @@ fn test_ls_devices() {
|
|||
.stdout_matches(&Regex::new("[^ ] 3, 2 [^ ]").unwrap());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
scene
|
||||
.ucmd()
|
||||
|
@ -327,11 +327,15 @@ fn test_ls_devices() {
|
|||
// Tests display alignment against a file (stdout is a link to a tty)
|
||||
#[cfg(unix)]
|
||||
{
|
||||
#[cfg(not(target_os = "android"))]
|
||||
let stdout = "/dev/stdout";
|
||||
#[cfg(target_os = "android")]
|
||||
let stdout = "/proc/self/fd/1";
|
||||
let res = scene
|
||||
.ucmd()
|
||||
.arg("-alL")
|
||||
.arg("/dev/null")
|
||||
.arg("/dev/stdout")
|
||||
.arg(stdout)
|
||||
.succeeds();
|
||||
|
||||
let null_len = String::from_utf8(res.stdout().to_owned())
|
||||
|
@ -350,7 +354,7 @@ fn test_ls_devices() {
|
|||
.lines()
|
||||
.nth(1)
|
||||
.unwrap()
|
||||
.strip_suffix("/dev/stdout")
|
||||
.strip_suffix(stdout)
|
||||
.unwrap()
|
||||
.len();
|
||||
|
||||
|
@ -1546,9 +1550,9 @@ fn test_ls_order_time() {
|
|||
at.open("test-4").metadata().unwrap().accessed().unwrap();
|
||||
|
||||
// It seems to be dependent on the platform whether the access time is actually set
|
||||
#[cfg(unix)]
|
||||
#[cfg(all(unix, not(target_os = "android")))]
|
||||
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
#[cfg(any(windows, target_os = "android"))]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -783,7 +783,7 @@ fn test_mv_verbose() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))] // mkdir does not support -m on windows. Freebsd doesn't return a permission error either.
|
||||
fn test_mv_permission_error() {
|
||||
let scene = TestScenario::new("mkdir");
|
||||
let folder1 = "bar";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn test_get_current_niceness() {
|
||||
// NOTE: this assumes the test suite is being run with a default niceness
|
||||
// of 0, which may not necessarily be true
|
||||
|
@ -8,6 +9,7 @@ fn test_get_current_niceness() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(target_os = "android"))]
|
||||
fn test_negative_adjustment() {
|
||||
// This assumes the test suite is run as a normal (non-root) user, and as
|
||||
// such attempting to set a negative niceness value will be rejected by
|
||||
|
|
|
@ -6,7 +6,12 @@ use std::thread::sleep;
|
|||
// All that can be tested is the side-effects.
|
||||
|
||||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_vendor = "apple"))]
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "android",
|
||||
target_os = "freebsd",
|
||||
target_vendor = "apple"
|
||||
))]
|
||||
fn test_nohup_multiple_args_and_flags() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
|
|
|
@ -24,11 +24,14 @@ fn test_capitalize() {
|
|||
fn test_long_format() {
|
||||
let login = "root";
|
||||
let pw: Passwd = Passwd::locate(login).unwrap();
|
||||
let real_name = pw.user_info.replace('&', &pw.name.capitalize());
|
||||
let user_info = pw.user_info.unwrap_or_default();
|
||||
let user_dir = pw.user_dir.unwrap_or_default();
|
||||
let user_shell = pw.user_shell.unwrap_or_default();
|
||||
let real_name = user_info.replace('&', &pw.name.capitalize());
|
||||
let ts = TestScenario::new(util_name!());
|
||||
ts.ucmd().arg("-l").arg(login).succeeds().stdout_is(format!(
|
||||
"Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
|
||||
login, real_name, pw.user_dir, pw.user_shell
|
||||
login, real_name, user_dir, user_shell
|
||||
));
|
||||
|
||||
ts.ucmd()
|
||||
|
|
|
@ -872,7 +872,7 @@ fn sort_empty_chunk() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_compress() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
|
@ -888,7 +888,7 @@ fn test_compress() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_compress_merge() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
|
|
|
@ -113,14 +113,14 @@ fn test_invalid_option() {
|
|||
#[cfg(unix)]
|
||||
const NORMAL_FORMAT_STR: &str =
|
||||
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations
|
||||
#[cfg(any(target_os = "linux"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
const DEV_FORMAT_STR: &str =
|
||||
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z";
|
||||
#[cfg(target_os = "linux")]
|
||||
const FS_FORMAT_STR: &str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_terse_fs_format() {
|
||||
let args = ["-f", "-t", "/proc"];
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
@ -238,6 +238,7 @@ fn test_symlinks() {
|
|||
// arbitrarily chosen symlinks with hope that the CI environment provides at least one of them
|
||||
for file in [
|
||||
"/bin/sh",
|
||||
"/data/data/com.termux/files/usr/bin/sh", // spell-checker:disable-line
|
||||
"/bin/sudoedit",
|
||||
"/usr/bin/ex",
|
||||
"/etc/localtime",
|
||||
|
@ -259,7 +260,7 @@ fn test_symlinks() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_vendor = "apple"))]
|
||||
#[test]
|
||||
fn test_char() {
|
||||
// TODO: "(%t) (%x) (%w)" deviate from GNU stat for `character special file` on macOS
|
||||
|
@ -268,13 +269,13 @@ fn test_char() {
|
|||
// >"(f) (2021-05-20 23:08:03.455598000 +0200) (-)\n"
|
||||
let args = [
|
||||
"-c",
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
DEV_FORMAT_STR,
|
||||
#[cfg(target_os = "linux")]
|
||||
"/dev/pts/ptmx",
|
||||
#[cfg(any(target_vendor = "apple"))]
|
||||
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (/%T) %u %U %W %X %y %Y %z %Z",
|
||||
#[cfg(any(target_vendor = "apple"))]
|
||||
#[cfg(any(target_os = "android", target_vendor = "apple"))]
|
||||
"/dev/ptmx",
|
||||
];
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
|
|
@ -53,6 +53,11 @@ fn test_uname_kernel() {
|
|||
|
||||
#[test]
|
||||
fn test_uname_operating_system() {
|
||||
#[cfg(target_os = "android")]
|
||||
new_ucmd!()
|
||||
.arg("--operating-system")
|
||||
.succeeds()
|
||||
.stdout_is("Android\n");
|
||||
#[cfg(target_vendor = "apple")]
|
||||
new_ucmd!()
|
||||
.arg("--operating-system")
|
||||
|
|
|
@ -262,10 +262,10 @@ fn test_read_from_nonexistent_file() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn test_files_from_pseudo_filesystem() {
|
||||
let result = new_ucmd!().arg("-c").arg("/proc/version").succeeds();
|
||||
assert_ne!(result.stdout_str(), "0 /proc/version\n");
|
||||
let result = new_ucmd!().arg("-c").arg("/proc/cpuinfo").succeeds();
|
||||
assert_ne!(result.stdout_str(), "0 /proc/cpuinfo\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -670,7 +670,7 @@ impl AtPath {
|
|||
let name = CString::new(self.plus_as_string(fifo)).unwrap();
|
||||
let mut stat: libc::stat = std::mem::zeroed();
|
||||
if libc::stat(name.as_ptr(), &mut stat) >= 0 {
|
||||
libc::S_IFIFO & stat.st_mode != 0
|
||||
libc::S_IFIFO & stat.st_mode as libc::mode_t != 0
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -892,7 +892,7 @@ pub struct UCommand {
|
|||
stdout: Option<Stdio>,
|
||||
stderr: Option<Stdio>,
|
||||
bytes_into_stdin: Option<Vec<u8>>,
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
limits: Vec<(rlimit::Resource, u64, u64)>,
|
||||
}
|
||||
|
||||
|
@ -913,19 +913,21 @@ impl UCommand {
|
|||
let mut cmd = Command::new(bin_path);
|
||||
cmd.current_dir(curdir.as_ref());
|
||||
if env_clear {
|
||||
cmd.env_clear();
|
||||
if cfg!(windows) {
|
||||
// spell-checker:ignore (dll) rsaenh
|
||||
// %SYSTEMROOT% is required on Windows to initialize crypto provider
|
||||
// ... and crypto provider is required for std::rand
|
||||
// From `procmon`: RegQueryValue HKLM\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Strong Cryptographic Provider\Image Path
|
||||
// SUCCESS Type: REG_SZ, Length: 66, Data: %SystemRoot%\system32\rsaenh.dll"
|
||||
for (key, _) in env::vars_os() {
|
||||
if key.as_os_str() != "SYSTEMROOT" {
|
||||
cmd.env_remove(key);
|
||||
}
|
||||
if let Some(systemroot) = env::var_os("SYSTEMROOT") {
|
||||
cmd.env("SYSTEMROOT", systemroot);
|
||||
}
|
||||
} else {
|
||||
cmd.env_clear();
|
||||
// if someone is setting LD_PRELOAD, there's probably a good reason for it
|
||||
if let Some(ld_preload) = env::var_os("LD_PRELOAD") {
|
||||
cmd.env("LD_PRELOAD", ld_preload);
|
||||
}
|
||||
}
|
||||
}
|
||||
cmd
|
||||
|
@ -938,7 +940,7 @@ impl UCommand {
|
|||
stdin: None,
|
||||
stdout: None,
|
||||
stderr: None,
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
limits: vec![],
|
||||
};
|
||||
|
||||
|
@ -1042,7 +1044,7 @@ impl UCommand {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn with_limit(
|
||||
&mut self,
|
||||
resource: rlimit::Resource,
|
||||
|
|
BIN
tests/fixtures/install/helloworld_android
vendored
Executable file
BIN
tests/fixtures/install/helloworld_android
vendored
Executable file
Binary file not shown.
BIN
tests/fixtures/install/helloworld_linux
vendored
BIN
tests/fixtures/install/helloworld_linux
vendored
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue