2019-10-14 12:17:45 +03:00
|
|
|
// Copyright 2019 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package term_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2020-09-29 20:32:40 +03:00
|
|
|
"runtime"
|
2019-10-14 12:17:45 +03:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"golang.org/x/term"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIsTerminalTempFile(t *testing.T) {
|
2022-09-16 10:32:46 +03:00
|
|
|
file, err := os.CreateTemp("", "TestIsTerminalTempFile")
|
2019-10-14 12:17:45 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
if term.IsTerminal(int(file.Fd())) {
|
|
|
|
t.Fatalf("IsTerminal unexpectedly returned true for temporary file %s", file.Name())
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 20:32:40 +03:00
|
|
|
|
|
|
|
func TestIsTerminalTerm(t *testing.T) {
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
t.Skipf("unknown terminal path for GOOS %v", runtime.GOOS)
|
|
|
|
}
|
|
|
|
file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
if !term.IsTerminal(int(file.Fd())) {
|
|
|
|
t.Fatalf("IsTerminal unexpectedly returned false for terminal file %s", file.Name())
|
|
|
|
}
|
|
|
|
}
|