Debian Codegraph @

tests/base.at

raw
1 # -*- Autotest -*-
2
3 AT_BANNER([Autoconf base layer.])
4
5 # Copyright (C) 2000-2001, 2003, 2005-2017, 2020-2026 Free Software
6 # Foundation, Inc.
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21
22 ## ------------------------------- ##
23 ## AC_REQUIRE: topological sort.. ##
24 ## ------------------------------- ##
25
26 # Check that dependencies are always properly honored.
27
28 AT_SETUP([AC_REQUIRE: topological sort])
29 AT_KEYWORDS([m4@&t@_require])
30
31 AT_DATA([configure.ac],
32 [[define([REQUIRE_AND_CHECK],
33 [AC_REQUIRE([$1])
34 test -z "$m4@&t@_translit([$1], [A-Z], [a-z])" && AS_EXIT(1)])
35
36 AC_DEFUN([TEST1],
37 [REQUIRE_AND_CHECK([TEST2a])
38 REQUIRE_AND_CHECK([TEST2b])
39 test1=set])
40
41 AC_DEFUN([TEST2a],
42 [test2a=set])
43
44 AC_DEFUN([TEST2b],
45 [REQUIRE_AND_CHECK([TEST3])
46 test2b=set])
47
48 AC_DEFUN([TEST3],
49 [REQUIRE_AND_CHECK([TEST2a])
50 test3=set])
51
52 AS@&t@_INIT
53
54 TEST1
55 test -z "$test1" &&
56 AC_MSG_ERROR([\$test1 is empty])
57 AS_EXIT(0)
58 ]])
59
60 AT_CHECK_AUTOCONF([], [0], [],
61 [[trailer.m4: warning: AC_INIT was never used
62 trailer.m4: warning: AC_OUTPUT was never used
63 ]])
64 AT_CHECK_CONFIGURE
65
66 AT_CLEANUP
67
68
69 ## --------------------------- ##
70 ## AC_REQUIRE: error message. ##
71 ## --------------------------- ##
72
73 # Check that the message mentions AC_DEFUN, not m4_defun.
74
75 AT_SETUP([AC_REQUIRE: error message])
76 AT_KEYWORDS([m4@&t@_require])
77 AT_DATA([configure.ac],
78 [[AC_REQUIRE([AC_PROG_CC])
79 ]])
80
81 AT_CHECK_AUTOCONF([], [1], [],
82 [[configure.ac:1: error: AC_REQUIRE(AC_PROG_CC): cannot be used outside of an AC_DEFUN'd macro
83 configure.ac:1: the top level
84 autom4te: error: m4 failed with exit status: 1
85 ]])
86 AT_CLEANUP
87
88
89 ## ----------------------------------------------- ##
90 ## AC_REQUIRE and AC_DEFUN_ONCE: Require, expand. ##
91 ## ----------------------------------------------- ##
92
93 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Require, expand]])
94 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
95
96 AT_DATA([configure.ac],
97 [[AC_DEFUN([TEST],
98 [AC_REQUIRE([MULTI_TEST])
99 AC_REQUIRE([SINGLE_TEST])])
100
101 AC_DEFUN([MULTI_TEST],
102 [multi_test=".$multi_test"])
103
104 AC_DEFUN_ONCE([SINGLE_TEST],
105 [single_test=".$single_test"])
106
107 AS@&t@_INIT
108
109 TEST
110 TEST
111 MULTI_TEST
112 MULTI_TEST
113 SINGLE_TEST
114 SINGLE_TEST
115
116 case $multi_test:$single_test in
117 ...:. ) AS_EXIT(0);;
118 ...:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
119 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
120 esac
121 ]])
122
123 AT_CHECK_AUTOCONF([], 0, [],
124 [[trailer.m4: warning: AC_INIT was never used
125 trailer.m4: warning: AC_OUTPUT was never used
126 ]])
127
128 AT_CHECK_CONFIGURE
129
130 AT_CLEANUP
131
132
133
134 ## ----------------------------------------------- ##
135 ## AC_REQUIRE and AC_DEFUN_ONCE: Expand, require. ##
136 ## ----------------------------------------------- ##
137
138 AT_SETUP([AC_REQUIRE & AC_DEFUN_ONCE: [Expand, require]])
139 AT_KEYWORDS([m4@&t@_require m4@&t@_require_once])
140
141 AT_DATA([configure.ac],
142 [[AC_DEFUN([TEST],
143 [AC_REQUIRE([MULTI_TEST])
144 AC_REQUIRE([SINGLE_TEST])])
145
146 AC_DEFUN([MULTI_TEST],
147 [multi_test=".$multi_test"])
148
149 AC_DEFUN_ONCE([SINGLE_TEST],
150 [single_test=".$single_test"])
151
152 AS@&t@_INIT
153
154 MULTI_TEST
155 MULTI_TEST
156 SINGLE_TEST
157 SINGLE_TEST
158 TEST
159 TEST
160
161 case $multi_test:$single_test in
162 ..:. ) AS_EXIT(0);;
163 ..:* ) AC_MSG_ERROR([DEFUN_ONCE is broken]);;
164 *:. ) AC_MSG_ERROR([DEFUN is broken (Wow, congrats!)]);;
165 * ) AC_MSG_ERROR([received '$multi_test:$single_test']);;
166 esac
167 ]])
168
169 AT_CHECK_AUTOCONF([], 0, [],
170 [[trailer.m4: warning: AC_INIT was never used
171 trailer.m4: warning: AC_OUTPUT was never used
172 ]])
173 AT_CHECK_CONFIGURE
174
175 AT_CLEANUP
176
177
178
179 ## ------------------------- ##
180 ## AC_REQUIRE & AC_PROVIDE. ##
181 ## ------------------------- ##
182
183 AT_SETUP([AC_REQUIRE & AC_PROVIDE])
184 AT_KEYWORDS([m4@&t@_require])
185
186 AT_DATA([configure.ac],
187 [[AC_DEFUN([TEST],
188 [AC_REQUIRE([INNER_TEST])])
189
190 AC_DEFUN([INNER_TEST],
191 [inner_test=".$inner_test"])
192
193 AS@&t@_INIT
194
195 AC_PROVIDE([INNER_TEST])
196 TEST
197
198 case $inner_test in
199 "" ) AS_EXIT(0);;
200 * ) AC_MSG_ERROR([received '$inner_test']);;
201 esac
202 ]])
203
204 AT_CHECK_AUTOCONF([], 0, [],
205 [[trailer.m4: warning: AC_INIT was never used
206 trailer.m4: warning: AC_OUTPUT was never used
207 ]])
208 AT_CHECK_CONFIGURE
209
210 AT_CLEANUP
211
212
213 ## -------- ##
214 ## AC_INIT. ##
215 ## -------- ##
216
217 # Make sure AC_INIT sets PACKAGE_TARNAME properly.
218
219 AT_SETUP([AC_INIT])
220
221 AT_DATA([configure.ac],
222 [[AC_INIT([GNU fu], [1.0], [[email protected]])
223 AC_OUTPUT
224 ]])
225
226 AT_CHECK_AUTOCONF
227 AT_CHECK_CONFIGURE([-q])
228
229 # Ensure we get the expected definition:
230 AT_CHECK([grep "^PACKAGE_TARNAME='fu'\$" configure], [], [ignore])
231
232 AT_CLEANUP
233
234 ## ------------------------------- ##
235 ## AC_INIT (obsolete invocation). ##
236 ## ------------------------------- ##
237
238 # When AC_INIT is called with only one argument, it is equivalent to
239 # passing that argument to AC_CONFIG_SRCDIR and then calling AC_INIT
240 # with _no_ arguments. In particular, PACKAGE should _not_ be set
241 # to whatever the first argument is.
242
243 AT_SETUP([AC_INIT (obsolete invocation)])
244
245 AT_DATA([configure.ac],
246 [[AC_INIT([program.c])
247 AC_OUTPUT
248 ]])
249
250 AT_CHECK_AUTOCONF
251
252 # Ensure we get the expected definition:
253 AT_CHECK([grep "^PACKAGE_NAME=''\$" configure], [], [ignore])
254
255 # Running autoconf right now should fail because program.c doesn't exist.
256 AT_CHECK_CONFIGURE([], [1], [],
257 [[configure: error: cannot find sources (program.c) in . or ..
258 ]])
259
260 # Create program.c and then it should be fine.
261 AT_DATA([program.c])
262 AT_CHECK_CONFIGURE
263
264 AT_CLEANUP
265
266
267 ## ------------------------------------- ##
268 ## AC_INIT with unusual version strings. ##
269 ## ------------------------------------- ##
270
271 AT_SETUP([AC_INIT with unusual version strings])
272
273 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
274 FGREP="grep -F"
275 else
276 FGREP=fgrep
277 fi
278
279 # In both of the arguments that might contain URLs, make sure we test
280 # all of the unusual ASCII characters that commonly appear in URLs.
281 #
282 # The RFC 3986 "unreserved" characters are ASCII letters and digits, plus
283 # - . _ ~
284 # The RFC 3986 "gen-delims" and "sub-delims" are
285 # / : ? # [ ] @ ! $ & ' ( ) * + , ; =
286 # The URL escape character is
287 # %
288 #
289 # Any argument that contains characters significant to M4,
290 # [ ] ( ) ,
291 # may need to be double-quoted depending on exactly how they are used
292 # (as would an argument that contains a macro name, but we don't test
293 # that here).
294 #
295 # Characters that are still significant for Bourne shell within a
296 # single-quoted string, double-quoted string, quoted here-doc, or
297 # unquoted here-doc are explicitly not allowed:
298 # ' " ` \ $
299 #
300 # We don't test unbalanced parentheses or brackets here.
301
302 AT_DATA([configure.ac],
303 [[AC_INIT([GNU String++ with spaces
304 (foo)],
305 [2.48++ (2010-07-03)],
306 [[https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890]],
307 [string++],
308 [[HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890]])
309 AC_OUTPUT
310 ]])
311
312 AT_CHECK_AUTOCONF([-Werror])
313 AT_CHECK_CONFIGURE([-q])
314
315 AT_CHECK_CONFIGURE([--help], [], [stdout])
316 AT_CHECK([[$FGREP \
317 'https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890' \
318 stdout]], [], [ignore])
319 AT_CHECK([[$FGREP \
320 'HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890' \
321 stdout]], [], [ignore])
322
323 AT_CHECK_CONFIGURE([--version], [], [stdout])
324 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
325 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
326
327 AT_CHECK([./config.status --help], [], [stdout])
328 AT_CHECK([[$FGREP \
329 'https://example/~bug/cdfijknoqrvw/-._:@!()[]*+,;/?y=z#1234567890' \
330 stdout]], [], [ignore])
331 AT_CHECK([[$FGREP \
332 'HTTPS://EXAMPLE/~PKG/BCDFIJNOQRUVW/-._:@!()[]*+,;/?y=z#1234567890' \
333 stdout]], [], [ignore])
334
335 AT_CHECK([./config.status --version], [], [stdout])
336 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
337 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
338
339 # Repeat the above test using all the unusual characters that might appear
340 # in a list of email addresses in both BUG-REPORT and URL. (URL isn't
341 # supposed to contain email addresses, but there's no good reason to
342 # restrict its syntax.)
343 # The RFC 5822 "atext" characters are ASCII letters and digits, plus
344 # ! # $ % & ' * + - / = ? ^ _ ` { | } ~
345 # The RFC 5822 "special" characters, all of which might appear somewhere
346 # in an address list, are
347 # ( ) < > [ ] : ; @ \ , . "
348 # As above, characters that are significant for Bourne shell within
349 # strings and heredocs are explicitly not allowed:
350 # ' " ` \ $
351 # As above, any argument that contains characters significant to M4,
352 # [ ] ( ) ,
353 # may need to be double-quoted depending on exactly how they are used
354 # (as would an argument that contains a macro name, but we don't test
355 # that here).
356
357 AT_DATA([configure.ac],
358 [[AC_INIT([GNU String++ with spaces
359 (foo)],
360 [2.48++ (2010-07-03)],
361 [[bugs: fred <A=B?C^D_E@F>,
362 G!H!I#[email protected] (wilma),
363 M%N&O@[156.247.38.49],
364 P*Q+R-S/T@U,
365 {jon|chyp~}@kqtvxz.VWXYZ;]],
366 [string++],
367 [[contact: jem <A=B?C^D_E@bd>,
368 F!G!H#[email protected] (lugh),
369 K%L&M@[156.247.38.49],
370 N*O+P-Q/R@STU,
371 {qik|~prys}@wxz.VWXYZ;]])
372 AC_OUTPUT
373 ]])
374
375 AT_CHECK_AUTOCONF([-Werror])
376 AT_CHECK_CONFIGURE([-q])
377
378 AT_CHECK_CONFIGURE([--help], [], [stdout])
379 AT_CHECK([[$FGREP \
380 'bugs: fred <A=B?C^D_E@F>, G!H!I#[email protected] (wilma), M%N&O@[156.247.38.49], P*Q+R-S/T@U, {jon|chyp~}@kqtvxz.VWXYZ;' \
381 stdout]], [], [ignore])
382 AT_CHECK([[$FGREP \
383 'contact: jem <A=B?C^D_E@bd>, F!G!H#[email protected] (lugh), K%L&M@[156.247.38.49], N*O+P-Q/R@STU, {qik|~prys}@wxz.VWXYZ;' \
384 stdout]], [], [ignore])
385
386 AT_CHECK_CONFIGURE([--version], [], [stdout])
387 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
388 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
389
390 AT_CHECK([./config.status --help], [], [stdout])
391 AT_CHECK([[$FGREP \
392 'bugs: fred <A=B?C^D_E@F>, G!H!I#[email protected] (wilma), M%N&O@[156.247.38.49], P*Q+R-S/T@U, {jon|chyp~}@kqtvxz.VWXYZ;' \
393 stdout]], [], [ignore])
394 AT_CHECK([[$FGREP \
395 'contact: jem <A=B?C^D_E@bd>, F!G!H#[email protected] (lugh), K%L&M@[156.247.38.49], N*O+P-Q/R@STU, {qik|~prys}@wxz.VWXYZ;' \
396 stdout]], [], [ignore])
397
398 AT_CHECK([./config.status --version], [], [stdout])
399 AT_CHECK([$FGREP 'GNU String++ with spaces (foo)' stdout], [], [ignore])
400 AT_CHECK([$FGREP '2.48++ (2010-07-03)' stdout], [], [ignore])
401
402 # Check for invalid characters in each argument.
403 AT_DATA([configure.ac],
404 [[AC_INIT([GNU "String++"],
405 [2.48], [https://example.com/], [string++])
406 AC_OUTPUT
407 ]])
408
409 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
410 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
411
412 AT_DATA([configure.ac],
413 [[AC_INIT([GNU String++],
414 ['codename' 2.48], [https://example.com/], [string++])
415 AC_OUTPUT
416 ]])
417
418 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
419 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
420
421 AT_DATA([configure.ac],
422 [[AC_INIT([GNU
423 String++], [2.48], [https://example.com/], [string++])
424 AC_OUTPUT
425 ]])
426
427 AT_CHECK_AUTOCONF([-Werror])
428
429 AT_DATA([configure.ac],
430 [[AC_INIT([GNU String++], ['2.48'], [https://example.com], [string++])
431 AC_OUTPUT
432 ]])
433
434 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
435 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
436
437 AT_DATA([configure.ac],
438 [[AC_INIT([GNU String++], [2.48], ['https://example.com'], [string++])
439 AC_OUTPUT
440 ]])
441
442 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
443 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
444
445 AT_DATA([configure.ac],
446 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string++],
447 ['https://example.com'])
448 AC_OUTPUT
449 ]])
450
451 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
452 AT_CHECK([grep 'AC_INIT: not a literal: ' stderr], [], [ignore])
453
454
455 # The TARNAME argument is used to construct filenames, so it's even
456 # more constrained.
457
458 AT_DATA([configure.ac],
459 [[AC_INIT([GNU String++], [2.48], [https://example.com], ['string++'])
460 AC_OUTPUT
461 ]])
462
463 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
464 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
465
466 AT_DATA([configure.ac],
467 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string ++])
468 AC_OUTPUT
469 ]])
470
471 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
472 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
473
474 AT_DATA([configure.ac],
475 [[AC_INIT([GNU String++], [2.48], [https://example.com], [string*])
476 AC_OUTPUT
477 ]])
478
479 AT_CHECK_AUTOCONF([-Werror], [1], [ignore], [stderr])
480 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
481
482 # Commas and unbalanced close parentheses are especially troublesome for M4.
483 # They are only expected to work when double-quoted, but even then they can
484 # cause malfunctions if not handled carefully within Autoconf.
485
486 AT_DATA([configure.ac],
487 [[AC_INIT([[GNU, String]], [2.48], [[email protected]],
488 [string], [https://gstring.example/])
489 AC_OUTPUT
490 ]])
491 AT_CHECK_AUTOCONF
492
493 AT_DATA([configure.ac],
494 [[AC_INIT([[GNU String)]], [2.48], [[email protected]],
495 [string], [https://gstring.example/])
496 AC_OUTPUT
497 ]])
498 AT_CHECK_AUTOCONF
499
500 AT_DATA([configure.ac],
501 [[AC_INIT([GNU String], [[2,48]], [[email protected]],
502 [string], [https://gstring.example/])
503 AC_OUTPUT
504 ]])
505 AT_CHECK_AUTOCONF
506
507 AT_DATA([configure.ac],
508 [[AC_INIT([GNU String], [[2.48)]], [[email protected]],
509 [string], [https://gstring.example/])
510 AC_OUTPUT
511 ]])
512 AT_CHECK_AUTOCONF
513
514 AT_DATA([configure.ac],
515 [[AC_INIT([GNU String], [2.48], [[[email protected],
516 [email protected]]],
517 [string], [https://gstring.example/])
518 AC_OUTPUT
519 ]])
520 AT_CHECK_AUTOCONF
521
522 AT_DATA([configure.ac],
523 [[AC_INIT([GNU String], [2.48], [[bugs)@gstring.example]],
524 [string], [https://gstring.example/])
525 AC_OUTPUT
526 ]])
527 AT_CHECK_AUTOCONF
528
529 AT_DATA([configure.ac],
530 [[AC_INIT([GNU String], [2.48], [[email protected]],
531 [[string,]], [https://gstring.example/])
532 AC_OUTPUT
533 ]])
534 AT_CHECK_AUTOCONF
535
536 AT_DATA([configure.ac],
537 [[AC_INIT([GNU String], [2.48], [[email protected]],
538 [[string)]], [https://gstring.example/])
539 AC_OUTPUT
540 ]])
541 AT_CHECK_AUTOCONF([], [0], [ignore], [stderr])
542 AT_CHECK([grep 'AC_INIT: unsafe as a filename: ' stderr], [], [ignore])
543
544 AT_DATA([configure.ac],
545 [[AC_INIT([GNU String], [2.48], [[email protected]],
546 [string], [[https://gstring.example/docs,html]])
547 AC_OUTPUT
548 ]])
549 AT_CHECK_AUTOCONF
550
551 AT_DATA([configure.ac],
552 [[AC_INIT([GNU String], [2.48], [[email protected]],
553 [string], [[https://gstring.example/weird)/path]])
554 AC_OUTPUT
555 ]])
556 AT_CHECK_AUTOCONF
557
558 AT_CLEANUP
559
560
561 ## -------------- ##
562 ## AC_COPYRIGHT. ##
563 ## -------------- ##
564
565 # Ensure the FSF notice as well as the user-provided one are present
566 # in the head of the testsuite as well as the --version output.
567
568 AT_SETUP([AC@&t@_COPYRIGHT])
569
570 AT_DATA([configure.ac],
571 [[AC_INIT([GNU fu], [1.0])
572 AC_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
573 words that may be matched by scanners for legal things,
574 causing extra work for distributors.
575 Multi-line values should be supported.
576 ]])
577 AC_OUTPUT
578 ]])
579
580 AT_CHECK_AUTOCONF
581 AT_CHECK_CONFIGURE([--version], [], [stdout])
582 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
583 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
584 AT_CHECK([sed -ne 50q -e '/Copyright/{' -e N -e N -e N -e N -e 's/#//g' ]dnl
585 [ -e 's/\n//g' -e p -e '}' configure ]dnl
586 [ | grep 'Copyright.*Free Software Foundation'],
587 [], [ignore])
588 AT_CHECK([sed 50q configure | grep 'This is just a test notice'], [], [ignore])
589
590 AT_CLEANUP
591
592
593 ## ---------------- ##
594 ## AC_CACHE_CHECK. ##
595 ## ---------------- ##
596
597 # Make sure AC_CACHE_CHECK is silent with -q.
598 # Also make sure we warn about cache id's not named with '_cv_'.
599
600 AT_SETUP([AC_CACHE_CHECK])
601 AT_KEYWORDS([CONFIG_SITE])
602
603 AT_DATA([configure.ac],
604 [[AC_INIT
605 # m4_define([ac_nothing], [ac_cv_absolutely_nothing])
606 AC_CACHE_CHECK([for nothing],
607 [ac_nothing],
608 [ac_nothing=found])
609
610 AC_MSG_CHECKING([for some other variable])
611 commands_to_set_it_was_run=false
612 AC_CACHE_VAL([my_cv_variable], [
613 # FOO
614 commands_to_set_it_was_run=true
615 my_cv_variable=true
616 ])
617 AC_MSG_RESULT([$my_cv_variable])
618
619 # Ensure that the result is available at this point.
620 if ${my_cv_variable+false} :; then
621 AC_MSG_ERROR([AC@&@&t@t@_CACHE_VAL did not ensure that the cache variable was set])
622 fi
623
624 AC_OUTPUT
625 ]])
626
627 AT_CHECK_AUTOCONF([], [], [], [stderr])
628 AT_CHECK([grep 'must contain _cv_ to be cached' stderr], [], [ignore])
629
630 # Do not warn about defines:
631 sed 's/^# m4_define/m4_define/' configure.ac > t
632 mv -f t configure.ac
633 AT_CHECK_AUTOCONF
634 AT_CHECK_CONFIGURE([-q])
635
636 sed '/m4_define/d; s/ac_nothing/ac_cv_nothing/' configure.ac > t
637 mv -f t configure.ac
638 AT_CHECK_AUTOCONF
639 AT_CHECK_CONFIGURE([-q])
640
641 # Print a message saying that the result was cached, iff it was cached.
642 AT_CHECK_CONFIGURE([], [], [stdout])
643 AT_CHECK([grep 'cached' stdout], [1])
644 AT_CHECK_CONFIGURE([my_cv_variable='yes it is set'], [], [stdout])
645 AT_CHECK([grep 'cached.*yes it is set' stdout], [], [ignore])
646
647 # --cache-file is honored and has caching semantics.
648 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
649 AT_CHECK([grep 'cached' stdout], [1])
650 AT_CHECK([test ! -f config.cache])
651 AT_CHECK([grep 'my_cv_variable.*true' foobar.cache], [], [ignore])
652 AT_CHECK_CONFIGURE([--cache-file=foobar.cache], [], [stdout])
653 AT_CHECK([grep 'some other variable.*cached.*true' stdout], [], [ignore])
654
655 # A setting on the command line overrides the cache.
656 AT_CHECK_CONFIGURE([--cache-file=foobar.cache my_cv_variable='override'], [], [stdout])
657 AT_CHECK([grep 'cached.*override' stdout], [], [ignore])
658 AT_CHECK([grep 'my_cv_variable.*override' foobar.cache], [], [ignore])
659
660 # Values containing braces need special internal treatment.
661 AT_CHECK_CONFIGURE([-C ac_cv_nothing='{' my_cv_variable='contains } brace'],
662 [], [stdout])
663 AT_CHECK([grep 'ac_cv_nothing.*{' config.cache], [], [ignore])
664 AT_CHECK([grep 'my_cv_variable.*contains } brace' config.cache], [], [ignore])
665 AT_CHECK_CONFIGURE([-C], [], [stdout])
666 AT_CHECK([grep 'nothing.*{' stdout], [], [ignore])
667 AT_CHECK([grep 'some other variable.*contains } brace' stdout], [], [ignore])
668 rm -f config.cache
669
670 # Diagnose common side-effects that are errors in COMMANDS-TO-SET-IT:
671 sed 's/^# FOO/AC_DEFINE([some-define], [1], [oooh.])/' configure.ac > t
672 mv -f t configure.ac
673 AT_CHECK_AUTOCONF([], [], [], [stderr])
674 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
675
676 sed 's/^AC_DEFINE.*/AC_SUBST([some_substitution], [oooh.])/' configure.ac > t
677 mv -f t configure.ac
678 AT_CHECK_AUTOCONF([], [], [], [stderr])
679 AT_CHECK([grep 'suspicious.*AC_SUBST' stderr], [], [ignore])
680
681 # Ensure the examples from the manual work as intended.
682 # Taken from autoconf.texi:Caching Results
683 AT_DATA([configure.ac],
684 [[AC_INIT
685 AC_DEFUN([AC_SHELL_TRUE],
686 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
687 [my_cv_shell_true_works=no
688 (true) 2>/dev/null && my_cv_shell_true_works=yes
689 if test "x$my_cv_shell_true_works" = xyes; then
690 AC_DEFINE([TRUE_WORKS], [1],
691 [Define if 'true(1)' works properly.])
692 fi])
693 ])
694 AC_SHELL_TRUE
695 ]])
696 AT_CHECK_AUTOCONF([-Werror], [1], [], [stderr])
697 AT_CHECK([grep 'suspicious.*AC_DEFINE' stderr], [], [ignore])
698
699 # Taken from autoconf.texi:Caching Results
700 AT_DATA([configure.ac],
701 [[AC_INIT
702 AC_DEFUN([AC_SHELL_TRUE],
703 [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
704 [my_cv_shell_true_works=no
705 (true) 2>/dev/null && my_cv_shell_true_works=yes])
706 if test "x$my_cv_shell_true_works" = xyes; then
707 AC_DEFINE([TRUE_WORKS], [1],
708 [Define if 'true(1)' works properly.])
709 fi
710 ])
711 AC_SHELL_TRUE
712 AC_OUTPUT
713 ]])
714 AT_CHECK_AUTOCONF([-Werror])
715 AT_CHECK_CONFIGURE([-C], [], [stdout])
716 AT_CHECK([grep my_cv_shell_true_works config.cache], [], [ignore])
717 AT_CHECK([grep 'true.*works.*yes' stdout], [], [ignore])
718
719 AT_CHECK_CONFIGURE([--config-cache], [], [stdout])
720 AT_CHECK([grep 'true.*works.*cached.*yes' stdout], [], [ignore])
721
722 # config.status only pays attention to the cache file with --recheck.
723 AT_CHECK([./config.status], [], [stdout])
724 AT_CHECK([grep cache stdout], [1])
725 AT_CHECK([./config.status --recheck], [], [stdout])
726 AT_CHECK([grep cache stdout], [0], [ignore])
727
728 # By default, configure uses no cache file, neither loading nor updating it.
729 : > a-stamp-file
730 AT_CHECK_CONFIGURE([], [], [stdout])
731 AT_CHECK([grep cache stdout], [1])
732 AT_CHECK([test config.cache -ot a-stamp-file])
733
734 # Using a symlinked cache file works.
735 : > cache
736 rm -f config.cache
737 AS_LN_S([cache], [config.cache])
738 AT_CHECK_CONFIGURE([-C])
739 # Either the system does not support symlinks, or the symlinked-to file
740 # should be updated.
741 AT_CHECK([test -s cache || test ! -h config.cache])
742
743 # config.site can specify a site-wide cache, accumulating information.
744 # Also test that we don't run afoul of sourcing a file with leading -.
745 AT_DATA([-config.site],
746 [[cache_file=sitecache
747 ]])
748 AT_DATA([sitecache],
749 [[my_cv_some_preset_cache_var=yes
750 ]])
751 CONFIG_SITE=-config.site
752 export CONFIG_SITE
753 AT_CHECK_CONFIGURE
754 AT_CHECK([grep my_cv_some_preset_cache_var sitecache], [], [ignore])
755 AT_CHECK([grep my_cv_shell_true_works sitecache], [], [ignore])
756 AT_CHECK_CONFIGURE([], [], [stdout])
757 AT_CHECK([grep 'whether true.*works.*cached' stdout], [], [ignore])
758
759 dnl Until we can find a way to avoid catastrophic failure,
760 dnl skip the rest of this test on such shells.
761 echo 'if' > syntax
762 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
763 0|"") exit 77;; esac'], [0], [ignore], [ignore])
764
765 # Check that config cache scripts must be well-formed.
766 AT_DATA([bad.site],
767 [[fi
768 ]])
769 CONFIG_SITE=$PWD/bad.site
770 AT_CHECK_CONFIGURE([ || exit 1], [1], [stdout], [stderr])
771 AT_CHECK([grep 'failed to load site script' stderr], [], [ignore], [ignore],
772 [AT_CHECK([grep 'whether true' stdout], [1])])
773
774 # However, a missing file is ignored.
775 CONFIG_SITE=./no-such-file
776 AT_CHECK_CONFIGURE
777
778 # Check that multiple files are loaded
779 AT_DATA([first.site],
780 [[my_cv_shell_true_works=no
781 ]])
782 AT_DATA([second.site],
783 [[my_cv_shell_true_works=maybe
784 ]])
785 CONFIG_SITE="$PWD/first.site $PWD/second.site"
786 AT_CHECK_CONFIGURE([], [], [stdout])
787 AT_CHECK([grep 'whether true.*works.*cached.*maybe' stdout], [], [ignore])
788
789 AT_CLEANUP
790
791
792 ## --------------- ##
793 ## AC_CACHE_LOAD. ##
794 ## --------------- ##
795
796 # Test AC_CACHE_LOAD.
797
798 AT_SETUP([AC_CACHE_LOAD])
799
800 AT_DATA([configure.ac],
801 [[AC_INIT
802 $some_test_code
803 AC_CACHE_LOAD
804 AC_MSG_NOTICE([some_cv_variable is $some_cv_variable])
805 AC_OUTPUT
806 ]])
807 AT_CHECK_AUTOCONF
808 AS_UNSET([some_test_code])
809 AT_DATA([new-cache],
810 [[some_cv_variable=value-from-new-cache
811 ]])
812 AT_CHECK_CONFIGURE([some_test_code='eval cache_file=new-cache'], [], [stdout])
813 AT_CHECK([grep 'some_cv_variable.*value-from-new-cache' stdout], [], [ignore])
814
815 AT_CLEANUP
816
817
818 ## ---------------- ##
819 ## AC_COMPUTE_INT. ##
820 ## ---------------- ##
821
822 # Make sure AC_COMPUTE_INT fails properly.
823
824 AT_SETUP([AC_COMPUTE_INT])
825
826 AT_DATA([configure.ac],
827 [[AC_INIT
828 AC_COMPUTE_INT([invalid_expression],
829 [**0**],
830 [],
831 [invalid_expression=failed])
832 test "$invalid_expression" = failed ||
833 AC_MSG_ERROR([**0** evaluated to $invalid_expression instead of failing])
834 AC_OUTPUT
835 ]])
836
837 AT_CHECK_AUTOCONF
838 AT_CHECK_CONFIGURE
839
840 AT_CLEANUP
841
842
843 ## ---------------- ##
844 ## AC_TRY_COMMAND. ##
845 ## ---------------- ##
846
847 AT_SETUP([AC_TRY_COMMAND])
848
849 AT_DATA([configure.ac],
850 [[AC_INIT
851
852 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
853 echo "The Hat in the Cat" >&2) |
854 grep \^The\ Cat\ in\ the\ Hat\$ >/dev/null]); then
855 :
856 else
857 AC_MSG_ERROR([didn't see the Cat in the Hat])
858 fi
859
860 if AC_TRY_COMMAND([(echo "The Cat in the Hat";
861 echo "The Hat in the Cat" >&2) |
862 grep \^The\ Hat\ in\ the\ Cat\$ >/dev/null]); then
863 AC_MSG_ERROR([saw the Hat in the Cat])
864 fi
865
866 AC_OUTPUT
867 ]])
868
869 AT_CHECK_AUTOCONF
870 AT_CHECK_CONFIGURE([-q])
871
872 AT_CLEANUP
873
874
875 ## ------------ ##
876 ## Input/Output ##
877 ## ------------ ##
878
879 AT_SETUP([Input/Output])
880
881 AT_DATA([configure.ac],
882 [[AC_INIT
883 cat <&AS@&t@_ORIGINAL_STDIN_FD >&AS@&t@_MESSAGE_FD
884 AC_OUTPUT
885 ]])
886 AT_CHECK_AUTOCONF
887 AT_CHECK([echo Hello |
888 ./configure $configure_options |
889 grep -v '^configure: '],,
890 [Hello
891 ])
892 AT_CHECK([echo Hello | ./configure $configure_options --silent])
893
894 AT_CLEANUP
895
896
897 ## ------------------- ##
898 ## configure arguments ##
899 ## ------------------- ##
900
901 AT_SETUP([configure arguments])
902
903 AT_DATA([configure.ac],
904 [[AC_INIT
905 echo "$@"
906 AC_OUTPUT
907 ]])
908
909 AT_CHECK_AUTOCONF
910 AT_CHECK_CONFIGURE([FOO=bar --enable-baz --without-zork --silent], [0], [stdout], [ignore])
911 AT_CHECK([grep 'FOO=bar --enable-baz --without-zork --silent' stdout], [0], [ignore], [ignore])
912
913 dnl check that syntax error is detected
914 AT_CHECK_CONFIGURE([=], [1], [], [ignore], [ignore])
915 AT_CHECK_CONFIGURE([1=2], [1], [], [ignore], [ignore])
916
917 AT_CLEANUP
918
919
920 ## ------------------------------ ##
921 ## AC_ARG_ENABLE and AC_ARG_WITH. ##
922 ## ------------------------------ ##
923
924 AT_SETUP([AC_ARG_ENABLE and AC_ARG_WITH])
925
926 AT_DATA_M4SH([configure.ac],
927 [[AC_INIT
928 # Taken from autoconf.texi:Pretty Help Strings.
929 AC_ARG_WITH([foo],
930 [AS_HELP_STRING([--with-foo],
931 [use foo (default is no)])],
932 [use_foo=$withval],
933 [use_foo=no])
934 AC_ARG_WITH([c++],
935 [AS_HELP_STRING([--with-c++],
936 [with c++])],
937 [choice_with=$withval])
938 AC_ARG_ENABLE([c++],
939 [AS_HELP_STRING([--enable-c++],
940 [enable c++])],
941 [choice_enable=$enableval])
942 echo "use_foo: $use_foo"
943 echo "with_c++: $with_c__, $choice_with"
944 echo "enable_c++: $enable_c__, $choice_enable"
945 AC_OUTPUT
946 ]])
947
948 AT_CHECK_AUTOCONF
949 AT_CHECK_CONFIGURE([--help | grep foo], [0],
950 [[ --with-foo use foo (default is no)
951 ]], [ignore])
952 AT_CHECK_CONFIGURE([--with-foo=yes --with-c++ --disable-c++],
953 [], [stdout], [ignore])
954 AT_CHECK([grep 'use_foo: yes' stdout], [], [ignore])
955 AT_CHECK([grep 'with_c++: yes, yes' stdout], [], [ignore])
956 AT_CHECK([grep 'enable_c++: no, no' stdout], [], [ignore])
957 AT_CHECK([grep 'unrecognized option' stdout], [1])
958 AT_CHECK_CONFIGURE([--without-foo --with-c++=no --enable-c++=maybe],
959 [], [stdout], [ignore])
960 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
961 AT_CHECK([grep 'with_c++: no, no' stdout], [], [ignore])
962 AT_CHECK([grep 'enable_c++: maybe, maybe' stdout], [], [ignore])
963 AT_CHECK([grep 'unrecognized option' stdout], [1])
964 AT_CHECK_CONFIGURE([], [], [stdout], [ignore])
965 AT_CHECK([grep 'use_foo: no' stdout], [], [ignore])
966 AT_CHECK([grep 'with_c++: , $' stdout], [], [ignore])
967 AT_CHECK([grep 'enable_c++: , $' stdout], [], [ignore])
968 AT_CHECK([grep 'unrecognized option' stdout], [1])
969
970 AT_CLEANUP
971
972
973 ## --------------------- ##
974 ## configure directories ##
975 ## --------------------- ##
976
977 AT_SETUP([configure directories])
978
979 AT_DATA([foo.in],
980 [[prefix=@prefix@
981 exec_prefix=@exec_prefix@
982 libdir=@libdir@
983 ]])
984
985 AT_DATA([configure.ac],
986 [[AC_INIT
987 AC_CONFIG_FILES([foo])
988 AC_OUTPUT
989 ]])
990
991 AT_CHECK_AUTOCONF
992 dnl check that relative paths are rejected
993 AT_CHECK_CONFIGURE([--libdir=.], [1], [ignore], [stderr])
994 AT_CHECK([grep 'expected an absolute directory name for --libdir: \.' stderr],
995 [0], [ignore])
996
997 dnl check that extra slashes are stripped, and that defaults are not expanded
998 AT_CHECK_CONFIGURE([--prefix=/usr//])
999 AT_CHECK([cat foo], [0], [[prefix=/usr
1000 exec_prefix=${prefix}
1001 libdir=${exec_prefix}/lib
1002 ]])
1003
1004 AT_CLEANUP
1005
1006 ## ---------- ##
1007 ## AC_SUBST. ##
1008 ## ---------- ##
1009
1010 AT_SETUP([AC_SUBST])
1011 AT_KEYWORDS([AS@&t@_IDENTIFIER_IF])
1012
1013 # Check that a valid variable name is used.
1014 AT_DATA([configure.ac],
1015 [[AC_INIT([test], [1])
1016 AC_SUBST([1], [bar])
1017 AC_OUTPUT
1018 ]])
1019 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1020 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1021
1022 AT_DATA([configure.ac],
1023 [[AC_INIT([test], [1])
1024 AC_SUBST([], [bar])
1025 AC_OUTPUT
1026 ]])
1027 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1028 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1029
1030 AT_DATA([configure.ac],
1031 [[AC_INIT([test], [1])
1032 AC_SUBST([*], [bar])
1033 AC_OUTPUT
1034 ]])
1035 AT_CHECK_AUTOCONF([], [1], [], [stderr])
1036 AT_CHECK([grep 'not a valid shell variable' stderr], [], [ignore])
1037
1038 # Make sure AC_SUBST handles variables as expected.
1039 AT_DATA([file.in],
1040 [[@FOO@
1041 @BAR@
1042 FOO
1043 ]])
1044 AT_DATA([configure.ac],
1045 [[AC_INIT([test], [0])
1046 m4_define([FOO], [baz])
1047 AC_SUBST([FOO], [bar])
1048 BAR=one
1049 AC_SUBST([B@&t@AR])
1050 BAR=two
1051 AC_CONFIG_FILES([file])
1052 AC_OUTPUT
1053 ]])
1054
1055 AT_CHECK_AUTOCONF([], [], [], [stderr])
1056 AT_CHECK_CONFIGURE
1057 AT_CHECK([cat file], [],
1058 [[bar
1059 two
1060 FOO
1061 ]])
1062
1063 AT_CLEANUP
1064
1065 ## ----------------------------------- ##
1066 ## configure with closed standard fds ##
1067 ## ----------------------------------- ##
1068
1069 AT_SETUP([configure with closed standard fds])
1070 AT_KEYWORDS([AS@&t@_INIT])
1071
1072 # Create a configure script that runs a relatively complicated but
1073 # self-contained test. Run it.
1074 AT_CONFIGURE_AC([[AC_PROG_CC]])
1075 AT_CHECK_AUTOCONF
1076 AT_CHECK_AUTOHEADER
1077 AT_CHECK_CONFIGURE([], [], [stdout], [stderr])
1078 AT_CHECK_ENV
1079
1080 mv stdout stdout-expected
1081 mv stderr stderr-expected
1082 mv state-env.after state-env-expected
1083 mv config.status config-status-expected
1084 mv config.h config-h-expected
1085
1086 # Run it again with stdin (fd 0) closed.
1087 # There should be no change to the stdout or stderr output and the
1088 # result of configuration should be the same.
1089
1090 AT_CHECK_CONFIGURE([ 0<&- ], [], [stdout], [stderr])
1091 AT_CHECK_ENV
1092 AT_CMP([stdout-expected], [stdout])
1093 AT_CMP([stderr-expected], [stderr])
1094 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1095
1096 mv stdout stdout-closed-0
1097 mv stderr stderr-closed-0
1098 mv state-env.after state-env-closed-0
1099 mv config.status config-status-closed-0
1100 mv config.h config-h-closed-0
1101
1102 # Run it again with stdout (fd 1) closed.
1103 # There should be no change to the stderr output and the
1104 # result of configuration should be the same. (Any output
1105 # that would have gone to stdout, of course, is lost.)
1106
1107 AT_CHECK_CONFIGURE([ 1>&- ], [], [stdout], [stderr])
1108 AT_CHECK_ENV
1109 AT_CHECK([test -f stdout && test ! -s stdout])
1110 AT_CMP([stderr-expected], [stderr])
1111 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1112
1113 mv stdout stdout-closed-1
1114 mv stderr stderr-closed-1
1115 mv state-env.after state-env-closed-1
1116 mv config.status config-status-closed-1
1117 mv config.h config-h-closed-1
1118
1119 # Run it again with stderr (fd 2) closed.
1120 # There should be no change to the stdout output and the
1121 # result of configuration should be the same. (Any output
1122 # that would have gone to stderr, of course, is lost.)
1123
1124 AT_CHECK_CONFIGURE([ 2>&- ], [], [stdout], [stderr])
1125 AT_CHECK_ENV
1126 AT_CMP([stdout-expected], [stdout])
1127 AT_CHECK([test -f stderr && test ! -s stderr])
1128 AT_CONFIG_CMP([state-env-expected], [state-env.after])
1129
1130 mv stdout stdout-closed-2
1131 mv stderr stderr-closed-2
1132 mv state-env.after state-env-closed-2
1133 mv config.status config-status-closed-2
1134 mv config.h config-h-closed-2
1135
1136 AT_CLEANUP