Source file src/cmd/go/testdata/testterminal18153/terminal_test.go
1 // Copyright 2016 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 5 //go:build linux 6 // +build linux 7 8 // This test is run by src/cmd/dist/test.go (cmd_go_test_terminal), 9 // and not by cmd/go's tests. This is because this test requires 10 // that it be called with its stdout and stderr being a terminal. 11 // dist doesn't run `cmd/go test` against this test directory if 12 // dist's stdout/stderr aren't terminals. 13 // 14 // See issue 18153. 15 16 package p 17 18 import ( 19 "syscall" 20 "testing" 21 "unsafe" 22 ) 23 24 const ioctlReadTermios = syscall.TCGETS 25 26 // isTerminal reports whether fd is a terminal. 27 func isTerminal(fd uintptr) bool { 28 var termios syscall.Termios 29 _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0) 30 return err == 0 31 } 32 33 func TestIsTerminal(t *testing.T) { 34 if !isTerminal(1) { 35 t.Errorf("stdout is not a terminal") 36 } 37 if !isTerminal(2) { 38 t.Errorf("stderr is not a terminal") 39 } 40 } 41