mirror of
https://github.com/golang/term.git
synced 2026-02-08 03:36:04 +03:00
Extracted from golang.org/x/crypto/ssh/terminal The implementation for plan9 is based on IsTerminal from github.com/mattn/go-isatty Change-Id: Id7bf2d6595639ff08e5fd5f786a145d340bbed08 Reviewed-on: https://go-review.googlesource.com/c/term/+/200681 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
43 lines
881 B
Go
43 lines
881 B
Go
// 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 (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"golang.org/x/sys/unix"
|
|
"golang.org/x/term"
|
|
)
|
|
|
|
func TestIsTerminalTerm(t *testing.T) {
|
|
|
|
dir, err := ioutil.TempDir("", "TestIsTerminalTerm")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
|
|
tty := filepath.Join(dir, "tty")
|
|
err = unix.Mknod(tty, unix.S_IFCHR, int(unix.Mkdev(5, 0)))
|
|
if err == unix.EPERM {
|
|
t.Skip("no permission to create terminal file, skipping test")
|
|
} else if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
file, err := os.Open(tty)
|
|
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())
|
|
}
|
|
}
|