-
Notifications
You must be signed in to change notification settings - Fork 3
/
proto_package_test.go
187 lines (152 loc) · 4.04 KB
/
proto_package_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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package main
import (
"os"
"strings"
"testing"
)
const PkgbuildTest = `# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
pkgname=gnome-todo
pkgver=41.0+r69+ga9a5b7cd
pkgrel=1
pkgdesc="Task manager for GNOME"
url="https://wiki.gnome.org/Apps/Todo"
arch=(x86_64)
license=(GPL)
depends=(evolution-data-server libpeas python gtk4 libportal-gtk4 libadwaita)
makedepends=(gobject-introspection appstream-glib git meson yelp-tools)
groups=(gnome-extra)
_commit=a9a5b7cdde0244331d2d49220f04018be60c018e # master
source=("git+https://gitlab.gnome.org/GNOME/gnome-todo.git#commit=$_commit")
sha256sums=('SKIP')
pkgver() {
cd $pkgname
git describe --tags | sed 's/^GNOME_TODO_//;s/_/./g;s/[^-]*-g/r&/;s/-/+/g'
}
prepare() {
cd $pkgname
}
build() {
arch-meson $pkgname build
meson compile -C build
}
check() (
glib-compile-schemas "${GSETTINGS_SCHEMA_DIR:=$PWD/$pkgname/data}"
export GSETTINGS_SCHEMA_DIR
meson test -C build --print-errorlogs
)
package() {
meson install -C build --destdir "$pkgdir"
}
# vim:set sw=2 et:
`
const PkgbuildTestWithPkgrelSub = `# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
pkgname=gnome-todo
pkgver=41.0+r69+ga9a5b7cd
pkgrel=1.1
pkgdesc="Task manager for GNOME"
url="https://wiki.gnome.org/Apps/Todo"
arch=(x86_64)
license=(GPL)
depends=(evolution-data-server libpeas python gtk4 libportal-gtk4 libadwaita)
makedepends=(gobject-introspection appstream-glib git meson yelp-tools)
groups=(gnome-extra)
_commit=a9a5b7cdde0244331d2d49220f04018be60c018e # master
source=("git+https://gitlab.gnome.org/GNOME/gnome-todo.git#commit=$_commit")
sha256sums=('SKIP')
pkgver() {
cd $pkgname
git describe --tags | sed 's/^GNOME_TODO_//;s/_/./g;s/[^-]*-g/r&/;s/-/+/g'
}
prepare() {
cd $pkgname
}
build() {
arch-meson $pkgname build
meson compile -C build
}
check() (
glib-compile-schemas "${GSETTINGS_SCHEMA_DIR:=$PWD/$pkgname/data}"
export GSETTINGS_SCHEMA_DIR
meson test -C build --print-errorlogs
)
package() {
meson install -C build --destdir "$pkgdir"
}
# vim:set sw=2 et:
`
func TestIncreasePkgRel(t *testing.T) { //nolint:paralleltest
pkgbuild, err := os.CreateTemp("", "")
if err != nil {
t.Fatal("unable to setup temp. PKGBUILD")
}
defer func(name string) {
_ = os.Remove(name)
}(pkgbuild.Name())
_, err = pkgbuild.WriteString(PkgbuildTest)
if err != nil {
t.Fatal("unable to write to temp. PKGBUILD")
}
_ = pkgbuild.Close()
buildPkg := &ProtoPackage{
Pkgbase: "gnome-todo",
Pkgbuild: pkgbuild.Name(),
}
err = buildPkg.increasePkgRel(1)
if err != nil {
t.Logf("increasePkgRel: %v", err)
t.Fail()
}
versionSplit := strings.Split(buildPkg.Version, "-")
if versionSplit[len(versionSplit)-1] != "1.1" {
t.Logf("increasePkgRel: expected 1.1 pkgrel, got: %s", buildPkg.Version)
t.Fail()
}
buildPkg.Srcinfo = nil
err = buildPkg.genSrcinfo()
if err != nil {
t.Logf("increasePkgRel: %v", err)
t.Fail()
}
if buildPkg.Srcinfo.Pkgrel != "1.1" {
t.Logf("increasePkgRel: expected 1.1 pkgrel, got: %s", buildPkg.Srcinfo.Pkgrel)
t.Fail()
}
}
func TestIncreasePkgRelWithPkgSub(t *testing.T) { //nolint:paralleltest
pkgbuild, err := os.CreateTemp("", "")
if err != nil {
t.Fatal("unable to setup temp. PKGBUILD")
}
defer func(name string) {
_ = os.Remove(name)
}(pkgbuild.Name())
_, err = pkgbuild.WriteString(PkgbuildTestWithPkgrelSub)
if err != nil {
t.Fatal("unable to write to temp. PKGBUILD")
}
_ = pkgbuild.Close()
buildPkg := &ProtoPackage{
Pkgbase: "gnome-todo",
Pkgbuild: pkgbuild.Name(),
}
err = buildPkg.increasePkgRel(1)
if err != nil {
t.Logf("increasePkgRel: %v", err)
t.Fail()
}
versionSplit := strings.Split(buildPkg.Version, "-")
if versionSplit[len(versionSplit)-1] != "1.2" {
t.Logf("increasePkgRel: expected 1.2 pkgrel, got: %s", buildPkg.Version)
t.Fail()
}
buildPkg.Srcinfo = nil
err = buildPkg.genSrcinfo()
if err != nil {
t.Logf("increasePkgRel: %v", err)
t.Fail()
}
if buildPkg.Srcinfo.Pkgrel != "1.2" {
t.Logf("increasePkgRel: expected 1.2 pkgrel, got: %s", buildPkg.Srcinfo.Pkgrel)
t.Fail()
}
}