pmap: implemented rc options (#456)

* pmap: implemented rc options

* pmap: added tests for rc options

* fixed lint errors

* pmap: updated test_default_rc to run only in CI

* Update src/uu/pmap/src/pmap.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Update src/uu/pmap/src/pmap.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
estodi
2025-07-03 07:08:41 -07:00
committed by GitHub
parent bc6811964c
commit e6261faad1
5 changed files with 274 additions and 11 deletions
+72
View File
@@ -20,6 +20,78 @@ fn test_no_args() {
new_ucmd!().fails().code_is(1);
}
#[test]
#[cfg(target_os = "linux")]
fn test_default_rc() {
if !uutests::util::is_ci() {
return;
}
let pid = process::id();
let ts = TestScenario::new(util_name!());
// Fails to read before creating rc file
for arg in ["-c", "--read-rc"] {
ts.ucmd().arg(arg).arg(pid.to_string()).fails().code_is(1);
}
// Create rc file
ts.ucmd().arg("-n").succeeds();
// Fails to create because rc file already exists
for arg in ["-n", "--create-rc"] {
ts.ucmd().arg(arg).fails().code_is(1);
}
// Succeeds to read now
for arg in ["-c", "--read-rc"] {
ts.ucmd().arg(arg).arg(pid.to_string()).succeeds();
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_create_rc_to() {
let ts = TestScenario::new(util_name!());
ts.ucmd().args(&["-N", "pmap_rc_file_name"]).succeeds();
// Fails to create because rc file already exists
for arg in ["-N", "--create-rc-to"] {
ts.ucmd()
.args(&[arg, "pmap_rc_file_name"])
.fails()
.code_is(1);
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_read_rc_from() {
let pid = process::id();
let ts = TestScenario::new(util_name!());
// Fails to read before creating rc file
for arg in ["-C", "--read-rc-from"] {
ts.ucmd()
.args(&[arg, "pmap_rc_file_name"])
.arg(pid.to_string())
.fails()
.code_is(1);
}
// Create rc file
ts.ucmd().args(&["-N", "pmap_rc_file_name"]).succeeds();
// Succeeds to read now
for arg in ["-C", "--read-rc-from"] {
ts.ucmd()
.args(&[arg, "pmap_rc_file_name"])
.arg(pid.to_string())
.succeeds();
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_existing_pid() {