summaryrefslogtreecommitdiff
path: root/t/internals.tap
blob: eede9748f764b4665721d81a4e8c6c6531ce48e3 (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
#! /bin/sh
# Copyright (C) 2012-2015 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, see <http://www.gnu.org/licenses/>.

# Test some generic Automake-provided internal macros and make functions.

am_create_testdir=empty
. test-init.sh

plan_ 13

# Filter out Automake comments.
grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \
  || fatal_ "fetching makefile fragment headers-vars.am"

# WARNING: there are a lot of embedded tabs in the makefile
# fragments used by this script.  They are all deliberate.
# DO NOT "NORMALIZE" THEM TO SPACES!

i=0
T ()
{
  i=$(($i + 1))
  mkdir T$i.d
  cd T$i.d
  {
    echo 'include ../defn.mk'
    echo 'lower = abcdefghijklmnopqrstuvwxyz'
    echo 'upper = ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    echo 'digits = 0123456789'
  } > Makefile
  cat >> Makefile
  test_name=$1; shift
  command_ok_ "$test_name" $MAKE ${1+"$@"} test
  cd ..
}

T 'sanity check' FOO=ok <<'END'
FOO = ko
test:
	test $(FOO) = ok
	touch sane
END
test -f T1.d/sane || fatal_ "function 'T' is buggy"

T 'am.util.strip-first-word' <<'END'
test:
	test '$(call am.util.strip-first-word,)'                = ''
	test '$(call am.util.strip-first-word,1)'               = ''
	test '$(call am.util.strip-first-word,1 1)'             = '1'
	test '$(call am.util.strip-first-word,1 2)'             = '2'
	test '$(call am.util.strip-first-word,1 2 3 4 5 6 7 8)' = '2 3 4 5 6 7 8'
	test '$(call am.util.strip-first-word,  1	  2	)' = '2'
END

T 'am.util.strip-last-word' <<'END'
test:
	test '$(call am.util.strip-last-word,)'                 = ''
	test '$(call am.util.strip-last-word,1)'                = ''
	test '$(call am.util.strip-last-word,1 1)'              = '1'
	test '$(call am.util.strip-last-word,1 2)'              = '1'
	test '$(call am.util.strip-last-word,1 2 3 4 5 6 7 8)'  = '1 2 3 4 5 6 7'
	test '$(call am.util.strip-last-word,  1	  2	)' = '1'
END

T 'am.util.uniq' <<'END'
test:
	test '$(call am.util.uniq,)'                    = ''
	test '$(call am.util.uniq,1)'                   = '1'
	test '$(call am.util.uniq,1 1)'                 = '1'
	test '$(call am.util.uniq,1 2)'                 = '1 2'
	test '$(call am.util.uniq,2 1)'                 = '2 1'
	test '$(call am.util.uniq,1 2 3)'               = '1 2 3'
	test '$(call am.util.uniq,2 3 1)'               = '2 3 1'
	test '$(call am.util.uniq,1 1 1)'               = '1'
	test '$(call am.util.uniq,1 2 1)'               = '1 2'
	test '$(call am.util.uniq,2 1 1)'               = '2 1'
	test '$(call am.util.uniq,2 1 1)'               = '2 1'
	test '$(call am.util.uniq,2 2 1)'               = '2 1'
	test '$(call am.util.uniq,1 1 1 3 1 1 1)'       = '1 3'
	test '$(call am.util.uniq,3 1 1 4 1 4 1 1)'     = '3 1 4'
	test '$(call am.util.uniq,	1   3 	1  )'   = '1 3'
END

T 'am.util.strip-suffixes' <<'END'
test:
	test '$(call am.util.strip-suffixes,,)'                 = ''
	test '$(call am.util.strip-suffixes, 	  ,)'           = ''
	test '$(call am.util.strip-suffixes,, 	  )'            = ''
	test '$(call am.util.strip-suffixes,  	,   	)'      = ''
	test '$(call am.util.strip-suffixes,x,)'                = ''
	test '$(call am.util.strip-suffixes,x y, 	  )'    = ''
	test '$(call am.util.strip-suffixes,,x y)'              = 'x y'
	test '$(call am.util.strip-suffixes,   	 ,x y)'         = 'x y'
	test '$(call am.util.strip-suffixes,.c,foo.c)'          = 'foo'
	test '$(call am.util.strip-suffixes,.foo,a.foo b.foo)'  = 'a b'
	test '$(call am.util.strip-suffixes, x y, ax ay ax)'    = 'a a a'
	test '$(call am.util.strip-suffixes,x,ax)'              = 'a'
	test '$(call am.util.strip-suffixes,x,xa)'              = 'xa'
	test '$(call am.util.strip-suffixes,x,xx)'              = 'x'
	test '$(call am.util.strip-suffixes,x,xux)'             = 'xu'
	test '$(call am.util.strip-suffixes, .c .c++, \
	        foo.c bar.c++ baz.cxx zap.c)' = 'foo bar baz.cxx zap'
	test '$(call am.util.strip-suffixes, .a .b, \
	        1.a.a 2.a.b 3.b.a 4.b.b)' = '1.a 2.a 3.b 4.b'
	# Corner cases: the *first* matched suffix is stripped
	test '$(call am.util.strip-suffixes,.a .b,x.a.a)' = 'x.a'
	test '$(call am.util.strip-suffixes,.a .b,x.a.b)' = 'x.a'
	test '$(call am.util.strip-suffixes,.a .b,x.b.a)' = 'x.b'
	test '$(call am.util.strip-suffixes,.a .b,x.b.b)' = 'x.b'
	test '$(call am.util.strip-suffixes, .a .b.a, foo.b.a bar.a)' \
	      = 'foo.b bar'
	test '$(call am.util.strip-suffixes, .b.a .a, foo.b.a bar.a)' \
	      = 'foo bar'
END

T 'am.util.toupper' <<'END'
test:
	test '$(call am.util.toupper,a)'        = A
	test '$(call am.util.toupper,A)'        = A
	test '$(call am.util.toupper,aba)'      = ABA
	test '$(call am.util.toupper,a b)'      = 'A B'
	test '$(call am.util.toupper, a B)'     = ' A B'
	test '$(call am.util.toupper,Ab  )'     = 'AB  '
	test '$(call am.util.toupper,A 	 B c )' = 'A 	 B C '
	test '$(call am.util.toupper,0)'        = 0
	test '$(call am.util.toupper,0d)'       = 0D
	test '$(call am.util.toupper,@:&/?-)'   = '@:&/?-'
	test '$(call am.util.toupper,a@B)'      = A@B
	test '$(call am.util.toupper,zxzxzxZXZxzxzxzxzx)' = ZXZXZXZXZXZXZXZXZX
	test '$(call am.util.toupper,$(lower))' = '$(upper)'
	test '$(call am.util.toupper,$(upper))' = '$(upper)'
END

T 'am.util.tolower' <<'END'
test:
	test '$(call am.util.tolower,A)'        = a
	test '$(call am.util.tolower,a)'        = a
	test '$(call am.util.tolower,ABA)'      = aba
	test '$(call am.util.tolower,A B)'      = 'a b'
	test '$(call am.util.tolower, A b)'     = ' a b'
	test '$(call am.util.tolower,aB  )'     = 'ab  '
	test '$(call am.util.tolower,a 	 b C )' = 'a 	 b c '
	test '$(call am.util.tolower,0)'        = 0
	test '$(call am.util.tolower,0D)'       = 0d
	test '$(call am.util.tolower,@:&/?-)'   = '@:&/?-'
	test '$(call am.util.tolower,a@B)'      = a@b
	test '$(call am.util.tolower,ZXZXZXzxzXZXZXZXZX)' = zxzxzxzxzxzxzxzxzx
	test '$(call am.util.tolower,$(upper))' = '$(lower)'
	test '$(call am.util.tolower,$(lower))' = '$(lower)'
END

T 'am.util.canon' <<'END'
comma = ,
dollar = $$
bslash = \\
test:
	test '$(call am.util.canon,A)' = A
	test '$(call am.util.canon, b)' = b
	test '$(call am.util.canon, foo	 )' = foo
	test '$(call am.util.canon,$(upper)$(lower)$(digits)_)' = '$(upper)$(lower)$(digits)_'
	test '$(call am.util.canon,@)' = '@'
	test '$(call am.util.canon,%)' = '_'
	test '$(call am.util.canon,.&@!;)' = '__@__'
	test '$(call am.util.canon,')' = '_'
	test '$(call am.util.canon,$(dollar))' = '_'
	test '$(call am.util.canon,$(bslash))' = '_'
	test '$(call am.util.canon,$(comma))' = '_'
	test '$(call am.util.canon,$(bslash)$(comma))' = '__'
	test '$(call am.util.canon,x$(comma)@$(bslash))' = 'x_@_'
