Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/tests/frontend/add.sh
2065 views
1
#! /usr/bin/env atf-sh
2
3
. $(atf_get_srcdir)/test_environment.sh
4
tests_init \
5
add \
6
add_automatic \
7
add_noscript \
8
add_noscript \
9
add_force \
10
add_accept_missing \
11
add_quiet \
12
add_stdin \
13
add_stdin_missing \
14
add_no_version \
15
add_no_version_multi \
16
add_deps_multi \
17
add_wrong_version
18
#add_require
19
20
initialize_pkg() {
21
touch a
22
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
23
cat << EOF >> test.ucl
24
files: {
25
${TMPDIR}/a: ""
26
}
27
scripts: {
28
pre-install: <<EOD
29
echo "pre-install"
30
EOD
31
post-install: <<EOD
32
echo "post-install"
33
EOD
34
}
35
EOF
36
37
atf_check \
38
-o empty \
39
-e empty \
40
-s exit:0 \
41
pkg create -M test.ucl
42
}
43
44
add_body() {
45
initialize_pkg
46
47
OUTPUT="${JAILED}Installing test-1...
48
pre-install
49
${JAILED}Extracting test-1: done
50
post-install
51
"
52
atf_check \
53
-o inline:"${OUTPUT}" \
54
-e empty \
55
pkg add test-1.pkg
56
57
# test automatic is not set
58
atf_check \
59
-o inline:"0\n" \
60
-e empty \
61
pkg query "%a" test
62
}
63
64
add_automatic_body() {
65
initialize_pkg
66
67
OUTPUT="${JAILED}Installing test-1...
68
pre-install
69
${JAILED}Extracting test-1: done
70
post-install
71
"
72
atf_check \
73
-o inline:"${OUTPUT}" \
74
-e empty \
75
pkg add -A test-1.pkg
76
77
atf_check \
78
-o inline:"1\n" \
79
-e empty \
80
pkg query "%a" test
81
82
}
83
84
add_noscript_body() {
85
initialize_pkg
86
87
OUTPUT="${JAILED}Installing test-1...
88
${JAILED}Extracting test-1: done
89
"
90
cat test-1.pkg | atf_check \
91
-o inline:"${OUTPUT}" \
92
-e empty \
93
pkg add -I test-1.pkg
94
}
95
96
add_force_body() {
97
initialize_pkg
98
}
99
100
101
add_accept_missing_body() {
102
touch a
103
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
104
cat << EOF >> test.ucl
105
deps: {
106
b: {
107
origin: "wedontcare",
108
version: "1"
109
}
110
}
111
files: {
112
${TMPDIR}/a: ""
113
}
114
scripts: {
115
pre-install: <<EOD
116
echo "pre-install"
117
EOD
118
post-install: <<EOD
119
echo "post-install"
120
EOD
121
}
122
EOF
123
124
atf_check \
125
-o empty \
126
-e empty \
127
-s exit:0 \
128
pkg create -M test.ucl
129
130
atf_check \
131
-o inline:"${JAILED}Installing test-1...\n\nFailed to install the following 1 package(s): test-1.pkg\n" \
132
-e inline:"${PROGNAME}: Missing dependency 'b'\n" \
133
-s exit:1 \
134
pkg add test-1.pkg
135
136
OUTPUT="${JAILED}Installing test-1...
137
pre-install
138
${JAILED}Extracting test-1: done
139
post-install
140
"
141
atf_check \
142
-o inline:"${OUTPUT}" \
143
-e inline:"${PROGNAME}: Missing dependency 'b'\n" \
144
-s exit:0 \
145
pkg add -M test-1.pkg
146
}
147
148
add_quiet_body() {
149
initialize_pkg
150
151
atf_check \
152
-o inline:"pre-install\npost-install\n" \
153
-e empty \
154
pkg add -q ./test-1.pkg
155
}
156
157
add_stdin_body() {
158
initialize_pkg
159
160
OUTPUT="${JAILED}Installing test-1...
161
pre-install
162
${JAILED}Extracting test-1: done
163
post-install
164
"
165
cat test-1.pkg | atf_check \
166
-o inline:"${OUTPUT}" \
167
-e empty \
168
pkg add -
169
}
170
171
add_stdin_missing_body() {
172
touch a
173
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
174
cat << EOF >> test.ucl
175
deps: {
176
b: {
177
origin: "wedontcare",
178
version: "1"
179
}
180
}
181
files: {
182
${TMPDIR}/a: ""
183
}
184
scripts: {
185
pre-install: <<EOD
186
echo "pre-install"
187
EOD
188
post-install: <<EOD
189
echo "post-install"
190
EOD
191
}
192
EOF
193
194
atf_check \
195
-o empty \
196
-e empty \
197
-s exit:0 \
198
pkg create -M test.ucl
199
200
atf_check \
201
-o inline:"${JAILED}Installing test-1...\n\nFailed to install the following 1 package(s): -\n" \
202
-e inline:"${PROGNAME}: Missing dependency 'b'\n" \
203
-s exit:1 \
204
pkg add - < test-1.pkg
205
206
OUTPUT="${JAILED}Installing test-1...
207
pre-install
208
${JAILED}Extracting test-1: done
209
post-install
210
"
211
atf_check \
212
-o inline:"${OUTPUT}" \
213
-e inline:"${PROGNAME}: Missing dependency 'b'\n" \
214
-s exit:0 \
215
pkg add -M - < test-1.pkg
216
}
217
218
add_no_version_body() {
219
for p in test final ; do
220
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg ${p} ${p} 1
221
if [ ${p} = "final" ]; then
222
cat << EOF >> final.ucl
223
deps {
224
test {
225
origin = "test";
226
}
227
}
228
EOF
229
fi
230
atf_check -o ignore -s exit:0 \
231
pkg create -M ${p}.ucl
232
done
233
atf_check -o ignore -s exit:0 \
234
pkg add final-1.pkg
235
}
236
237
add_no_version_multi_body() {
238
for p in test final ; do
239
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg ${p} ${p} 1
240
if [ ${p} = "final" ]; then
241
cat << EOF >> final.ucl
242
deps {
243
test {
244
origin = "test";
245
},
246
pkgnotfound {
247
origin = "pkgnotfound";
248
}
249
}
250
EOF
251
fi
252
atf_check -o ignore -s exit:0 \
253
pkg create -M ${p}.ucl
254
done
255
atf_check -o ignore -e ignore -s exit:1 \
256
pkg add final-1.pkg
257
}
258
259
add_deps_multi_body() {
260
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 2
261
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg final final 1
262
263
cat << EOF >> final.ucl
264
deps {
265
test {
266
origin = "test";
267
},
268
}
269
EOF
270
atf_check -o ignore -s exit:0 pkg create -M test.ucl
271
atf_check -o ignore -s exit:0 pkg create -M final.ucl
272
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
273
atf_check -o ignore -s exit:0 pkg create -M test.ucl
274
atf_check -o "match:.*test-2.*" -e empty -s exit:0 \
275
pkg add final-1.pkg
276
}
277
278
add_require_body() {
279
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg test test 1
280
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg final final 1
281
cat << EOF >> final.ucl
282
requires: [functionA]
283
EOF
284
cat << EOF >> test.ucl
285
provides: [functionA]
286
EOF
287
288
atf_check -o ignore -s exit:0 pkg create -M test.ucl
289
atf_check -s exit:0 pkg create -M final.ucl
290
atf_check -o match:".*test-1.*" -e ignore -s exit:0 \
291
pkg add final-1.pkg
292
}
293
294
add_wrong_version_body() {
295
for p in test final ; do
296
atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg ${p} ${p} 1
297
if [ ${p} = "final" ]; then
298
cat << EOF >> final.ucl
299
deps {
300
test {
301
origin = "test";
302
version = "2";
303
}
304
}
305
EOF
306
fi
307
atf_check -o ignore -s exit:0 \
308
pkg create -M ${p}.ucl
309
done
310
atf_check -o ignore -s exit:0 \
311
pkg add final-1.pkg
312
}
313
314