mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Merge branch 'main' into default-env-for-tests
This commit is contained in:
commit
a4a290caf2
20 changed files with 84 additions and 123 deletions
12
.github/dependabot.yml
vendored
12
.github/dependabot.yml
vendored
|
@ -1,12 +0,0 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "cargo"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
open-pull-requests-limit: 10
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: weekly
|
||||
open-pull-requests-limit: 5
|
4
.github/workflows/GnuTests.yml
vendored
4
.github/workflows/GnuTests.yml
vendored
|
@ -42,7 +42,7 @@ jobs:
|
|||
outputs path_GNU path_GNU_tests path_reference path_UUTILS
|
||||
#
|
||||
repo_default_branch="${{ github.event.repository.default_branch }}"
|
||||
repo_GNU_ref="v9.1"
|
||||
repo_GNU_ref="v9.2"
|
||||
repo_reference_branch="${{ github.event.repository.default_branch }}"
|
||||
outputs repo_default_branch repo_GNU_ref repo_reference_branch
|
||||
#
|
||||
|
@ -305,7 +305,7 @@ jobs:
|
|||
with:
|
||||
repository: 'coreutils/coreutils'
|
||||
path: 'gnu'
|
||||
ref: 'v9.1'
|
||||
ref: 'v9.2'
|
||||
submodules: recursive
|
||||
- name: Install `rust` toolchain
|
||||
run: |
|
||||
|
|
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -128,9 +128,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "blake3"
|
||||
version = "1.3.2"
|
||||
version = "1.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "895adc16c8b3273fbbc32685a7d55227705eda08c01e77704020f3491924b44b"
|
||||
checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"arrayvec",
|
||||
|
@ -202,9 +202,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.23"
|
||||
version = "0.4.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
|
||||
checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b"
|
||||
dependencies = [
|
||||
"iana-time-zone",
|
||||
"num-integer",
|
||||
|
|
|
@ -268,7 +268,7 @@ binary-heap-plus = "0.5.0"
|
|||
bstr = "1.0"
|
||||
bytecount = "0.6.3"
|
||||
byteorder = "1.3.2"
|
||||
chrono = { version="^0.4.23", default-features=false, features=["std", "alloc", "clock"]}
|
||||
chrono = { version="^0.4.24", default-features=false, features=["std", "alloc", "clock"]}
|
||||
clap = { version = "4.1", features = ["wrap_help", "cargo"] }
|
||||
clap_complete = "4.0"
|
||||
clap_mangen = "0.2"
|
||||
|
@ -339,7 +339,7 @@ sha1 = "0.10.1"
|
|||
sha2 = "0.10.2"
|
||||
sha3 = "0.10.6"
|
||||
blake2b_simd = "1.0.1"
|
||||
blake3 = "1.3.2"
|
||||
blake3 = "1.3.3"
|
||||
sm3 = "0.4.1"
|
||||
digest = "0.10.6"
|
||||
|
||||
|
@ -489,7 +489,7 @@ unindent = "0.1"
|
|||
uucore = { workspace=true, features=["entries", "process", "signals"] }
|
||||
walkdir = { workspace=true }
|
||||
is-terminal = { workspace=true }
|
||||
hex-literal = "0.3.1"
|
||||
hex-literal = "0.3.4"
|
||||
rstest = "0.16.0"
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
|
||||
|
|
8
src/uu/more/more.md
Normal file
8
src/uu/more/more.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
# more
|
||||
|
||||
```
|
||||
more [OPTIONS] <FILE>...
|
||||
```
|
||||
|
||||
Display the contents of a text file
|
||||
|
|
@ -28,7 +28,10 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||
use unicode_width::UnicodeWidthStr;
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{UResult, USimpleError, UUsageError};
|
||||
use uucore::{format_usage, help_about, help_usage};
|
||||
|
||||
const ABOUT: &str = help_about!("more.md");
|
||||
const USAGE: &str = help_usage!("more.md");
|
||||
const BELL: &str = "\x07";
|
||||
|
||||
pub mod options {
|
||||
|
@ -97,7 +100,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
|
||||
pub fn uu_app() -> Command {
|
||||
Command::new(uucore::util_name())
|
||||
.about("A file perusal filter for CRT viewing.")
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
.version(crate_version!())
|
||||
.infer_long_args(true)
|
||||
.arg(
|
||||
|
|
9
src/uu/mv/mv.md
Normal file
9
src/uu/mv/mv.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# mv
|
||||
|
||||
```
|
||||
mv [OPTION]... [-T] SOURCE DEST
|
||||
mv [OPTION]... SOURCE... DIRECTORY
|
||||
mv [OPTION]... -t DIRECTORY SOURCE...
|
||||
```
|
||||
|
||||
Move `SOURCE` to `DEST`, or multiple `SOURCE`(s) to `DIRECTORY`.
|
|
@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
|
|||
use uucore::backup_control::{self, BackupMode};
|
||||
use uucore::display::Quotable;
|
||||
use uucore::error::{FromIo, UError, UResult, USimpleError, UUsageError};
|
||||
use uucore::{format_usage, prompt_yes, show};
|
||||
use uucore::{format_usage, help_about, help_usage, prompt_yes, show};
|
||||
|
||||
use fs_extra::dir::{
|
||||
get_size as dir_get_size, move_dir, move_dir_with_progress, CopyOptions as DirCopyOptions,
|
||||
|
@ -53,12 +53,8 @@ pub enum OverwriteMode {
|
|||
Force,
|
||||
}
|
||||
|
||||
static ABOUT: &str = "Move SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.";
|
||||
static LONG_HELP: &str = "";
|
||||
const USAGE: &str = "\
|
||||
{} [OPTION]... [-T] SOURCE DEST
|
||||
{} [OPTION]... SOURCE... DIRECTORY
|
||||
{} [OPTION]... -t DIRECTORY SOURCE...";
|
||||
const ABOUT: &str = help_about!("mv.md");
|
||||
const USAGE: &str = help_usage!("mv.md");
|
||||
|
||||
static OPT_FORCE: &str = "force";
|
||||
static OPT_INTERACTIVE: &str = "interactive";
|
||||
|
@ -73,12 +69,7 @@ static ARG_FILES: &str = "files";
|
|||
|
||||
#[uucore::main]
|
||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
let help = format!(
|
||||
"{}\n{}",
|
||||
LONG_HELP,
|
||||
backup_control::BACKUP_CONTROL_LONG_HELP
|
||||
);
|
||||
let mut app = uu_app().after_help(help);
|
||||
let mut app = uu_app().after_help(backup_control::BACKUP_CONTROL_LONG_HELP);
|
||||
let matches = app.try_get_matches_from_mut(args)?;
|
||||
|
||||
if !matches.contains_id(OPT_TARGET_DIRECTORY)
|
||||
|
|
10
src/uu/nice/nice.md
Normal file
10
src/uu/nice/nice.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# nice
|
||||
|
||||
```
|
||||
nice [OPTIONS] [COMMAND [ARGS]]
|
||||
```
|
||||
|
||||
Run `COMMAND` with an adjusted niceness, which affects process scheduling.
|
||||
With no `COMMAND`, print the current niceness. Niceness values range from at
|
||||
least -20 (most favorable to the process) to 19 (least favorable to the
|
||||
process).
|
|
@ -15,7 +15,7 @@ use std::ptr;
|
|||
use clap::{crate_version, Arg, ArgAction, Command};
|
||||
use uucore::{
|
||||
error::{set_exit_code, UClapError, UResult, USimpleError, UUsageError},
|
||||
format_usage, show_error,
|
||||
format_usage, help_about, help_usage, show_error,
|
||||
};
|
||||
|
||||
pub mod options {
|
||||
|
@ -23,12 +23,8 @@ pub mod options {
|
|||
pub static COMMAND: &str = "COMMAND";
|
||||
}
|
||||
|
||||
const ABOUT: &str = "\
|
||||
Run COMMAND with an adjusted niceness, which affects process scheduling. \
|
||||
With no COMMAND, print the current niceness. Niceness values range from at \
|
||||
least -20 (most favorable to the process) to 19 (least favorable to the \
|
||||
process).";
|
||||
const USAGE: &str = "{} [OPTIONS] [COMMAND [ARGS]]";
|
||||
const ABOUT: &str = help_about!("nice.md");
|
||||
const USAGE: &str = help_usage!("nice.md");
|
||||
|
||||
fn is_prefix_of(maybe_prefix: &str, target: &str, min_match: usize) -> bool {
|
||||
if maybe_prefix.len() < min_match || maybe_prefix.len() > target.len() {
|
||||
|
|
|
@ -396,7 +396,7 @@ fn test_chown_only_user_id() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-u").run();
|
||||
let result = scene.cmd("id").arg("-u").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ fn test_chown_fail_id() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-u").run();
|
||||
let result = scene.cmd("id").arg("-u").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ fn test_chown_only_group_id() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-g").run();
|
||||
let result = scene.cmd("id").arg("-g").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
|
@ -551,14 +551,14 @@ fn test_chown_owner_group_id() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-u").run();
|
||||
let result = scene.cmd("id").arg("-u").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
let user_id = String::from(result.stdout_str().trim());
|
||||
assert!(!user_id.is_empty());
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-g").run();
|
||||
let result = scene.cmd("id").arg("-g").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
|
@ -612,14 +612,14 @@ fn test_chown_owner_group_mix() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-u").run();
|
||||
let result = scene.cmd("id").arg("-u").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
let user_id = String::from(result.stdout_str().trim());
|
||||
assert!(!user_id.is_empty());
|
||||
|
||||
let result = scene.cmd("id").keep_env().arg("-gn").run();
|
||||
let result = scene.cmd("id").arg("-gn").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ use std::fs as std_fs;
|
|||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[cfg(feature = "truncate")]
|
||||
use crate::common::util::PATH;
|
||||
|
||||
static TEST_EXISTING_FILE: &str = "existing_file.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE: &str = "hello_world.txt";
|
||||
static TEST_HELLO_WORLD_SOURCE_SYMLINK: &str = "hello_world.txt.link";
|
||||
|
@ -1687,7 +1691,7 @@ fn test_cp_reflink_always_override() {
|
|||
|
||||
if !scene
|
||||
.cmd("env")
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.args(&["mkfs.btrfs", "--rootdir", ROOTDIR, DISK])
|
||||
.run()
|
||||
.succeeded()
|
||||
|
@ -1700,7 +1704,7 @@ fn test_cp_reflink_always_override() {
|
|||
|
||||
let mount = scene
|
||||
.cmd("sudo")
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.args(&["-E", "--non-interactive", "mount", DISK, MOUNTPOINT])
|
||||
.run();
|
||||
|
||||
|
@ -1727,7 +1731,7 @@ fn test_cp_reflink_always_override() {
|
|||
|
||||
scene
|
||||
.cmd("sudo")
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.args(&["-E", "--non-interactive", "umount", MOUNTPOINT])
|
||||
.succeeds();
|
||||
}
|
||||
|
|
|
@ -153,11 +153,9 @@ fn test_null_delimiter() {
|
|||
|
||||
#[test]
|
||||
fn test_unset_variable() {
|
||||
// This test depends on the HOME variable being pre-defined by the
|
||||
// default shell
|
||||
let out = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("HOME", "FOO")
|
||||
.arg("-u")
|
||||
.arg("HOME")
|
||||
.succeeds()
|
||||
|
|
|
@ -426,7 +426,6 @@ fn test_mktemp_tmpdir_one_arg() {
|
|||
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("--tmpdir")
|
||||
.arg("apt-key-gpghome.XXXXXXXXXX")
|
||||
.succeeds();
|
||||
|
@ -440,7 +439,6 @@ fn test_mktemp_directory_tmpdir() {
|
|||
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("--directory")
|
||||
.arg("--tmpdir")
|
||||
.arg("apt-key-gpghome.XXXXXXXXXX")
|
||||
|
|
|
@ -21,7 +21,6 @@ fn test_nproc_all_omp() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "60")
|
||||
.succeeds();
|
||||
|
||||
|
@ -30,7 +29,6 @@ fn test_nproc_all_omp() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "1") // Has no effect
|
||||
.arg("--all")
|
||||
.succeeds();
|
||||
|
@ -40,7 +38,6 @@ fn test_nproc_all_omp() {
|
|||
// If the parsing fails, returns the number of CPU
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "incorrectnumber") // returns the number CPU
|
||||
.succeeds();
|
||||
let nproc_omp: u8 = result.stdout_str().trim().parse().unwrap();
|
||||
|
@ -55,7 +52,6 @@ fn test_nproc_ignore() {
|
|||
// Ignore all CPU but one
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("--ignore")
|
||||
.arg((nproc_total - 1).to_string())
|
||||
.succeeds();
|
||||
|
@ -64,7 +60,6 @@ fn test_nproc_ignore() {
|
|||
// Ignore all CPU but one with a string
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("--ignore= 1")
|
||||
.succeeds();
|
||||
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
|
||||
|
@ -76,7 +71,6 @@ fn test_nproc_ignore() {
|
|||
fn test_nproc_ignore_all_omp() {
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "42")
|
||||
.arg("--ignore=40")
|
||||
.succeeds();
|
||||
|
@ -88,7 +82,6 @@ fn test_nproc_ignore_all_omp() {
|
|||
fn test_nproc_omp_limit() {
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "42")
|
||||
.env("OMP_THREAD_LIMIT", "0")
|
||||
.succeeds();
|
||||
|
@ -97,7 +90,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "42")
|
||||
.env("OMP_THREAD_LIMIT", "2")
|
||||
.succeeds();
|
||||
|
@ -106,7 +98,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "42")
|
||||
.env("OMP_THREAD_LIMIT", "2bad")
|
||||
.succeeds();
|
||||
|
@ -119,7 +110,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_THREAD_LIMIT", "1")
|
||||
.succeeds();
|
||||
let nproc: u8 = result.stdout_str().trim().parse().unwrap();
|
||||
|
@ -127,7 +117,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "0")
|
||||
.env("OMP_THREAD_LIMIT", "")
|
||||
.succeeds();
|
||||
|
@ -136,7 +125,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "")
|
||||
.env("OMP_THREAD_LIMIT", "")
|
||||
.succeeds();
|
||||
|
@ -145,7 +133,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "2,2,1")
|
||||
.env("OMP_THREAD_LIMIT", "")
|
||||
.succeeds();
|
||||
|
@ -154,7 +141,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "2,ignored")
|
||||
.env("OMP_THREAD_LIMIT", "")
|
||||
.succeeds();
|
||||
|
@ -163,7 +149,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "2,2,1")
|
||||
.env("OMP_THREAD_LIMIT", "0")
|
||||
.succeeds();
|
||||
|
@ -172,7 +157,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "2,2,1")
|
||||
.env("OMP_THREAD_LIMIT", "1bad")
|
||||
.succeeds();
|
||||
|
@ -181,7 +165,6 @@ fn test_nproc_omp_limit() {
|
|||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("OMP_NUM_THREADS", "29,2,1")
|
||||
.env("OMP_THREAD_LIMIT", "1bad")
|
||||
.succeeds();
|
||||
|
|
|
@ -1,29 +1,21 @@
|
|||
use crate::common::util::TestScenario;
|
||||
use std::env;
|
||||
|
||||
#[test]
|
||||
fn test_get_all() {
|
||||
let key = "KEY";
|
||||
env::set_var(key, "VALUE");
|
||||
assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
||||
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("HOME", "FOO")
|
||||
.env("KEY", "VALUE")
|
||||
.succeeds()
|
||||
.stdout_contains("HOME=")
|
||||
.stdout_contains("HOME=FOO")
|
||||
.stdout_contains("KEY=VALUE");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_var() {
|
||||
let key = "KEY";
|
||||
env::set_var(key, "VALUE");
|
||||
assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
||||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.env("KEY", "VALUE")
|
||||
.arg("KEY")
|
||||
.succeeds();
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ fn test_buffer_sizes() {
|
|||
for buffer_size in &buffer_sizes {
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("-n")
|
||||
.arg("-S")
|
||||
.arg(buffer_size)
|
||||
|
@ -46,7 +45,6 @@ fn test_buffer_sizes() {
|
|||
for buffer_size in &buffer_sizes {
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("-n")
|
||||
.arg("-S")
|
||||
.arg(buffer_size)
|
||||
|
@ -921,7 +919,6 @@ fn test_compress_fail() {
|
|||
#[cfg(not(windows))]
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.args(&[
|
||||
"ext_sort.txt",
|
||||
"-n",
|
||||
|
@ -938,7 +935,6 @@ fn test_compress_fail() {
|
|||
#[cfg(windows)]
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.args(&[
|
||||
"ext_sort.txt",
|
||||
"-n",
|
||||
|
@ -954,7 +950,6 @@ fn test_compress_fail() {
|
|||
fn test_merge_batches() {
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.timeout(Duration::from_secs(120))
|
||||
.args(&["ext_sort.txt", "-n", "-S", "150b"])
|
||||
.succeeds()
|
||||
|
@ -965,7 +960,6 @@ fn test_merge_batches() {
|
|||
fn test_merge_batch_size() {
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.arg("--batch-size=2")
|
||||
.arg("-m")
|
||||
.arg("--unique")
|
||||
|
@ -1074,7 +1068,6 @@ fn test_output_is_input() {
|
|||
at.append("file", input);
|
||||
scene
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.args(&["-m", "-u", "-o", "file", "file", "file", "file"])
|
||||
.succeeds();
|
||||
assert_eq!(at.read("file"), input);
|
||||
|
|
|
@ -11,7 +11,6 @@ fn test_invalid_arg() {
|
|||
fn test_uptime() {
|
||||
TestScenario::new(util_name!())
|
||||
.ucmd()
|
||||
.keep_env()
|
||||
.succeeds()
|
||||
.stdout_contains("load average:")
|
||||
.stdout_contains(" up ");
|
||||
|
|
|
@ -23,7 +23,6 @@ fn test_users_check_name() {
|
|||
#[allow(clippy::needless_borrow)]
|
||||
let expected = TestScenario::new(&util_name)
|
||||
.cmd(util_name)
|
||||
.keep_env()
|
||||
.env("LC_ALL", "C")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
|
|
@ -47,6 +47,7 @@ static MULTIPLE_STDIN_MEANINGLESS: &str = "Ucommand is designed around a typical
|
|||
static NO_STDIN_MEANINGLESS: &str = "Setting this flag has no effect if there is no stdin";
|
||||
|
||||
pub const TESTS_BINARY: &str = env!("CARGO_BIN_EXE_coreutils");
|
||||
pub const PATH: &str = env!("PATH");
|
||||
|
||||
/// Default environment variables to run the commands with
|
||||
const DEFAULT_ENV: [(&str, &str); 2] = [("LC_ALL", "C"), ("TZ", "UTC")];
|
||||
|
@ -1173,14 +1174,12 @@ impl TestScenario {
|
|||
/// * [`UCommand::from_test_scenario`]: Run `coreutils UTIL_NAME` instead of the shell in the
|
||||
/// temporary directory of the [`TestScenario`]
|
||||
/// * [`UCommand::current_dir`]: Sets the working directory
|
||||
/// * [`UCommand::keep_env`]: Keep environment variables instead of clearing them
|
||||
/// * ...
|
||||
#[derive(Debug, Default)]
|
||||
pub struct UCommand {
|
||||
args: VecDeque<OsString>,
|
||||
env_vars: Vec<(OsString, OsString)>,
|
||||
current_dir: Option<PathBuf>,
|
||||
env_clear: bool,
|
||||
bin_path: Option<PathBuf>,
|
||||
util_name: Option<String>,
|
||||
has_run: bool,
|
||||
|
@ -1206,7 +1205,6 @@ impl UCommand {
|
|||
/// temporary directory for safety purposes.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
env_clear: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -1256,12 +1254,6 @@ impl UCommand {
|
|||
self
|
||||
}
|
||||
|
||||
/// Keep the environment variables instead of clearing them before running the command.
|
||||
pub fn keep_env(&mut self) -> &mut Self {
|
||||
self.env_clear = false;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the working directory for this [`UCommand`]
|
||||
///
|
||||
/// Per default the working directory is set to the [`UCommands`] temporary directory.
|
||||
|
@ -1391,7 +1383,6 @@ impl UCommand {
|
|||
/// which this command will be run and `current_dir` will be set to this `temp_dir`.
|
||||
/// * `current_dir`: The temporary directory given by `temp_dir`.
|
||||
/// * `timeout`: `30 seconds`
|
||||
/// * `env_clear`: `true`. (Almost) all environment variables will be cleared.
|
||||
/// * `stdin`: `Stdio::null()`
|
||||
/// * `ignore_stdin_write_error`: `false`
|
||||
/// * `stdout`, `stderr`: If not specified the output will be captured with [`CapturedOutput`]
|
||||
|
@ -1450,22 +1441,20 @@ impl UCommand {
|
|||
self.tmpd = Some(Rc::new(temp_dir));
|
||||
}
|
||||
|
||||
if self.env_clear {
|
||||
command.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"
|
||||
if let Some(systemroot) = env::var_os("SYSTEMROOT") {
|
||||
command.env("SYSTEMROOT", systemroot);
|
||||
}
|
||||
} else {
|
||||
// if someone is setting LD_PRELOAD, there's probably a good reason for it
|
||||
if let Some(ld_preload) = env::var_os("LD_PRELOAD") {
|
||||
command.env("LD_PRELOAD", ld_preload);
|
||||
}
|
||||
command.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"
|
||||
if let Some(systemroot) = env::var_os("SYSTEMROOT") {
|
||||
command.env("SYSTEMROOT", systemroot);
|
||||
}
|
||||
} else {
|
||||
// if someone is setting LD_PRELOAD, there's probably a good reason for it
|
||||
if let Some(ld_preload) = env::var_os("LD_PRELOAD") {
|
||||
command.env("LD_PRELOAD", ld_preload);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2472,7 +2461,7 @@ pub fn expected_result(ts: &TestScenario, args: &[&str]) -> std::result::Result<
|
|||
|
||||
let result = ts
|
||||
.cmd(util_name.as_ref())
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.envs(DEFAULT_ENV)
|
||||
.args(args)
|
||||
.run();
|
||||
|
@ -2547,7 +2536,7 @@ pub fn run_ucmd_as_root(
|
|||
// run ucmd as root:
|
||||
Ok(ts
|
||||
.cmd("sudo")
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.envs(DEFAULT_ENV)
|
||||
.arg("-E")
|
||||
.arg("--non-interactive")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue