summaryrefslogtreecommitdiff
path: root/gnu/dist/autoconf/tests/m4sh.at
blob: 8b67f93ce230d70b54f8e8f61a749d13ededc341 (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
#							-*- Autotest -*-

AT_BANNER([M4sh.])

# Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# Used in many tests.
m4_pattern_allow([^AS_EXIT$])

## ---------------- ##
## LINENO support.  ##
## ---------------- ##

AT_SETUP([LINENO])

# We cannot unset LINENO with Zsh, yet this test case relies on
# unsetting LINENO to compare its result when (i) LINENO is supported
# and when (ii) it is not.
# So just skip if the shell is ZSH.
AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)

# AT_DATA_LINENO(FILENAME,
#                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
# ----------------------------------------------------------------
# Produce the FILENAME M4sh script which uses the COUNTER LINENO or
# _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
# UNSET-LINENO.
#
# Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
#  or                     = [__OLINE__],  [_oline__]
#
# instead of the obvious $LINENO and __oline__, because they would
# be replaced in the test suite itself, even before creating these
# scripts.  For the same reason, grep for LINENO and _oline__ (sic).
#
# UNSET-LINENO is a shell condition to make sure the scripts have the
# same number of lines in the output, so that their outputs be identical.
m4_define([AT_DATA_LINENO],
[AT_DATA([$1.tas],
[[AS@&t@_INIT
if $2; then
  AS@&t@_UNSET([LINENO])
fi
_AS@&t@_PREPARE
echo "Line: $3"
grep 'Line: .*$4' $[0] >/dev/null ||
  AS@&t@_ERROR([cannot find original script])
exit 0
]])
# If occurrences of $LINENO or __oline__ were wanted, create them.
sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
AT_CHECK([autom4te -l m4sh $1.as -o $1])
])# AT_DATA_LINENO

# `_oline_', once processed and ran, produces our reference.
# We check that we find ourselves by looking at a string which is
# available only in the original script: `_oline_'.
AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
AT_CHECK([./reference], 0, [stdout])

# The reference:
mv stdout expout

# Now using a maybe-functioning LINENO, with different call conventions.
# Be sure to be out of the PATH.
AT_CHECK([mkdir test || exit 77])

AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
AT_CHECK([./test/test-1],                          0, [expout])
AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
						   0, [expout])
AT_CHECK([sh ./test/test-1],                       0, [expout])

# Now using a disabled LINENO, with different call conventions.
AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
AT_CHECK([./test/test-2],                          0, [expout])
AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
						   0, [expout])
AT_CHECK([sh ./test/test-2],                       0, [expout])

AT_CLEANUP



## ------------ ##
## AS_DIRNAME.  ##
## ------------ ##

# Build nested dirs.
AT_SETUP([[AS@&t@_DIRNAME]])

