Skip to content

Commit

Permalink
fix test_raw_tty hang (denoland#8520)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored Nov 27, 2020
1 parent 22f951a commit 29374db
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
40 changes: 39 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ chrono = "0.4.15"
os_pipe = "0.9.2"
test_util = { path = "../test_util" }

[target.'cfg(unix)'.dev-dependencies]
exec = "0.3.1" # Used in test_raw_tty

[package.metadata.winres]
# This section defines the metadata that appears in the deno.exe PE header.
OriginalFilename = "deno.exe"
Expand Down
23 changes: 10 additions & 13 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ fn no_color() {
pub fn test_raw_tty() {
use std::io::{Read, Write};
use util::pty::fork::*;

let deno_exe = util::deno_exe_path();
let deno_dir = TempDir::new().expect("tempdir fail");
let root_path = util::root_path();
let fork = Fork::from_ptmx().unwrap();

if let Ok(mut master) = fork.is_parent() {
Expand All @@ -193,31 +194,27 @@ pub fn test_raw_tty() {
master.write_all(b"c").unwrap();
nread = master.read(&mut obytes).unwrap();
assert_eq!(String::from_utf8_lossy(&obytes[0..nread]), "C");
fork.wait().unwrap();
} else {
use nix::sys::termios;
use std::os::unix::io::AsRawFd;
use std::process::*;

// Turn off echo such that parent is reading works properly.
let stdin_fd = std::io::stdin().as_raw_fd();
let mut t = termios::tcgetattr(stdin_fd).unwrap();
t.local_flags.remove(termios::LocalFlags::ECHO);
termios::tcsetattr(stdin_fd, termios::SetArg::TCSANOW, &t).unwrap();

let mut child = Command::new(deno_exe)
.env("DENO_DIR", deno_dir.path())
.current_dir(util::root_path())
std::env::set_current_dir(root_path).unwrap();
let err = exec::Command::new(deno_exe)
.arg("run")
.arg("--unstable")
.arg("--quiet")
.arg("--no-check")
.arg("cli/tests/raw_mode.ts")
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
// Warning: errors may be swallowed. Try to comment stderr null if
// experiencing problems.
.stderr(Stdio::null())
.spawn()
.expect("Failed to spawn script");
child.wait().unwrap();
.exec();
println!("err {}", err);
unreachable!()
}
}

Expand Down

0 comments on commit 29374db

Please sign in to comment.