...

Source file src/golang.org/x/term/term_test.go

Documentation: golang.org/x/term

     1  // Copyright 2019 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  package term_test
     6  
     7  import (
     8  	"os"
     9  	"runtime"
    10  	"testing"
    11  
    12  	"golang.org/x/term"
    13  )
    14  
    15  func TestIsTerminalTempFile(t *testing.T) {
    16  	file, err := os.CreateTemp("", "TestIsTerminalTempFile")
    17  	if err != nil {
    18  		t.Fatal(err)
    19  	}
    20  	defer os.Remove(file.Name())
    21  	defer file.Close()
    22  
    23  	if term.IsTerminal(int(file.Fd())) {
    24  		t.Fatalf("IsTerminal unexpectedly returned true for temporary file %s", file.Name())
    25  	}
    26  }
    27  
    28  func TestIsTerminalTerm(t *testing.T) {
    29  	if runtime.GOOS != "linux" {
    30  		t.Skipf("unknown terminal path for GOOS %v", runtime.GOOS)
    31  	}
    32  	file, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	defer file.Close()
    37  
    38  	if !term.IsTerminal(int(file.Fd())) {
    39  		t.Fatalf("IsTerminal unexpectedly returned false for terminal file %s", file.Name())
    40  	}
    41  }
    42  

View as plain text