mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Remove keep_env
from the test framework
This commit is contained in:
parent
cc77a952f5
commit
81a4e8fb7d
10 changed files with 36 additions and 81 deletions
|
@ -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");
|
||||
|
||||
/// Test if the program is running under CI
|
||||
pub fn is_ci() -> bool {
|
||||
|
@ -1170,14 +1171,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,
|
||||
|
@ -1203,7 +1202,6 @@ impl UCommand {
|
|||
/// temporary directory for safety purposes.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
env_clear: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
@ -1253,12 +1251,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.
|
||||
|
@ -1376,7 +1368,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`]
|
||||
|
@ -1435,7 +1426,6 @@ impl UCommand {
|
|||
self.tmpd = Some(Rc::new(temp_dir));
|
||||
}
|
||||
|
||||
if self.env_clear {
|
||||
command.env_clear();
|
||||
if cfg!(windows) {
|
||||
// spell-checker:ignore (dll) rsaenh
|
||||
|
@ -1452,7 +1442,6 @@ impl UCommand {
|
|||
command.env("LD_PRELOAD", ld_preload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
command.envs(self.env_vars.iter().cloned());
|
||||
|
||||
|
@ -2455,7 +2444,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)
|
||||
.env("LC_ALL", "C")
|
||||
.args(args)
|
||||
.run();
|
||||
|
@ -2530,7 +2519,7 @@ pub fn run_ucmd_as_root(
|
|||
// run ucmd as root:
|
||||
Ok(ts
|
||||
.cmd("sudo")
|
||||
.keep_env()
|
||||
.env("PATH", PATH)
|
||||
.env("LC_ALL", "C")
|
||||
.arg("-E")
|
||||
.arg("--non-interactive")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue