forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_test.go
80 lines (71 loc) · 1.23 KB
/
install_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
package gb
import (
"os"
"path/filepath"
"testing"
)
func TestStale(t *testing.T) {
var tests = []struct {
pkgs []string
stale map[string]bool
}{{
pkgs: []string{"a"},
stale: map[string]bool{
"a": true,
},
}, {
pkgs: []string{"a", "b"},
stale: map[string]bool{
"a": false,
"b": true,
},
}, {
pkgs: []string{"a", "b"},
stale: map[string]bool{
"a": false,
"b": false,
},
}}
root := mktemp(t)
defer os.RemoveAll(root)
proj := Project{
rootdir: root,
srcdirs: []Srcdir{{
Root: filepath.Join(getwd(t), "testdata", "src"),
}},
}
newctx := func() *Context {
ctx, err := proj.NewContext(
GcToolchain(),
)
if err != nil {
t.Fatal(err)
}
return ctx
}
resolve := func(ctx *Context, pkg string) *Package {
p, err := ctx.ResolvePackage(pkg)
if err != nil {
t.Fatal(err)
}
return p
}
for _, tt := range tests {
ctx := newctx()
defer ctx.Destroy()
for _, pkg := range tt.pkgs {
resolve(ctx, pkg)
}
for p, s := range tt.stale {
pkg := resolve(ctx, p)
if pkg.Stale != s {
t.Errorf("%q.Stale: got %v, want %v", pkg.Name, pkg.Stale, s)
}
}
for _, pkg := range tt.pkgs {
if err := Build(resolve(ctx, pkg)); err != nil {
t.Fatal(err)
}
}
}
}