-
Notifications
You must be signed in to change notification settings - Fork 112
/
simple_test.go
108 lines (91 loc) · 2.08 KB
/
simple_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package simple
import (
"os"
"runtime/debug"
"testing"
bazel "github.com/bazelbuild/bazel-integration-testing/go"
"github.com/bazelbuild/bazel-watcher/e2e"
)
func must(t *testing.T, e error) {
if e != nil {
t.Errorf("Error: %s", e)
debug.PrintStack()
}
}
func TestSimpleRun(t *testing.T) {
b, err := bazel.New()
if err != nil {
t.Fatal(err)
}
must(t, b.ScratchFile("WORKSPACE", ""))
must(t, b.ScratchFileWithMode("test.sh", `printf "Started!"`, 0777))
must(t, b.ScratchFile("BUILD", `
sh_binary(
name = "test",
srcs = ["test.sh"],
)
`))
ibazel := e2e.NewIBazelTester(t, b)
ibazel.Run("//:test")
defer ibazel.Kill()
ibazel.ExpectOutput("Started!")
}
func TestSimpleRunUnderSubdir(t *testing.T) {
b, err := bazel.New()
if err != nil {
t.Fatal(err)
}
must(t, b.ScratchFile("WORKSPACE", ""))
must(t, b.ScratchDir("subdir"))
must(t, b.ScratchFileWithMode("subdir/test.sh", `printf "Started!"`, 0777))
must(t, b.ScratchFile("subdir/BUILD", `
sh_binary(
name = "test",
srcs = ["test.sh"],
)
`))
ibazel := e2e.NewIBazelTester(t, b)
err = os.Chdir("subdir")
if err != nil {
t.Fatal(err)
}
ibazel.Run("test")
defer ibazel.Kill()
err = os.Chdir("..")
if err != nil {
t.Fatal(err)
}
ibazel.ExpectOutput("Started!")
}
func TestSimpleRunWithModifiedFile(t *testing.T) {
b, err := bazel.New()
if err != nil {
t.Fatal(err)
}
must(t, b.ScratchFile("WORKSPACE", ""))
must(t, b.ScratchFileWithMode("test.sh", `printf "Started!"`, 0777))
must(t, b.ScratchFile("BUILD", `
sh_binary(
name = "test",
srcs = ["test.sh"],
)
`))
ibazel := e2e.NewIBazelTester(t, b)
ibazel.Run("//:test")
defer ibazel.Kill()
// Give it time to start up and query.
must(t, b.ScratchFileWithMode("test.sh", `printf "Started2!"`, 0777))
ibazel.ExpectOutput("Started2!")
// Manipulate a source file and sleep past the debounce.
must(t, b.ScratchFileWithMode("test.sh", `printf "Started3!"`, 0777))
ibazel.ExpectOutput("Started3!")
// Now a BUILD file.
must(t, b.ScratchFile("BUILD", `
sh_binary(
# New comment
name = "test",
srcs = ["test.sh"],
)
`))
ibazel.ExpectOutput("Started3!")
}