Skip to content

Commit 9003e3f

Browse files
authored
Merge pull request #5869 from cre4ture/feature/simulate_terminal_utility
test utilities: easy way to simulate terminal context
2 parents 09048a3 + d8b3b41 commit 9003e3f

File tree

5 files changed

+390
-30
lines changed

5 files changed

+390
-30
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ procfs = { version = "0.16", default-features = false }
498498
rlimit = "0.10.1"
499499

500500
[target.'cfg(unix)'.dev-dependencies]
501-
nix = { workspace = true, features = ["process", "signal", "user"] }
501+
nix = { workspace = true, features = ["process", "signal", "user", "term"] }
502502
rand_pcg = "0.3"
503503
xattr = { workspace = true }
504504

tests/by-util/test_nohup.rs

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
5+
// spell-checker:ignore winsize Openpty openpty xpixel ypixel ptyprocess
56
use crate::common::util::TestScenario;
67
use std::thread::sleep;
78

@@ -31,3 +32,32 @@ fn test_nohup_multiple_args_and_flags() {
3132
assert!(at.file_exists("file1"));
3233
assert!(at.file_exists("file2"));
3334
}
35+
36+
#[test]
37+
#[cfg(any(
38+
target_os = "linux",
39+
target_os = "android",
40+
target_os = "freebsd",
41+
target_vendor = "apple"
42+
))]
43+
fn test_nohup_with_pseudo_terminal_emulation_on_stdin_stdout_stderr_get_replaced() {
44+
let ts = TestScenario::new(util_name!());
45+
let result = ts
46+
.ucmd()
47+
.terminal_simulation(true)
48+
.args(&["sh", "is_atty.sh"])
49+
.succeeds();
50+
51+
assert_eq!(
52+
String::from_utf8_lossy(result.stderr()).trim(),
53+
"nohup: ignoring input and appending output to 'nohup.out'"
54+
);
55+
56+
sleep(std::time::Duration::from_millis(10));
57+
58+
// this proves that nohup was exchanging the stdio file descriptors
59+
assert_eq!(
60+
std::fs::read_to_string(ts.fixtures.plus_as_string("nohup.out")).unwrap(),
61+
"stdin is not atty\nstdout is not atty\nstderr is not atty\n"
62+
);
63+
}

0 commit comments

Comments
 (0)