-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathttyutils_test.go
55 lines (45 loc) · 974 Bytes
/
ttyutils_test.go
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
package ttyutils_test
import (
"os"
"reflect"
"testing"
"github.com/burke/ttyutils"
"github.com/kr/pty"
)
func TestIsTerminal(t *testing.T) {
mpty, mtty, err := pty.Open()
if err != nil {
t.Fatal(err)
}
defer mtty.Close()
defer mpty.Close()
if !ttyutils.IsTerminal(mtty.Fd()) {
t.Error("tty should be reported as a terminal")
}
if !ttyutils.IsTerminal(mpty.Fd()) {
t.Error("pty should be reported as a terminal")
}
null, err := os.Open(os.DevNull)
if err != nil {
t.Fatal(err)
}
defer null.Close()
if ttyutils.IsTerminal(null.Fd()) {
t.Error("/dev/null should not be reported as a terminal")
}
}
func TestWinSize(t *testing.T) {
mpty, mtty, err := pty.Open()
if err != nil {
t.Fatal(err)
}
defer mtty.Close()
defer mpty.Close()
size, err := ttyutils.Winsize(mtty)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(size, ttyutils.Ttysize{Lines: 0, Columns: 0}) {
t.Errorf("expected 0x0 terminal, got %#v", size)
}
}