term: use pseudo terminal in TestIsTerminalTerm on linux

Use /dev/ptmx to create a new pseudo terminal and use this in
TestIsTerminalTerm.

This should fix the test failing with ENXIO on some linux builders.

Change-Id: I39880d2cb538e3e9c8063ac79b5380ed00a476f5
Reviewed-on: https://go-review.googlesource.com/c/term/+/201417
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tobias Klauser
2019-10-16 13:13:44 +02:00
committed by Tobias Klauser
parent f887077f25
commit 159e5304a9

View File

@@ -5,32 +5,14 @@
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)
file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
if err != nil {
t.Fatal(err)
}