-
Notifications
You must be signed in to change notification settings - Fork 289
/
test.go
48 lines (40 loc) · 1002 Bytes
/
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
44
45
46
47
48
package shell
import (
"io"
"os"
"runtime"
"testing"
"github.com/buildkite/agent/v3/env"
)
// NewTestShell creates a minimal shell suitable for tests.
func NewTestShell(t *testing.T) *Shell {
t.Helper()
sh, err := New()
if err != nil {
t.Fatalf("shell.New() error = %v", err)
}
sh.Logger = DiscardLogger
sh.Writer = io.Discard
if os.Getenv(`DEBUG_SHELL`) == "1" {
sh.Logger = TestingLogger{T: t}
sh.Writer = os.Stdout
}
// Windows requires certain env variables to be present
if runtime.GOOS == "windows" {
sh.Env = env.FromMap(map[string]string{
"PATH": os.Getenv("PATH"),
"SystemRoot": os.Getenv("SystemRoot"),
"WINDIR": os.Getenv("WINDIR"),
"COMSPEC": os.Getenv("COMSPEC"),
"PATHEXT": os.Getenv("PATHEXT"),
"TMP": os.Getenv("TMP"),
"TEMP": os.Getenv("TEMP"),
"ProgramData": os.Getenv("ProgramData"),
})
} else {
sh.Env = env.FromMap(map[string]string{
"PATH": os.Getenv("PATH"),
})
}
return sh
}