END

FOO_ENVIRON=ok; export FOO_ENVIRON
FOO_UNDEF=; unset FOO_UNDEF
FOO_INDIR=; unset FOO_INDIR
T 'am.vars.is-undef' FOO_CMDLINE=ok <<'END'

FOO_MAKEFILE_1 = ok
FOO_MAKEFILE_2 := ok
override FOO_OVERRIDE_1 = ok
override FOO_OVERRIDE_2 := ok
FOO_EMPTY_1 =
FOO_EMPTY_2 :=

# Help avoiding typos.
X = $(call am.vars.is-undef,$1)

test:
	@echo UNDEF:
	test '$(call X,FOO_UNDEF)' = yes
	@echo ENVIRON:
	test '$(call X,FOO_ENVIRON)' = yes
	@echo MAKEFILE 1:
	test -z '$(call X,FOO_MAKEFILE_1)'
	@echo MAKEFILE 2:
	test -z '$(call X,FOO_MAKEFILE_2)'
	@echo CMDLINE:
	test -z '$(call X,FOO_CMDLINE)'
	@echo OVERRIDE 1:
	test -z '$(call X,FOO_OVERRIDE_1)'
	@echo OVERRIDE 2:
	test -z '$(call X,FOO_OVERRIDE_2)'
	@echo EMPTY 1:
	test -z '$(call X,FOO_EMPTY_1)'
	@echo EMPTY 2:
	test -z '$(call X,FOO_EMPTY_2)'
	@echo DEFAULT:
	test -z '$(call X,CC)'
	@echo EXTRA SPACES:
	test '$(call X,  FOO_UNDEF 	)' = yes
	@echo SANITY CHECKS:
	test '$(FOO_ENVIRON)' = ok
	test '$(FOO_CMDLINE)' = ok
