forked from rwxrob/bonzai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
term_test.go
43 lines (37 loc) · 889 Bytes
/
term_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2022 Robert S. Muhlestein
// SPDX-License-Identifier: Apache-2.0
package term
import "fmt"
// coverage will never catch this test
/*
func TestIsInteractive_false(t *testing.T) {
if os.Getenv("TEST_ISNOTTERM") == "1" {
fmt.Println("out")
if !IsInteractive() {
os.Exit(20)
}
os.Exit(1)
}
exe := os.Args[0]
cmd := exec.Command(exe, "-test.run=TestIsInteractive_false")
cmd.Env = append(os.Environ(), "TEST_ISNOTTERM=1")
cmd.StdoutPipe() // just enough to push into background
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok {
t.Log(e.ExitCode())
if e.ExitCode() != 20 {
t.Errorf("exit %v: still a terminal", e.ExitCode())
}
}
}
func TestIsInteractive_true(t *testing.T) {
if !IsInteractive() {
t.Error("terminal not connected")
}
}
*/
func ExampleIsInteractive() {
if !IsInteractive() {
fmt.Println("terminal not connected")
}
}