-
Notifications
You must be signed in to change notification settings - Fork 3
/
ver_test.go
139 lines (122 loc) · 4.01 KB
/
ver_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package dpkg
import (
"io/ioutil"
"strings"
"testing"
)
func TestProvide(t *testing.T) {
str := "python-cffi-backend-api-9729, python-cffi-backend-api-max (= 10239), python-cffi-backend-api-min (= 9729)"
Assert(t, parseProvides(str), []string{
"python-cffi-backend-api-9729",
"python-cffi-backend-api-max",
"python-cffi-backend-api-min",
})
}
func TestFilterMatch(t *testing.T) {
str := "libbabeltrace-dev [amd64], libabc [m] | lib0 [mips] |lib2, libefg [xx], lib3"
info, err := ParseDepInfo(str)
Assert(t, err, nil)
info = info.Filter("i386", "")
Assert(t, info.String(), "lib2, lib3")
}
func TestDepFilter(t *testing.T) {
str := "libbabeltrace-dev [amd64], libabc [m] | lib0 [mips] |lib2, libefg, lib3"
info, err := ParseDepInfo(str)
Assert(t, err, nil)
info = info.Filter("i386", "")
Assert(t, info.String(), "lib2, libefg, lib3")
}
func TestDepMatch(t *testing.T) {
str := `binutils:native (>= 2.27.90.20170221) | binutils-multiarch:native (>= 2.27.90.20170221)`
info, err := ParseDepInfo(str)
Assert(t, info.Name, "binutils")
Assert(t, info.Or != nil, true)
str = "libc6.1-dev (>= 2.13-5) [ alpha ia64] | ulibc | linuxc"
info, err = ParseDepInfo(str)
Assert(t, err, nil)
Assert(t, info.Name, "libc6.1-dev")
Assert(t, info.Restrict.Archs, []string{"alpha", "ia64"})
Assert(t, info.match("amd64", ""), false)
Assert(t, info.Or.Name, "ulibc")
Assert(t, info.Or.Or.Name, "linuxc")
str = "libbabeltrace-dev [amd64] <p1>, libabc | lib0 |lib2, libefg, lib3"
info, err = ParseDepInfo(str)
Assert(t, err, nil)
Assert(t, info.Restrict.Archs, []string{"amd64"})
Assert(t, info.Restrict.Profiles, []string{"p1"})
Assert(t, info.And.Name, "libabc")
Assert(t, info.And.Or.Name, "lib0")
Assert(t, info.And.Or.Or.Name, "lib2")
Assert(t, info.And.And.Name, "libefg")
Assert(t, info.And.And.And.Name, "lib3")
}
func TestParseDepends(t *testing.T) {
vs := map[string]string{
"valac": "valac",
"libgtk-3-dev": "libgtk-3-dev",
"libgee-0.8-dev": "libgee-0.8-dev",
"libvte-2.91-dev": "libvte-2.91-dev",
"libjson-glib-dev": "libjson-glib-dev",
"libsecret-1-dev": "libsecret-1-dev",
"libwnck-3-dev": "libwnck-3-dev",
"cmake": "cmake",
"debhelper (>= 3.10)": "debhelper",
"libbabeltrace-dev [amd64 mipsel mips64el powerpc s390x]": "libbabeltrace-dev",
"libghc-aeson-qq-dev [!mips !i386]": "libghc-aeson-qq-dev",
"g++-multilib [amd64 i386 powerpc ppc64 s390 sparc] <!nobiarch>": "g++-multilib",
}
for str, rightName := range vs {
info, err := ParseDepInfo(str)
Assert(t, err, nil)
Assert(t, info.Name, rightName)
}
}
func TestAllVersions(t *testing.T) {
t.Skip()
bs, err := ioutil.ReadFile("testdata/ver.list")
if err != nil {
t.Fatal("Can't load deps.list", err)
}
for _, v := range strings.Split(string(bs), "\n") {
_, err := ParseDepInfo("dump (>=" + v + ")")
if err != nil {
t.Fatal(err)
}
}
}
func TestAllDepends(t *testing.T) {
bs, err := ioutil.ReadFile("testdata/deps.list")
if err != nil {
t.Fatal("Can't load deps.list", err)
}
for _, v := range strings.Split(string(bs), "\n") {
info, err := ParseDepInfo(v)
if err != nil {
t.Fatal(err)
}
t.Log(v, "-->", info)
c1, c2 := strings.Count(v, ","), strings.Count(v, "|")
cc1, cc2 := countAndAndOr(info)
Assert(t, c1, cc1)
Assert(t, c2, cc2)
}
}
func countAndAndOr(info *DepInfo) (int, int) {
if info == nil {
return 0, 0
}
and, or := 0, 0
if info.And != nil {
and++
t1, t2 := countAndAndOr(info.And)
and += t1
or += t2
}
if info.Or != nil {
or++
t1, t2 := countAndAndOr(info.Or)
and += t1
or += t2
}
return and, or
}