summaryrefslogtreecommitdiffstats
path: root/tests/torture.at
blob: 786efd08e646147d6f34f369b63e12857f90222d (plain)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#							-*- autoconf -*-

AT_BANNER([[Testing config.status.

## ---------------------------------------------------------------- ##
## This section of torture tests is trying to make Autoconf produce ##
## failing `configure' scripts, which must never happen.  If one of ##
## these tests ever fails, it is extremely important that you       ##
## report the failure to dickey@invisible-island.net.               ##
## ---------------------------------------------------------------- ##]])


## ------------ ##
## AC_ARG_VAR.  ##
## ------------ ##

# AT_CHECK_AC_ARG_VAR(FIRST-VALUE, SECOND-VALUE)
# ----------------------------------------------
# Check that AC_ARG_VAR caches the latest values, diagnoses
# inconsistances, and arms config.status.
m4_define([AT_CHECK_AC_ARG_VAR],
[rm -f config.cache

# Initial value.
m4_ifval([$1],
         [precious='$1'; export precious],
         [unset precious])
AT_CHECK_CONFIGURE([--config-cache])
AT_CHECK([cat file], [], [`$1'
])

# Testing --recheck.
unset precious
AT_CHECK([./config.status --recheck], [], [ignore])
AT_CHECK([./config.status], [], [ignore])
AT_CHECK([cat file], [], [`$1'
])

# Second value.
m4_ifval([$2],
         [precious='$2'; export precious],
         [unset precious])
AT_CHECK_CONFIGURE([--config-cache], [1], [], [ignore])

])# AT_CHECK_AC_ARG_VAR


AT_SETUP([AC_ARG_VAR])

# We don't want to run this test if this shell doesn't support
# `unset'.
AT_CHECK([
if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
  exit 0
else
  exit 77
fi
])

AT_DATA([configure.ac],
[[AC_INIT
AC_ARG_VAR([precious], [this variable costs a lot])
AC_OUTPUT(file)
]])

AT_DATA([file.in],
[[`@precious@'
]])

AT_CHECK_AUTOCONF

# Set a precious variable
AT_CHECK_AC_ARG_VAR([], [apple of my eye])

# Unset a precious variable
AT_CHECK_AC_ARG_VAR([apple of my eye], [])

# Change a precious variable
AT_CHECK_AC_ARG_VAR([apple of my eye], [orange of my eye])

AT_CLEANUP




## ---------------------------------------------- ##
## AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS.  ##
## ---------------------------------------------- ##

AT_SETUP([AC_CONFIG_FILES, HEADERS, LINKS and COMMANDS])

AT_DATA(configure.ac,
[[AC_INIT
rm -rf header var-header file var-file link var-link command var-command
echo 'OK' >input

# Be sure to also stress the associated INIT-CMDS.
case $what_to_test in
 header)
   AC_CONFIG_HEADERS(header:input);;
 var-header)
   AC_CONFIG_HEADERS(var-header:$header_in, [], [header_in=input]);;

 file)
   AC_CONFIG_FILES(file:input);;
 var-file)
   AC_CONFIG_FILES(var-file:$file_in, [], [file_in=input]);;

 command)
   AC_CONFIG_COMMANDS(command:input,
                      [cp input command]);;
 var-command)
   AC_CONFIG_COMMANDS(var-command:$command_in,
                      [cp $command_in var-command], [command_in=input]);;

 link)
   AC_CONFIG_LINKS(link:input);;
 var-link)
   AC_CONFIG_LINKS(var-link:$link_in, [], [link_in=input]);;
esac
AC_OUTPUT
]])

AT_CHECK_AUTOCONF


# AT_CHECK_CONFIG_CREATION(THING = (header | link | file | command))
# ------------------------------------------------------------------
# Check that THING and var-THING (which uses variables in AC_CONFIG_THING)
# are properly created, with the right content.
# Use `grep OK' instead of a simple `cat' to avoid banners such as in
# AC_CONFIG_HEADERS.
m4_define([AT_CHECK_CONFIG_CREATION],
[AT_CHECK_CONFIGURE([what_to_test=$1])
AT_CHECK([ls header var-header file var-file command var-command link var-link 2>/dev/null],
         [ignore], [$1
])
AT_CHECK([grep OK $1], [], [OK
])

AT_CHECK_CONFIGURE([what_to_test=var-$1 --no-create])
# config.status might be stupidly expecting data on stdin, if it's
# really broken...
AT_CHECK([./config.status var-$1 </dev/null], [], [ignore])
AT_CHECK([ls header var-header file var-file command var-command link var-link 2>/dev/null],
         [ignore], [var-$1
])
AT_CHECK([grep OK var-$1], [], [OK
])
])# AT_CHECK_CONFIG_CREATION


# Create a file
AT_CHECK_CONFIG_CREATION(file)

# Create a header
AT_CHECK_CONFIG_CREATION(header)

# Execute a command
AT_CHECK_CONFIG_CREATION(command)

# Create a link
AT_CHECK_CONFIG_CREATION(link)

AT_CLEANUP(header file link commandvar-header var-file var-link var-command
           input)



## ------------------- ##
## Missing templates.  ##
## ------------------- ##

# Check that config.status detects missing input files
AT_SETUP([Missing templates])

AT_DATA(configure.ac,
[[AC_INIT
AC_CONFIG_FILES([nonexistent])
AC_OUTPUT
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([], [1], [],
[[config.status: error: cannot find input file: nonexistent.in
]])
# Make sure that the output file doesn't exist
AT_CHECK([test -f nonexistent], 1)

AT_CLEANUP




## ---------------------- ##
## configure invocation.  ##
## ---------------------- ##

# Check that `configure' and `config.status' honor their interface.
#
# We run `./configure one=val1 --enable-two=val2 --with-three=val3'
# and verify that (i) `configure' correctly receives the arguments and
# (ii) correctly passes them to `config.status', which we check by
# running `config.status --recheck'.

AT_SETUP([configure invocation])

AT_DATA(configure.ac,
[[AC_INIT
echo "result=$one$enable_two$with_three"
AC_OUTPUT
]])

AT_CHECK_AUTOCONF

AT_CHECK_CONFIGURE([one=one --enable-two=two --with-three=three |
                     sed -n -e 's/^result=//p'], 0,
                   [onetwothree
])
AT_CHECK([./config.status --recheck | sed -n 's/^result=//p'], 0,
         [onetwothree
])

AT_CHECK_CONFIGURE([one="\"'$ " --enable-two="\" ' $" --with-three=" \"'$"|
                      sed -n -e 's/^result=//p'], 0,
                   ["'$ " ' $ "'$
])
AT_CHECK([./config.status --recheck | sed -n 's/^result=//p'], 0,
         ["'$ " ' $ "'$
])

AT_CLEANUP(configure config.status config.log config.cache)



## -------------------------------------------- ##
## Check that `#define' templates are honored.  ##
## -------------------------------------------- ##

# Use various forms of `#define' templates, and make sure there are no
# problems when a symbol is prefix of another.

AT_SETUP([#define header templates])

AT_DATA([configure.ac],
[[AC_INIT
AC_CONFIG_HEADERS(config.h:config.hin)

# I18n of dummy variables: their French translations.
AC_DEFINE(foo, toto)
AC_DEFINE(bar, tata)
AC_DEFINE(baz, titi)
AC_DEFINE(fubar, tutu)

# Symbols which are prefixes of another.
AC_DEFINE(a, A)
AC_DEFINE(aaa, AAA)
AC_DEFINE(aa, AA)
AC_CONFIG_FILES(defs)

# Things included in confdefs.h, but which make no sense in
# config.h, nor in $DEFS.
cat <<\EOF >>confdefs.h
/* Hi Mum! Look, I'm doing C++! */
#ifdef __cplusplus
void exit (int status);
#endif
EOF

# In addition of config.h output a full DEFS
AC_OUTPUT_MAKE_DEFS
DEFS_SAVED=$DEFS
AC_SUBST(DEFS_SAVED)
AC_OUTPUT
]])

AT_DATA([defs.in],
[[@DEFS_SAVED@
]])

AT_DATA([config.hin],
[[#define foo   0
#  define bar bar
#  define baz   "Archimedes was sinking in his baz"
#  define fubar	 	 	 	tutu
#define a B
#define aa BB
#define aaa BBB
#undef a
#undef aa
#undef aaa
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE

AT_DATA([expout],
[[/* config.h.  Generated automatically by configure.  */
#define foo toto
#  define bar tata
#  define baz titi
#  define fubar tutu
#define a A
#define aa AA
#define aaa AAA
#define a A
#define aa AA
#define aaa AAA
]])
AT_CHECK([cat config.h], 0, expout)

# Check the value of DEFS.  Note the leading space.
AT_DATA([expout],
[[-Dfoo=toto -Dbar=tata -Dbaz=titi -Dfubar=tutu -Da=A -Daaa=AAA -Daa=AA]
])

# Because we strip trailing spaces in `testsuite' we can't leave one in
# expout, hence nuke the one left by AC_OUTPUT_MAKE_DEFS.
AT_CHECK([sed -e 's/ $//' defs], 0, expout)

AT_CLEANUP



## ------------------------- ##
## Torturing config.status.  ##
## ------------------------- ##

## Require 100 AC_DEFINE and AC_SUBST with a significantly big value.
## This is mostly to check that Autoconf produces portable sed scripts
## in config.status.  sed is used to skip the first two lines
## `Generated by...'.

AT_SETUP([Torturing config.status])

dnl The value used as a big value for AC_DEFINE.
dnl Don't use sh active chars here, below it is also used in a sh
dnl assignment.
m4_define([AT_BIG_VALUE],
[This value should be long enough to torture the various limits of sed and other tools used by Autoconf.])

m4_define([AT_DESCRIPTION],
[Define to a long string if your `Autoconf' works properly.])


# AT_DUMMY_VAR(NUMBER)
# --------------------
# Build a name used for AC_SUBST and AC_DEFINE.  Put ac_ in it
# so that the check for user name space invasion does not complain
# of the new variables defined.
#
# Note that you should not use the name ac_dummy, because it will be
# turned into ac_uummy during the construction of config.status.  Yes,
# this is admittedly a bug, but it would be too hard to fix this.
# There is really no point in AC_DEFINE a var named ac_d.*.
m4_define([AT_DUMMY_VAR],
[ac_Dummy_[]m4_patsubst([000$1], [.*\(...\)$], [\1])])



AT_DATA([dummy.in],
[m4_for([AT_Count], 1, 100, 1,
[@AT_DUMMY_VAR(AT_Count)@
])])


# ------------ #
# configure.ac #
# ------------ #

AT_DATA(configure.ac,
dnl The following lines transfer AT_DUMMY_VAR, AT_DESCRIPTION, and
dnl AT_BIG_VALUE into the configure.ac as AC_DUMMY_VAR etc.
[[m4_define([AC_DUMMY_VAR],]
m4_dquote(m4_defn([AT_DUMMY_VAR]))[)]]

[[m4_define([AC_DESCRIPTION],]
m4_dquote(m4_defn([AT_DESCRIPTION]))[)]]

[[m4_define([AC_BIG_VALUE],]
m4_dquote(m4_defn([AT_BIG_VALUE]))[)]]

[[# AC_DEFUBST(NAME)
# ----------------
# Related VALUE to NAME both with AC_SUBST and AC_DEFINE.  This is
# used in the torture tests.
m4_defun([AC_DEFUBST],
[AC_DUMMY_VAR($1)="AC_BIG_VALUE"
AC_DEFINE_UNQUOTED(AC_DUMMY_VAR($1), "$AC_DUMMY_VAR($1)",
                   AC_DESCRIPTION)
AC_SUBST(AC_DUMMY_VAR($1))])

AC_INIT
AC_CONFIG_HEADERS(config.h:config.hin)
AC_CONFIG_FILES(dummy)
m4_for(AC_Count, 1, 100, 1,
       [AC_DEFUBST(AC_Count)])
AC_OUTPUT
]])# configure.ac

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE

# Checking that AC_DEFINE worked properly.
AT_DATA(expout,
[m4_for(AT_Count, 1, 100, 1,
[
/* AT_DESCRIPTION */
[#define] AT_DUMMY_VAR(AT_Count) "AT_BIG_VALUE"
])])
AT_CHECK([sed -n '3,$ p' config.h], 0, expout)

# Checking that AC_SUBST worked properly.
AT_DATA(expout,
[m4_for(AT_Count, 1, 100, 1,
[AT_BIG_VALUE
])])

AT_CLEANUP(dummy)


## -------- ##
## srcdir.  ##
## -------- ##

AT_SETUP([srcdir])

rm -rf at-dir
mkdir at-dir
: >at-dir/bar.in
: >foo.in

AT_DATA([configure.ac],
[[AC_INIT

AC_CONFIG_FILES([foo at-dir/bar])

AC_CONFIG_COMMANDS([report],
[test -f $srcdir/configure.ac ||
   AC_MSG_ERROR([cannot find $srcdir/configure.ac])],
                   [srcdir=$srcdir])

AC_OUTPUT
rm -rf foo at-dir/bar
]])

AT_CHECK_AUTOCONF

# In place.
AT_CHECK([./configure], [], [ignore])

# Relative path.
AT_CHECK([cd at-dir && ../configure], [], [ignore])

# Absolute path.
at_here=`pwd`
AT_CHECK([cd at-dir && $at_here/configure], [], [ignore])

AT_CLEANUP(at-dir foo.in foo)


## ----------------- ##
## Signal handling.  ##
## ----------------- ##

AT_SETUP([Signal handling])

AT_DATA([configure.ac],
[[AC_INIT
kill -2 $$
exit 77
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE([], 1, ignore, ignore)

AT_CLEANUP