Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/testdata/testterminal18153/terminal_test.go

Documentation: cmd/go/testdata/testterminal18153

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

View as plain text