File: term_test.go

package info (click to toggle)
golang-github-pkg-term 0.0~git20181116.27bbf2e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 200 kB
  • sloc: makefile: 2
file content (95 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package term

import (
	"testing"

	"github.com/pkg/term/termios"
	"time"
)

// assert that Term implements the same method set across
// all supported platforms
var _ interface {
	Available() (int, error)
	Buffered() (int, error)
	Close() error
	DTR() (bool, error)
	Flush() error
	RTS() (bool, error)
	Read(b []byte) (int, error)
	Restore() error
	SendBreak() error
	SetCbreak() error
	SetDTR(v bool) error
	SetOption(options ...func(*Term) error) error
	SetRTS(v bool) error
	SetRaw() error
	SetSpeed(baud int) error
	Write(b []byte) (int, error)
} = new(Term)

func TestTermSetCbreak(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()
	if err := tt.SetCbreak(); err != nil {
		t.Fatal(err)
	}
}

func TestTermSetRaw(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()
	if err := tt.SetRaw(); err != nil {
		t.Fatal(err)
	}
}

func TestTermSetSpeed(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()
	if err := tt.SetSpeed(57600); err != nil {
		t.Fatal(err)
	}
}

func TestTermSetReadTimeout(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()
	if err := tt.SetReadTimeout(1 * time.Second); err != nil {
		t.Fatal(err)
	}
}

func TestTermSetFlowControl(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()

	kinds := []int{XONXOFF, NONE, HARDWARE, NONE, XONXOFF, HARDWARE, NONE}

	for _, kind := range kinds {
		if err := tt.SetFlowControl(kind); err != nil {
			t.Fatal(err)
		}
	}
}

func TestTermRestore(t *testing.T) {
	tt := opendev(t)
	defer tt.Close()
	if err := tt.Restore(); err != nil {
		t.Fatal(err)
	}
}

func opendev(t *testing.T) *Term {
	_, pts, err := termios.Pty()
	if err != nil {
		t.Fatal(err)
	}
	term, err := Open(pts.Name())
	if err != nil {
		t.Fatal(err)
	}
	pts.Close()
	return term
}