1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Debian runs tests with stdin/stdout/stderr not connected to terminals, so testing against
the users terminal doesn't work, we instead create a pseudo terminal specifically to use
for testing.
--- a/src/unix.rs
+++ b/src/unix.rs
@@ -60,6 +60,31 @@
fn compare_with_stty() {
use std::process::Command;
use std::process::Stdio;
+ use std::os::fd::OwnedFd;
+ use std::os::fd::FromRawFd;
+
+ //in debian the tests run without a terminal, create one for testing
+ let slavename;
+ let slavefd;
+ use libc::{posix_openpt,O_RDWR,O_NOCTTY,grantpt,unlockpt,ptsname_r,winsize,ioctl,TIOCSWINSZ,open,c_char};
+ let mut slavenamearr:[c_char;1024] = [0;1024];
+ unsafe {
+ use std::ffi::CStr;
+ let masterfd = posix_openpt(O_RDWR | O_NOCTTY);
+ if masterfd < 0 {panic!("posix_openpt failed");}
+ if grantpt(masterfd) < 0 {panic!("grantpt failed");}
+ if unlockpt(masterfd) < 0 {panic!("unlockpt failed");}
+ if ptsname_r(masterfd,slavenamearr.as_mut_ptr(),1024) != 0 {panic!("ptsname_r failed");}
+ slavename = CStr::from_ptr(slavenamearr.as_mut_ptr()).to_str().unwrap();
+ let ws = winsize {
+ ws_row: 123,
+ ws_col: 456,
+ ws_xpixel: 0,
+ ws_ypixel: 0,
+ };
+ if ioctl(masterfd,TIOCSWINSZ,&ws) != 0 {panic!("TIOCSWINSZ failed")}
+ slavefd = OwnedFd::from_raw_fd(open(slavenamearr.as_mut_ptr(), O_RDWR|O_NOCTTY));
+ }
let (rows, cols) = if cfg!(target_os = "illumos") {
// illumos stty(1) does not accept a device argument, instead using
@@ -96,14 +121,14 @@
Command::new("stty")
.arg("size")
.arg("-F")
- .arg("/dev/stderr")
+ .arg(slavename)
.stderr(Stdio::inherit())
.output()
.unwrap()
} else {
Command::new("stty")
.arg("-f")
- .arg("/dev/stderr")
+ .arg(slavename)
.arg("size")
.stderr(Stdio::inherit())
.output()
@@ -121,7 +146,7 @@
};
println!("{} {}", rows, cols);
- if let Some((Width(w), Height(h))) = terminal_size() {
+ if let Some((Width(w), Height(h))) = terminal_size_of(slavefd) {
assert_eq!(rows, h);
assert_eq!(cols, w);
} else {
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,6 +46,9 @@
version = "1.0.1"
features = ["termios"]
+[target."cfg(not(windows))".dev-dependencies.libc]
+version = "0.2"
+
[target."cfg(windows)".dependencies.windows-sys]
version = "0.59.0"
features = [
|