30eee88d95
/dev/null is a character device, and so is the /dev/null the Go runtime reopens onto a closed fd 1, so a bare invocation printed help and exited zero for both -- the two shapes a machine caller is most likely to hand the binary.
26 lines
608 B
Go
26 lines
608 B
Go
//go:build linux
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
"testing"
|
|
)
|
|
|
|
// The help-and-exit-zero branch is the whole point of the gate, and no CI
|
|
// container has a controlling terminal to reach it through /dev/tty. A pty
|
|
// allocated from /dev/ptmx is a real terminal, so the true branch is pinned
|
|
// here instead of skipped.
|
|
func TestIsTerminalDetectsAPTY(t *testing.T) {
|
|
pty, err := os.OpenFile("/dev/ptmx", syscall.O_RDWR|syscall.O_NOCTTY, 0)
|
|
if err != nil {
|
|
t.Fatalf("open /dev/ptmx: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = pty.Close() })
|
|
|
|
if !isTerminal(pty) {
|
|
t.Error("a pty is a terminal")
|
|
}
|
|
}
|