Skip to content

Commit

Permalink
Merge pull request #5869 from cre4ture/feature/simulate_terminal_utility
Browse files Browse the repository at this point in the history
test utilities: easy way to simulate terminal context
  • Loading branch information
sylvestre committed Mar 1, 2024
2 parents 09048a3 + d8b3b41 commit 9003e3f
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ procfs = { version = "0.16", default-features = false }
rlimit = "0.10.1"

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

Expand Down
30 changes: 30 additions & 0 deletions tests/by-util/test_nohup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore winsize Openpty openpty xpixel ypixel ptyprocess
use crate::common::util::TestScenario;
use std::thread::sleep;

Expand Down Expand Up @@ -31,3 +32,32 @@ fn test_nohup_multiple_args_and_flags() {
assert!(at.file_exists("file1"));
assert!(at.file_exists("file2"));
}

#[test]
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_vendor = "apple"
))]
fn test_nohup_with_pseudo_terminal_emulation_on_stdin_stdout_stderr_get_replaced() {
let ts = TestScenario::new(util_name!());
let result = ts
.ucmd()
.terminal_simulation(true)
.args(&["sh", "is_atty.sh"])
.succeeds();

assert_eq!(
String::from_utf8_lossy(result.stderr()).trim(),
"nohup: ignoring input and appending output to 'nohup.out'"
);

sleep(std::time::Duration::from_millis(10));

// this proves that nohup was exchanging the stdio file descriptors
assert_eq!(
std::fs::read_to_string(ts.fixtures.plus_as_string("nohup.out")).unwrap(),
"stdin is not atty\nstdout is not atty\nstderr is not atty\n"
);
}
Loading

0 comments on commit 9003e3f

Please sign in to comment.