AT_DATA_M4SH([script.as],
[[AS_INIT

# The EXPR variant is allowed to fail if `expr' was considered as too
# weak for us, in which case `as_expr=false'.
m4_define([DIRNAME_TEST],
[dir=`AS_DIRNAME([$1])`
test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
  echo "dirname($1) = $dir instead of $2" >&2

if test "$as_expr" != false; then
  dir=`AS_DIRNAME_EXPR([$1])`
  test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
    echo "dirname_expr($1) = $dir instead of $2" >&2
fi

dir=`AS_DIRNAME_SED([$1])`
test "$dir" = "$2" ||
test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
  echo "dirname_sed($1) = $dir instead of $2" >&2])

DIRNAME_TEST([/],		[/])
DIRNAME_TEST([//],		[//],	[/])
DIRNAME_TEST([///],		[/])
DIRNAME_TEST([//1],		[//],	[/])
DIRNAME_TEST([/1],		[/])
DIRNAME_TEST([./1],		[.])
DIRNAME_TEST([../../2],		[../..])
DIRNAME_TEST([//1/],		[//],	[/])
DIRNAME_TEST([/1/],		[/])
DIRNAME_TEST([./1/],		[.])
DIRNAME_TEST([../../2],		[../..])
DIRNAME_TEST([//1/3],		[//1])
DIRNAME_TEST([/1/3],		[/1])
DIRNAME_TEST([./1/3],		[./1])
DIRNAME_TEST([../../2/3],	[../../2])
DIRNAME_TEST([//1/3///],	[//1])
DIRNAME_TEST([/1/3///],		[/1])
DIRNAME_TEST([./1/3///],	[./1])
DIRNAME_TEST([../../2/3///],	[../../2])
DIRNAME_TEST([//1//3/],		[//1])
DIRNAME_TEST([/1//3/],		[/1])
DIRNAME_TEST([./1//3/],		[./1])
DIRNAME_TEST([../../2//3/],	[../../2])
AS_EXIT(0)
]])

AT_CHECK_M4SH
AT_CHECK([./script])

AT_CLEANUP



## ------------- ##
## AS_BASENAME.  ##
## ------------- ##

# Build nested dirs.
AT_SETUP([[AS@&t@_BASENAME]])

AT_DATA_M4SH([script.as],
[[AS_INIT

m4_define([BASENAME_TEST],
[base=`AS_BASENAME([$1])`
test "$base" = "$2" ||
  echo "basename($1) = $base instead of $2" >&2

base=`AS_BASENAME_SED([$1])`
test "$base" = "$2" ||
  echo "basename_sed($1) = $base instead of $2" >&2])

BASENAME_TEST([//1],             [1])
BASENAME_TEST([/1],              [1])
BASENAME_TEST([./1],             [1])
BASENAME_TEST([../../2],         [2])
BASENAME_TEST([//1/],            [1])
BASENAME_TEST([/1/],             [1])
BASENAME_TEST([./1/],            [1])
BASENAME_TEST([../../2],         [2])
BASENAME_TEST([//1/3],           [3])
BASENAME_TEST([/1/3],            [3])
BASENAME_TEST([./1/3],           [3])
BASENAME_TEST([../../2/3],       [3])
BASENAME_TEST([//1/3///],        [3])
BASENAME_TEST([/1/3///],         [3])
BASENAME_TEST([./1/3///],        [3])
BASENAME_TEST([../../2/3///],    [3])
BASENAME_TEST([//1//3/],         [3])
BASENAME_TEST([/1//3/],          [3])
BASENAME_TEST([./1//3/],         [3])
BASENAME_TEST([a.c],             [a.c])
BASENAME_TEST([a.c/],            [a.c])
BASENAME_TEST([/a.c/],           [a.c])
BASENAME_TEST([/1/a.c],          [a.c])
BASENAME_TEST([/1/a.c/],         [a.c])
BASENAME_TEST([/1/../a.c],       [a.c])
BASENAME_TEST([/1/../a.c/],      [a.c])
BASENAME_TEST([./1/a.c],         [a.c])
BASENAME_TEST([./1/a.c/],        [a.c])
AS_EXIT(0)
]])

AT_CHECK_M4SH
AT_CHECK([./script])

AT_CLEANUP



## ------------ ##
## AS_MKDIR_P.  ##
## ------------ ##

# Build nested dirs.
AT_SETUP([[AS@&t@_MKDIR_P]])

AT_DATA_M4SH([script.as],
[[AS_INIT

pwd=`pwd`
set -e
# Absolute
AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
test -d "$pwd/1/2/3/4/5/6" ||
  AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
# Relative
AS_MKDIR_P(["a/b/c/d/e/f"])
test -d a/b/c/d/e/f ||
  AS_ERROR([a/b/c/d/e/f has not been properly created])
AS_EXIT(0)
]])

AT_CHECK_M4SH
AT_CHECK([./script])

AT_CLEANUP




## ----------------------------- ##
## Negated classes in globbing.  ##
## ----------------------------- ##

# It is known that `[^...]' is not universally supported, but it is
# unknown for `[!...]'.

AT_SETUP([Negated classes in globbing])

AT_DATA_M4SH([script.as],
[[AS_INIT

case 'with!two!bangs' in
  *[[!a-z]]*) ;;
           *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
esac

case without in
  *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
esac
]])

AT_CHECK_M4SH
AT_CHECK([./script])

AT_CLEANUP