xref: /freebsd/contrib/pkgconf/tests/basic.sh (revision a3cefe7f2b4df0f70ff92d4570ce18e517af43ec)
1#!/usr/bin/env atf-sh
2
3. $(atf_get_srcdir)/test_env.sh
4
5tests_init \
6	noargs \
7	libs \
8	libs_cflags \
9	libs_cflags_version \
10	libs_cflags_version_multiple \
11	libs_cflags_version_alt \
12	libs_cflags_version_different \
13	libs_cflags_version_different_bad \
14	libs_env \
15	exists_nonexitent \
16	nonexitent \
17	exists_version \
18	exists_version_bad \
19	exists_version_bad2 \
20	exists_version_bad3 \
21	exists \
22	exists2 \
23	exists3 \
24	exists_version_alt \
25	exists_cflags \
26	exists_cflags_env \
27	uninstalled_bad \
28	uninstalled \
29	libs_intermediary \
30	libs_circular1 \
31	libs_circular2 \
32	libs_circular_directpc \
33	libs_static \
34	libs_static_ordering \
35	libs_metapackage \
36	license_isc \
37	license_noassertion \
38	modversion_noflatten \
39	pkg_config_path \
40	nolibs \
41	nocflags \
42	arbitary_path \
43	with_path \
44	relocatable \
45	single_depth_selectors \
46	print_variables_env \
47	variable_env \
48	variable_no_recurse
49
50noargs_body()
51{
52	export PKG_CONFIG_PATH="${selfdir}/lib1"
53	atf_check -s exit:1 -e ignore pkgconf
54}
55
56libs_body()
57{
58	export PKG_CONFIG_PATH="${selfdir}/lib1"
59	atf_check \
60		-o inline:"-L/test/lib -lfoo\n" \
61		pkgconf --libs foo
62}
63
64libs_cflags_body()
65{
66	export PKG_CONFIG_PATH="${selfdir}/lib1"
67	atf_check \
68		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lfoo\n" \
69		pkgconf --cflags --libs foo
70}
71
72atf_test_case basic_libs_cflags_version
73libs_cflags_version_body()
74{
75	export PKG_CONFIG_PATH="${selfdir}/lib1"
76	atf_check \
77		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lfoo\n" \
78		pkgconf --cflags --libs 'foo > 1.2'
79}
80
81libs_cflags_version_multiple_body()
82{
83	export PKG_CONFIG_PATH="${selfdir}/lib1"
84	atf_check \
85		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo\n" \
86		pkgconf --cflags --libs 'foo > 1.2 bar >= 1.3'
87}
88
89libs_cflags_version_multiple_coma_body()
90{
91	export PKG_CONFIG_PATH="${selfdir}/lib1"
92	atf_check \
93		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo\n" \
94		pkgconf --cflags --libs 'foo > 1.2,bar >= 1.3'
95}
96
97libs_cflags_version_alt_body()
98{
99	export PKG_CONFIG_PATH="${selfdir}/lib1"
100	atf_check \
101		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lfoo\n" \
102		pkgconf --cflags --libs 'foo' '>' '1.2'
103}
104
105libs_cflags_version_different_body()
106{
107	export PKG_CONFIG_PATH="${selfdir}/lib1"
108	atf_check \
109		-o inline:"-fPIC -I/test/include/foo -L/test/lib -lfoo\n" \
110		pkgconf --cflags --libs 'foo' '!=' '1.3.0'
111}
112
113atf_test_case basic_libs_cflags_version_different_bad
114libs_cflags_version_different_bad_body()
115{
116	export PKG_CONFIG_PATH="${selfdir}/lib1"
117	atf_check \
118		-s exit:1 \
119		-e inline:"Package dependency requirement 'foo != 1.2.3' could not be satisfied.\nPackage 'foo' has version '1.2.3', required version is '!= 1.2.3'\n" \
120		pkgconf --cflags --libs 'foo' '!=' '1.2.3'
121}
122
123exists_nonexitent_body()
124{
125	export PKG_CONFIG_PATH="${selfdir}/lib1"
126	atf_check \
127		-s exit:1 \
128		pkgconf --exists nonexistant
129}
130
131nonexitent_body()
132{
133	export PKG_CONFIG_PATH="${selfdir}/lib1"
134	atf_check \
135		-s exit:1 \
136		pkgconf nonexistant
137}
138
139exists_version_body()
140{
141	export PKG_CONFIG_PATH="${selfdir}/lib1"
142	atf_check \
143		pkgconf --exists 'foo > 1.2'
144}
145
146exists_version_bad_body()
147{
148	export PKG_CONFIG_PATH="${selfdir}/lib1"
149	atf_check \
150		-s exit:1 \
151		pkgconf --exists 'foo > 1.2.3'
152}
153
154exists_version_alt_body()
155{
156	export PKG_CONFIG_PATH="${selfdir}/lib1"
157	atf_check \
158		pkgconf --exists 'foo' '>' '1.2'
159}
160
161uninstalled_bad_body()
162{
163	export PKG_CONFIG_PATH="${selfdir}/lib1"
164	atf_check \
165		-s exit:1 \
166		pkgconf --uninstalled 'foo'
167}
168
169uninstalled_body()
170{
171	export PKG_CONFIG_PATH="${selfdir}/lib1"
172	atf_check \
173		pkgconf --uninstalled 'omg'
174}
175
176exists_version_bad2_body()
177{
178	export PKG_CONFIG_PATH="${selfdir}/lib1"
179	atf_check \
180		-s exit:1 \
181		pkgconf --exists 'foo >= '
182}
183
184exists_version_bad3_body()
185{
186	export PKG_CONFIG_PATH="${selfdir}/lib1"
187	atf_check \
188		-s exit:1 \
189		pkgconf --exists 'tilde >= 1.0.0'
190}
191
192exists_body()
193{
194	export PKG_CONFIG_PATH="${selfdir}/lib1"
195	atf_check \
196		pkgconf --exists 'tilde = 1.0.0~rc1'
197}
198
199exists2_body()
200{
201	export PKG_CONFIG_PATH="${selfdir}/lib1"
202	atf_check \
203		pkgconf --exists 'tilde <= 1.0.0'
204}
205
206exists3_body()
207{
208	export PKG_CONFIG_PATH="${selfdir}/lib1"
209	atf_check \
210		pkgconf --exists '' 'foo'
211}
212
213libs_intermediary_body()
214{
215	export PKG_CONFIG_PATH="${selfdir}/lib1"
216	atf_check \
217		-o inline:"-lintermediary-1 -lintermediary-2 -lfoo -lbar -lbaz\n" \
218		pkgconf --libs intermediary-1 intermediary-2
219}
220
221libs_circular2_body()
222{
223	export PKG_CONFIG_PATH="${selfdir}/lib1"
224	atf_check \
225		-o inline:"circular-1: breaking circular reference (circular-1 -> circular-2 -> circular-1)\n" \
226		pkgconf circular-2 --validate
227}
228
229libs_circular1_body()
230{
231	export PKG_CONFIG_PATH="${selfdir}/lib1"
232	atf_check \
233		-o inline:"circular-3: breaking circular reference (circular-3 -> circular-1 -> circular-3)\n" \
234		pkgconf circular-1 --validate
235}
236
237libs_circular_directpc_body()
238{
239	atf_check \
240		-o inline:"-lcircular-3 -lcircular-1 -lcircular-2\n" \
241		pkgconf --libs ${selfdir}/lib1/circular-3.pc
242}
243
244libs_static_body()
245{
246	export PKG_CONFIG_PATH="${selfdir}/lib1"
247	atf_check \
248		-o inline:"/libfoo.a -pthread\n" \
249		pkgconf --libs static-archive-libs
250}
251
252libs_static_ordering_body()
253{
254	export PKG_CONFIG_PATH="${selfdir}/lib1"
255	atf_check \
256		-o inline:"-L/test/lib -lbar -lfoo\n" \
257		pkgconf --libs foo bar
258}
259
260libs_metapackage_body()
261{
262	export PKG_CONFIG_PATH="${selfdir}/lib1"
263	atf_check \
264		-o inline:"-L/test/lib -lbar -lfoo\n" \
265		pkgconf --static --libs metapackage-3
266}
267
268pkg_config_path_body()
269{
270	export PKG_CONFIG_PATH="${selfdir}/lib1${PATH_SEP}${selfdir}/lib2"
271	atf_check \
272		-o inline:"-L/test/lib -lfoo\n" \
273		pkgconf --libs foo
274	atf_check \
275		-o inline:"-L/test/lib -lbar -lfoo\n" \
276		pkgconf --libs bar
277}
278
279with_path_body()
280{
281	atf_check \
282		-o inline:"-L/test/lib -lfoo\n" \
283		pkgconf --with-path=${selfdir}/lib1 --with-path=${selfdir}/lib2 --libs foo
284	atf_check \
285		-o inline:"-L/test/lib -lbar -lfoo\n" \
286		pkgconf --with-path=${selfdir}/lib1 --with-path=${selfdir}/lib2 --libs bar
287}
288
289nolibs_body()
290{
291	export PKG_CONFIG_PATH="${selfdir}/lib1"
292	atf_check \
293		-o inline:"\n" \
294		pkgconf --libs nolib
295}
296
297nocflags_body()
298{
299	export PKG_CONFIG_PATH="${selfdir}/lib1"
300	atf_check \
301		-o inline:"\n" \
302		pkgconf --cflags nocflag
303}
304
305arbitary_path_body()
306{
307	cp ${selfdir}/lib1/foo.pc .
308	atf_check \
309		-o inline:"-L/test/lib -lfoo\n" \
310		pkgconf --libs foo.pc
311}
312
313relocatable_body()
314{
315	basedir=$(pkgconf --relocate ${selfdir})
316	atf_check \
317		-o inline:"${basedir}/lib-relocatable\n" \
318		pkgconf --define-prefix --variable=prefix ${basedir}/lib-relocatable/lib/pkgconfig/foo.pc
319}
320
321single_depth_selectors_body()
322{
323	export PKG_CONFIG_MAXIMUM_TRAVERSE_DEPTH=1
324	atf_check \
325		-o inline:"foo\n" \
326		pkgconf --with-path=${selfdir}/lib3 --print-requires bar
327}
328
329license_isc_body()
330{
331	atf_check \
332		-o inline:"foo: ISC\n" \
333		pkgconf --with-path=${selfdir}/lib1 --license foo
334}
335
336license_noassertion_body()
337{
338	atf_check \
339		-o inline:"bar: NOASSERTION\nfoo: ISC\n" \
340		pkgconf --with-path=${selfdir}/lib1 --license bar
341}
342
343modversion_noflatten_body()
344{
345	atf_check \
346		-o inline:"1.3\n" \
347		pkgconf --with-path=${selfdir}/lib1 --modversion bar
348}
349
350exists_cflags_body()
351{
352	atf_check \
353		-o inline:"-DHAVE_FOO\n" \
354		pkgconf --with-path=${selfdir}/lib1 --cflags --exists-cflags --fragment-filter=D foo
355}
356
357exists_cflags_env_body()
358{
359	atf_check \
360		-o inline:"FOO_CFLAGS='-DHAVE_FOO'\n" \
361		pkgconf --with-path=${selfdir}/lib1 --cflags --exists-cflags --fragment-filter=D --env=FOO foo
362}
363
364libs_env_body()
365{
366	atf_check \
367		-o inline:"FOO_LIBS='-L/test/lib -lfoo'\n" \
368		pkgconf --with-path=${selfdir}/lib1 --libs --env=FOO foo
369}
370
371print_variables_env_body()
372{
373	atf_check \
374		-o inline:"FOO_CFLAGS='-fPIC -I/test/include/foo'\nFOO_LIBS='-L/test/lib -lfoo'\nFOO_INCLUDEDIR='/test/include'\nFOO_LIBDIR='/test/lib'\nFOO_EXEC_PREFIX='/test'\nFOO_PREFIX='/test'\nFOO_PCFILEDIR='${selfdir}/lib1'\n" \
375		pkgconf --with-path=${selfdir}/lib1 --env=FOO --print-variables --cflags --libs foo
376
377}
378
379variable_env_body()
380{
381	atf_check \
382		-o inline:"FOO_INCLUDEDIR='/test/include'\n" \
383		pkgconf --with-path=${selfdir}/lib1 --env=FOO --variable=includedir foo
384}
385
386variable_no_recurse_body()
387{
388	atf_check \
389		-o inline:"/test/include\n" \
390		pkgconf --with-path=${selfdir}/lib1 --variable=includedir bar
391}
392