Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Jan 30, 2025
1 parent 9ffafe5 commit 8c9f0d1
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: tests
on:
push:
branches: [main]
branches: [main, test]
pull_request: {}
env:
RUST_BACKTRACE: 1
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn main() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("tac")
// .args(&["500"])
.spawn(pts)
.spawn(&pts)
.unwrap();

main::run(&mut child, &mut pty);
Expand Down
2 changes: 1 addition & 1 deletion examples/interhack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async fn main() {

let (mut pty, pts) = pty_process::open().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("nethack").spawn(pts).unwrap();
let mut child = pty_process::Command::new("nethack").spawn(&pts).unwrap();
main::run(&mut child, &mut pty).await.unwrap();
let status = child.wait().await.unwrap();
std::process::exit(
Expand Down
2 changes: 1 addition & 1 deletion examples/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("tac")
// .args(&["500"])
.spawn(pts)
.spawn(&pts)
.unwrap();
main::run(&mut child, &mut pty).await.unwrap();
let status = child.wait().await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/blocking/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ impl Command {
#[allow(clippy::needless_pass_by_value)]
pub fn spawn(
mut self,
pts: crate::blocking::Pts,
pts: &crate::blocking::Pts,
) -> crate::Result<std::process::Child> {
self.spawn_impl(&pts)
self.spawn_impl(pts)
}

/// Executes the command as a child process via
Expand Down
4 changes: 2 additions & 2 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ impl Command {
#[allow(clippy::needless_pass_by_value)]
pub fn spawn(
mut self,
pts: crate::Pts,
pts: &crate::Pts,
) -> crate::Result<tokio::process::Child> {
self.spawn_impl(&pts)
self.spawn_impl(pts)
}

/// Executes the command as a child process via
Expand Down
6 changes: 3 additions & 3 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn test_cat_blocking() {
let (mut pty, pts) = pty_process::blocking::open().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("cat")
.spawn(pts)
.spawn(&pts)
.unwrap();

pty.write_all(b"foo\n").unwrap();
Expand All @@ -29,7 +29,7 @@ async fn test_cat_async() {

let (mut pty, pts) = pty_process::open().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("cat").spawn(pts).unwrap();
let mut child = pty_process::Command::new("cat").spawn(&pts).unwrap();

let (pty_r, mut pty_w) = pty.split();

Expand All @@ -51,7 +51,7 @@ async fn test_yes_async() {

let (mut pty, pts) = pty_process::open().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("yes").spawn(pts).unwrap();
let mut child = pty_process::Command::new("yes").spawn(&pts).unwrap();

let mut buf = [0u8; 3];

Expand Down
8 changes: 4 additions & 4 deletions tests/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn test_controlling_terminal() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("perl")
.arg("-Eopen my $fh, '<', '/dev/tty' or die; if (-t $fh) { say 'true' } else { say 'false' }")
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output(&pty);
Expand All @@ -252,7 +252,7 @@ async fn test_controlling_terminal_async() {
"-Eopen my $fh, '<', '/dev/tty' or die; \
if (-t $fh) { say 'true' } else { say 'false' }",
)
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output_async(pty_r);
Expand All @@ -268,7 +268,7 @@ fn test_session_leader() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("python")
.arg("-cimport os; print(os.getpid() == os.getsid(0))")
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output(&pty);
Expand All @@ -287,7 +287,7 @@ async fn test_session_leader_async() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::Command::new("python")
.arg("-cimport os; print(os.getpid() == os.getsid(0))")
.spawn(pts)
.spawn(&pts)
.unwrap();

let (pty_r, _) = pty.split();
Expand Down
6 changes: 4 additions & 2 deletions tests/fds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test_fds() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("perl")
.arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say")
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output(&pty);
Expand All @@ -20,14 +20,15 @@ fn test_fds() {
let status = child.wait().unwrap();
assert_eq!(status.code().unwrap(), 0);
drop(pty);
drop(pts);
check_open_fds(Some(&fds));

let (pty, pts) = pty_process::blocking::open().unwrap();
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let mut child = pty_process::blocking::Command::new("perl")
.arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say")
.stderr(std::process::Stdio::null())
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output(&pty);
Expand All @@ -36,6 +37,7 @@ fn test_fds() {
let status = child.wait().unwrap();
assert_eq!(status.code().unwrap(), 0);
drop(pty);
drop(pts);
check_open_fds(Some(&fds));
}

Expand Down
8 changes: 5 additions & 3 deletions tests/fds_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn test_fds_async() {
}; \
say",
)
.spawn(pts)
.spawn(&pts)
.unwrap();

let (pty_r, _) = pty.split();
Expand All @@ -52,7 +52,7 @@ fn test_fds_async() {
}; \
say",
)
.spawn(pts)
.spawn(&pts)
.unwrap();

let (pty_r, _) = pty.split();
Expand All @@ -63,6 +63,7 @@ fn test_fds_async() {
assert_eq!(status.code().unwrap(), 0);
drop(output);
drop(pty);
drop(pts);

check_open_fds(&fds);
});
Expand All @@ -75,7 +76,7 @@ fn test_fds_async() {
let mut child = pty_process::Command::new("perl")
.arg("-Efor my $fd (0..255) { open my $fh, \"<&=$fd\"; print $fd if stat $fh }; say")
.stderr(std::process::Stdio::null())
.spawn(pts)
.spawn(&pts)
.unwrap();

let (pty_r, _) = pty.split();
Expand All @@ -86,6 +87,7 @@ fn test_fds_async() {
assert_eq!(status.code().unwrap(), 0);
drop(output);
drop(pty);
drop(pts);

check_open_fds(&fds);
});
Expand Down
8 changes: 4 additions & 4 deletions tests/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ fn test_pipe_blocking() {
let cmd_from = pty_process::blocking::Command::new("seq")
.args(["1", "10"])
.stdout(std::process::Stdio::from(write_fd));
let mut child_from = cmd_from.spawn(pts_from).unwrap();
let mut child_from = cmd_from.spawn(&pts_from).unwrap();

let (mut pty_to, pts_to) = pty_process::blocking::open().unwrap();
let cmd_to = pty_process::blocking::Command::new("sh")
.args(["-c", TAC])
.stdin(std::process::Stdio::from(read_fd));
let mut child_to = cmd_to.spawn(pts_to).unwrap();
let mut child_to = cmd_to.spawn(&pts_to).unwrap();

assert!(child_from.wait().unwrap().success());

Expand Down Expand Up @@ -70,13 +70,13 @@ async fn test_pipe_async() {
let cmd_from = pty_process::Command::new("seq")
.args(["1", "10"])
.stdout(std::process::Stdio::from(write_fd));
let mut child_from = cmd_from.spawn(pts_from).unwrap();
let mut child_from = cmd_from.spawn(&pts_from).unwrap();

let (mut pty_to, pts_to) = pty_process::open().unwrap();
let cmd_to = pty_process::Command::new("sh")
.args(["-c", TAC])
.stdin(std::process::Stdio::from(read_fd));
let mut child_to = cmd_to.spawn(pts_to).unwrap();
let mut child_to = cmd_to.spawn(&pts_to).unwrap();

assert!(child_from.wait().await.unwrap().success());

Expand Down
4 changes: 2 additions & 2 deletions tests/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn test_split() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let cmd = pty_process::Command::new("perl")
.args(["-plE", "BEGIN { $SIG{WINCH} = sub { say 'WINCH' } }"]);
let mut child = cmd.spawn(pts).unwrap();
let mut child = cmd.spawn(&pts).unwrap();

{
pty.write_all(b"foo\n").await.unwrap();
Expand Down Expand Up @@ -48,7 +48,7 @@ async fn test_into_split() {
pty.resize(pty_process::Size::new(24, 80)).unwrap();
let cmd = pty_process::Command::new("perl")
.args(["-plE", "BEGIN { $SIG{WINCH} = sub { say 'WINCH' } }"]);
let mut child = cmd.spawn(pts).unwrap();
let mut child = cmd.spawn(&pts).unwrap();

{
pty.write_all(b"foo\n").await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tests/winch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn test_winch_std() {
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
.spawn(pts)
.spawn(&pts)
.unwrap();

let mut output = helpers::output(&pty);
Expand All @@ -38,7 +38,7 @@ async fn test_winch_async() {
"-E",
"$|++; $SIG{WINCH} = sub { say 'WINCH' }; say 'started'; <>",
])
.spawn(pts)
.spawn(&pts)
.unwrap();

let (pty_r, mut pty_w) = pty.split();
Expand Down

0 comments on commit 8c9f0d1

Please sign in to comment.