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