xref: /freebsd/contrib/pkgconf/tests/parser.sh (revision a3cefe7f2b4df0f70ff92d4570ce18e517af43ec)
1#!/usr/bin/env atf-sh
2
3. $(atf_get_srcdir)/test_env.sh
4
5tests_init \
6	comments \
7	comments_in_fields \
8	dos \
9	no_trailing_newline \
10	argv_parse \
11	bad_option \
12	argv_parse_3 \
13	tilde_quoting \
14	paren_quoting \
15	multiline_field \
16	multiline_bogus_header \
17	escaped_backslash \
18	flag_order_1 \
19	flag_order_2 \
20	flag_order_3 \
21	flag_order_4 \
22	quoted \
23	variable_whitespace \
24	fragment_escaping_1 \
25	fragment_escaping_2 \
26	fragment_escaping_3 \
27	fragment_quoting \
28	fragment_quoting_2 \
29	fragment_quoting_3 \
30	fragment_quoting_5 \
31	fragment_quoting_7 \
32	fragment_comment \
33	msvc_fragment_quoting \
34	msvc_fragment_render_cflags \
35	tuple_dequote \
36	version_with_whitespace \
37	version_with_whitespace_2 \
38	version_with_whitespace_diagnostic \
39	fragment_groups \
40	fragment_groups_composite \
41	fragment_tree \
42	truncated \
43	c_comment
44
45comments_body()
46{
47	export PKG_CONFIG_PATH="${selfdir}/lib1"
48	atf_check \
49		-o inline:"-lfoo\n" \
50		pkgconf --libs comments
51}
52
53comments_in_fields_body()
54{
55	export PKG_CONFIG_PATH="${selfdir}/lib1"
56	atf_check \
57		-o inline:"-lfoo\n" \
58		pkgconf --libs comments-in-fields
59}
60
61dos_body()
62{
63	export PKG_CONFIG_PATH="${selfdir}/lib1"
64	atf_check \
65		-o inline:"-L/test/lib/dos-lineendings -ldos-lineendings\n" \
66		pkgconf --libs dos-lineendings
67}
68
69no_trailing_newline_body()
70{
71	export PKG_CONFIG_PATH="${selfdir}/lib1"
72	atf_check \
73		-o inline:"-I/test/include/no-trailing-newline\n" \
74		pkgconf --cflags no-trailing-newline
75}
76
77argv_parse_body()
78{
79	export PKG_CONFIG_PATH="${selfdir}/lib1"
80	atf_check \
81		-o inline:"-llib-3 -llib-1 -llib-2 -lpthread\n" \
82		pkgconf --libs argv-parse
83}
84
85bad_option_body()
86{
87	export PKG_CONFIG_PATH="${selfdir}/lib1"
88	atf_check \
89		-e ignore \
90		-s eq:1 \
91		pkgconf --exists -foo
92}
93
94argv_parse_3_body()
95{
96	export PKG_CONFIG_PATH="${selfdir}/lib1"
97	atf_check \
98		-o inline:"-llib-1 -pthread /test/lib/lib2.so\n" \
99		pkgconf --libs argv-parse-3
100}
101
102tilde_quoting_body()
103{
104	export PKG_CONFIG_PATH="${selfdir}/lib1"
105	atf_check \
106		-o inline:"-L~ -ltilde\n" \
107		pkgconf --libs tilde-quoting
108	atf_check \
109		-o inline:"-I~\n" \
110		pkgconf --cflags tilde-quoting
111}
112
113paren_quoting_body()
114{
115	export PKG_CONFIG_PATH="${selfdir}/lib1"
116	atf_check \
117		-o inline:"-L\$(libdir) -ltilde\n" \
118		pkgconf --libs paren-quoting
119}
120
121multiline_field_body()
122{
123	export PKG_CONFIG_PATH="${selfdir}/lib1"
124	atf_check \
125		-e ignore \
126		-o match:"multiline description" \
127		pkgconf --list-all
128}
129
130multiline_bogus_header_body()
131{
132	export PKG_CONFIG_PATH="${selfdir}/lib1"
133	atf_check \
134		-s eq:0 \
135		pkgconf --exists multiline-bogus
136}
137
138escaped_backslash_body()
139{
140	atf_check \
141		-e ignore \
142		-o inline:"-IC:\\\\\\\\A\n" \
143		pkgconf --with-path=${selfdir}/lib1 --cflags escaped-backslash
144}
145
146quoted_body()
147{
148	export PKG_CONFIG_PATH="${selfdir}/lib1"
149	atf_check \
150		-o inline:"-DQUOTED=\\\"bla\\\" -DA=\\\"escaped\\ string\\\'\\ literal\\\" -DB=\\\\\\1\$ -DC=bla\n" \
151		pkgconf --cflags quotes
152}
153
154flag_order_1_body()
155{
156	export PKG_CONFIG_PATH="${selfdir}/lib1"
157	atf_check \
158		-o inline:"-L/test/lib -Bdynamic -lfoo -Bstatic -lbar\n" \
159		pkgconf --libs flag-order-1
160}
161
162flag_order_2_body()
163{
164	export PKG_CONFIG_PATH="${selfdir}/lib1"
165	atf_check \
166		-o inline:"-L/test/lib -Bdynamic -lfoo -Bstatic -lbar -lfoo\n" \
167		pkgconf --libs flag-order-1 foo
168}
169
170flag_order_3_body()
171{
172	export PKG_CONFIG_PATH="${selfdir}/lib1"
173	atf_check \
174		-o inline:"-L/test/lib -Wl,--start-group -lfoo -lbar -Wl,--end-group\n" \
175		pkgconf --libs flag-order-3
176}
177
178flag_order_4_body()
179{
180	export PKG_CONFIG_PATH="${selfdir}/lib1"
181	atf_check \
182		-o inline:"-L/test/lib -Wl,--start-group -lfoo -lbar -Wl,--end-group -lfoo\n" \
183		pkgconf --libs flag-order-3 foo
184}
185
186variable_whitespace_body()
187{
188	export PKG_CONFIG_PATH="${selfdir}/lib1"
189	atf_check \
190		-o inline:"-I/test/include\n" \
191		pkgconf --cflags variable-whitespace
192}
193
194fragment_quoting_body()
195{
196	export PKG_CONFIG_PATH="${selfdir}/lib1"
197	atf_check \
198		-o inline:"-fPIC -I/test/include/foo -DQUOTED=\\\"/test/share/doc\\\"\n" \
199		pkgconf --cflags fragment-quoting
200}
201
202fragment_quoting_2_body()
203{
204	export PKG_CONFIG_PATH="${selfdir}/lib1"
205	atf_check \
206		-o inline:"-fPIC -I/test/include/foo -DQUOTED=/test/share/doc\n" \
207		pkgconf --cflags fragment-quoting-2
208}
209
210fragment_quoting_3_body()
211{
212	export PKG_CONFIG_PATH="${selfdir}/lib1"
213	atf_check \
214		-o inline:"-fPIC -I/test/include/foo -DQUOTED=\\\"/test/share/doc\\\"\n" \
215		pkgconf --cflags fragment-quoting-3
216}
217
218fragment_quoting_5_body()
219{
220	export PKG_CONFIG_PATH="${selfdir}/lib1"
221	atf_check \
222		-o inline:"-fPIC -I/test/include/foo -DQUOTED=/test/share/doc\n" \
223		pkgconf --cflags fragment-quoting-5
224}
225
226fragment_quoting_7_body()
227{
228	export PKG_CONFIG_PATH="${selfdir}/lib1"
229	atf_check \
230		-o inline:"-Dhello=10 -Dworld=+32 -DDEFINED_FROM_PKG_CONFIG=hello\\ world\n" \
231		pkgconf --cflags fragment-quoting-7
232}
233
234fragment_escaping_1_body()
235{
236	atf_check \
237		-o inline:"-IC:\\\\\\\\D\\ E\n" \
238		pkgconf --with-path="${selfdir}/lib1" --cflags fragment-escaping-1
239}
240
241fragment_escaping_2_body()
242{
243	atf_check \
244		-o inline:"-IC:\\\\\\\\D\\ E\n" \
245		pkgconf --with-path="${selfdir}/lib1" --cflags fragment-escaping-2
246}
247
248fragment_escaping_3_body()
249{
250	atf_check \
251		-o inline:"-IC:\\\\\\\\D\\ E\n" \
252		pkgconf --with-path="${selfdir}/lib1" --cflags fragment-escaping-3
253}
254
255fragment_quoting_7a_body()
256{
257	set -x
258
259	test_cflags=$(pkgconf --with-path=${selfdir}/lib1 --cflags fragment-quoting-7)
260	echo $test_cflags
261#	test_cflags='-Dhello=10 -Dworld=+32 -DDEFINED_FROM_PKG_CONFIG=hello\\ world'
262
263	cat > test.c <<- __TESTCASE_END__
264		int main(int argc, char *argv[]) { return DEFINED_FROM_PKG_CONFIG; }
265	__TESTCASE_END__
266	cc -o test-fragment-quoting-7 ${test_cflags} ./test.c
267	atf_check -e 42 ./test-fragment-quoting-7
268	rm -f test.c test-fragment-quoting-7
269
270	set +x
271}
272
273
274fragment_comment_body()
275{
276	atf_check \
277		-o inline:'kuku=\#ttt\n' \
278		pkgconf --with-path="${selfdir}/lib1" --cflags fragment-comment
279}
280
281msvc_fragment_quoting_body()
282{
283	export PKG_CONFIG_PATH="${selfdir}/lib1"
284	atf_check \
285		-o inline:'/libpath:"C:\D E" E.lib \n' \
286		pkgconf --libs --msvc-syntax fragment-escaping-1
287}
288
289msvc_fragment_render_cflags_body()
290{
291	export PKG_CONFIG_PATH="${selfdir}/lib1"
292	atf_check \
293		-o inline:'/I/test/include/foo /DFOO_STATIC \n' \
294		pkgconf --cflags --static --msvc-syntax foo
295}
296
297tuple_dequote_body()
298{
299	atf_check \
300		-o inline:'-L/test/lib -lfoo\n' \
301		pkgconf --with-path="${selfdir}/lib1" --libs tuple-quoting
302}
303
304version_with_whitespace_body()
305{
306	atf_check \
307		-o inline:'3.922\n' \
308		pkgconf --with-path="${selfdir}/lib1" --modversion malformed-version
309}
310
311version_with_whitespace_2_body()
312{
313	atf_check \
314		-o inline:'malformed-version = 3.922\n' \
315		pkgconf --with-path="${selfdir}/lib1" --print-provides malformed-version
316}
317
318version_with_whitespace_diagnostic_body()
319{
320	atf_check \
321		-o match:warning \
322		pkgconf --with-path="${selfdir}/lib1" --validate malformed-version
323}
324
325fragment_groups_body()
326{
327	atf_check \
328		-o inline:'-Wl,--start-group -la -lb -Wl,--end-group -nodefaultlibs -Wl,--start-group -la -lgcc -Wl,--end-group -Wl,--gc-sections\n' \
329		pkgconf --with-path="${selfdir}/lib1" --libs fragment-groups
330}
331
332fragment_groups_composite_body()
333{
334	atf_check \
335		-o inline:'-Wl,--start-group -la -lb -Wl,--end-group -nodefaultlibs -Wl,--start-group -la -lgcc -Wl,--end-group -Wl,--gc-sections\n' \
336		pkgconf --with-path="${selfdir}/lib1" --libs fragment-groups-2
337}
338
339truncated_body()
340{
341	atf_check \
342		-o match:warning -s exit:1 \
343		pkgconf --with-path="${selfdir}/lib1" --validate truncated
344}
345
346c_comment_body()
347{
348	atf_check \
349		-o match:warning \
350		pkgconf --with-path="${selfdir}/lib1" --validate c-comment
351}
352
353fragment_tree_body()
354{
355	atf_check \
356		-o inline:"'-Wl,--start-group' [untyped]
357  '-la' [type l]
358  '-lb' [type l]
359  '-Wl,--end-group' [untyped]
360
361'-nodefaultlibs' [untyped]
362'-Wl,--start-group' [untyped]
363  '-la' [type l]
364  '-lgcc' [type l]
365  '-Wl,--end-group' [untyped]
366
367'-Wl,--gc-sections' [untyped]
368
369" \
370		pkgconf --with-path="${selfdir}/lib1" --fragment-tree fragment-groups-2
371}
372
373