-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
47 lines (37 loc) · 854 Bytes
/
main_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
package main_test
import (
"flag"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
var cli = flag.String("cli", "", "The CLI binary")
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestCLIVersion(t *testing.T) {
t.Parallel()
path, err := filepath.Abs(*cli)
if err != nil {
t.Fatalf("Could not find runfile %s: %q", *cli, err)
}
if _, err = os.Stat(path); os.IsNotExist(err) {
t.Fatalf("Missing binary %v", path)
}
file, err := filepath.EvalSymlinks(path)
if err != nil {
t.Fatalf("Invalid filename %v", path)
}
cmd := exec.Command(file, "--version")
cmd.Stderr = os.Stderr
res, err := cmd.Output()
if err != nil {
t.Fatalf("failed running '%v': %v", path, err)
}
output := strings.TrimSpace(string(res))
if output != "dev.bazel version" {
t.Error("Expected", "dev.bazel version", "got", output)
}
}