...
1
2
3
4
5 package term_test
6
7 import (
8 "os"
9 "runtime"
10 "testing"
11
12 "golang.org/x/term"
13 )
14
15 func TestIsTerminalTempFile(t *testing.T) {
16 file, err := os.CreateTemp("", "TestIsTerminalTempFile")
17 if err != nil {
18 t.Fatal(err)
19 }
20 defer os.Remove(file.Name())
21 defer file.Close()
22
23 if term.IsTerminal(int(file.Fd())) {
24 t.Fatalf("IsTerminal unexpectedly returned true for temporary file %s", file.Name())
25 }
26 }
27
28 func TestIsTerminalTerm(t *testing.T) {
29 if runtime.GOOS != "linux" {
30 t.Skipf("unknown terminal path for GOOS %v", runtime.GOOS)
31 }
32 file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
33 if err != nil {
34 t.Fatal(err)
35 }
36 defer file.Close()
37
38 if !term.IsTerminal(int(file.Fd())) {
39 t.Fatalf("IsTerminal unexpectedly returned false for terminal file %s", file.Name())
40 }
41 }
42
View as plain text