1// Copyright 2019 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package term_test 6 7import ( 8 "io/ioutil" 9 "os" 10 "runtime" 11 "testing" 12 13 "golang.org/x/term" 14) 15 16func TestIsTerminalTempFile(t *testing.T) { 17 file, err := ioutil.TempFile("", "TestIsTerminalTempFile") 18 if err != nil { 19 t.Fatal(err) 20 } 21 defer os.Remove(file.Name()) 22 defer file.Close() 23 24 if term.IsTerminal(int(file.Fd())) { 25 t.Fatalf("IsTerminal unexpectedly returned true for temporary file %s", file.Name()) 26 } 27} 28 29func TestIsTerminalTerm(t *testing.T) { 30 if runtime.GOOS != "linux" { 31 t.Skipf("unknown terminal path for GOOS %v", runtime.GOOS) 32 } 33 file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0) 34 if err != nil { 35 t.Fatal(err) 36 } 37 defer file.Close() 38 39 if !term.IsTerminal(int(file.Fd())) { 40 t.Fatalf("IsTerminal unexpectedly returned false for terminal file %s", file.Name()) 41 } 42} 43