-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
32 lines (28 loc) · 729 Bytes
/
main_test.go
File metadata and controls
32 lines (28 loc) · 729 Bytes
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
package main
import (
"errors"
"os"
"os/exec"
"strings"
"testing"
)
func TestMainExitsOnExecuteError(t *testing.T) {
if os.Getenv("PRETTY_MAIN_CHILD") == "1" {
os.Args = []string{"pretty"}
main()
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestMainExitsOnExecuteError")
cmd.Env = append(os.Environ(), "PRETTY_MAIN_CHILD=1")
out, err := cmd.CombinedOutput()
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) {
t.Fatalf("expected process exit error, got %v", err)
}
if exitErr.ExitCode() != 1 {
t.Fatalf("expected exit code 1, got %d", exitErr.ExitCode())
}
if !strings.Contains(string(out), "requires at least one host") {
t.Fatalf("expected error output, got %q", string(out))
}
}