END
unset FOO_ENVIRON

T 'am.chars.newline (1)' <<'END'
test:
	@echo OK > fo1$(am.chars.newline)@touch ba1$(am.chars.newline)-false > qu1
	test `cat fo1` = OK
	test -f ba1
	test -f qu1
END

T 'am.chars.newline (2)' <<'END'
my_newline = $(am.chars.newline)
test:
	@echo OK > fo2$(my_newline)@touch ba2$(my_newline)-false > qu2
	test `cat fo2` = OK
	test -f ba2
	test -f qu2
END

T 'am.chars.newline (3)' <<'END'
my_newline = $(am.chars.newline)
command-1 = test x = x$(am.chars.newline)
command-2 = test y = y$(my_newline)
test:
	$(command-1)$(command-2)touch n3
	test -f n3
END

T 'am.util.file-exists' <<'END'
prepare:
	: > 'a'
	test -f 'a'
	: > '?'
	test -f '?'
	: > 'foo bar'
	test -f 'foo bar'
	mkdir 'a  b'
	test -d 'a  b'
	: > 'a  b'/'c	d'
	test -f 'a  b'/'c	d'
test: prepare
	test x'$(call am.util.file-exists,.)' = x'yes'
	test x'$(call am.util.file-exists,Makefile)' = x'yes'
	test x'$(call am.util.file-exists,.././defn.mk)' = x'yes'
	test x'$(call am.util.file-exists,none)' = x
	test x'$(call am.util.file-exists,Makefile oops)' = x
	test x'$(call am.util.file-exists,foo bar)' = x'yes'
	test x'$(call am.util.file-exists,a  b)' = x'yes'
	test x'$(call am.util.file-exists,a  b/c	d)' = x'yes'
	test x'$(call am.util.file-exists,*)' = x
	test x'$(call am.util.file-exists,a)' = x'yes'
	test x'$(call am.util.file-exists,[ab])' = x
	test x'$(call am.util.file-exists,?)' = x'yes'
END

: