1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix: Deno.setRaw shouldn't panic on ENOTTY (#6630)

This commit is contained in:
uki00a 2020-07-07 07:26:34 +09:00 committed by GitHub
parent 2b52e3daf1
commit ab4c574f52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -319,6 +319,7 @@ impl From<nix::Error> for OpError {
nix::Error::Sys(EPERM) => ErrorKind::PermissionDenied,
nix::Error::Sys(EINVAL) => ErrorKind::TypeError,
nix::Error::Sys(ENOENT) => ErrorKind::NotFound,
nix::Error::Sys(ENOTTY) => ErrorKind::BadResource,
nix::Error::Sys(UnknownErrno) => unreachable!(),
nix::Error::Sys(_) => unreachable!(),
nix::Error::InvalidPath => ErrorKind::TypeError,

View file

@ -3063,3 +3063,23 @@ fn exec_path() {
let expected = std::fs::canonicalize(util::deno_exe_path()).unwrap();
assert_eq!(expected, actual);
}
#[cfg(not(windows))]
#[test]
fn set_raw_should_not_panic_on_no_tty() {
let output = util::deno_cmd()
.arg("eval")
.arg("--unstable")
.arg("Deno.setRaw(Deno.stdin.rid, true)")
// stdin set to piped so it certainly does not refer to TTY
.stdin(std::process::Stdio::piped())
// stderr is piped so we can capture output.
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap()
.wait_with_output()
.unwrap();
assert!(!output.status.success());
let stderr = std::str::from_utf8(&output.stderr).unwrap().trim();
assert!(stderr.contains("BadResource"));
}