summaryrefslogtreecommitdiff
path: root/t/am-xargs-map.sh
blob: 6bb234ad5b8a4f2bbcdb94e7169e027797a863ed (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
#! /bin/sh
# Copyright (C) 2012-2014 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 Automake internal function 'am.xargs-map', in several usage
# scenarios.

am_create_testdir=empty
. test-init.sh

# Filter out Automake comments.
grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \
  || fatal_ "fetching makefile fragment headers-vars.am"
echo 'x-warning = $(warning $1)' >> defn.mk
echo 'y-warning = $(warning $1 -- $2)' >> defn.mk

sed 's/^[0-9][0-9]*:://' > Makefile << 'END'
01::include ./defn.mk
02::
03::args1  := 0 1 2 3 4 5 6 7 8 9
04::args2  := $(args1) $(args1)
05::args4  := $(args2) $(args2)
06::args8  := $(args4) $(args4)
07::args16 := $(args8) $(args8)
08::
09::WARN := no
10::ifeq ($(WARN),yes)
11::  $(call am.xargs-map,x-warning,$(args16))
12::  $(call am.xargs-map,x-warning,$(args16) 0 1 2 3)
13::  $(call am.xargs-map,x-warning,x y z)
14::  $(call am.xargs-map,y-warning,$(args16) 0 1 2 3,X)
15::endif

args32 := $(args16) $(args16)
args64 := $(args32) $(args32)

bar = test '$1' = '$(args4)'$(am.chars.newline)
test-xargs-map:
	$(call am.xargs-map,bar,$(args16))

args = $(error 'args' should be overridden from the command line)
more-args = $(error 'more-args' should be overridden from the command line)

foo = @echo $1$(am.chars.newline)
echo-xargs-map:
	$(call am.xargs-map,foo,$(args))

foo2 = @echo $1$(if $2, -- $2)$(am.chars.newline)
echo2-xargs-map:
	$(call am.xargs-map,foo2,$(args),$(more-args))
END

args1="0 1 2 3 4 5 6 7 8 9"
args2="$args1 $args1"
args4="$args2 $args2"

run_make -E .am/nil WARN=yes
grep '^Makefile:' stderr # For debugging
test $(grep -c "^Makefile:11: $args4$" stderr) -eq 4
test $(grep -c "^Makefile:12: $args4$" stderr) -eq 4
test $(grep -c "^Makefile:12: 0 1 2 3$" stderr) -eq 1
test $(grep -c "^Makefile:13: x y z$" stderr) -eq 1
test $(grep -c "^Makefile:14: $args4 -- X$" stderr) -eq 4
test $(grep -c "^Makefile:14: 0 1 2 3 -- X" stderr) -eq 1
test $(grep -c "^Makefile:" stderr) -eq 15

$MAKE 'test-xargs-map'

check_echo ()
{
  cat > exp
  mk="$MAKE --no-print-directory"
  case $# in
    1) $mk "echo-xargs-map" args="$1";;
    2) $mk "echo2-xargs-map" args="$1" more-args="$2";;
    *) fatal_ "check_echo: incorrect usage";;
  esac >got \
    || { cat got >&2; exit 1; }
  cat exp && cat got && diff exp got || exit 1
}

echo "$args1"           | check_echo '$(args1)'
echo "$args1 -- x"      | check_echo '$(args1)' x
echo "$args2"           | check_echo '$(args2)'
echo "$args2 -- no"     | check_echo '$(args2)' '$(WARN)'
echo "$args4"           | check_echo '$(args4)'
echo "$args4 -- a b c"  | check_echo '$(args4)' '$(notdir x/a ./b c)'

check_echo '$(args8)'<<END
$args4
$args4
END

check_echo "$args4 $args4" <<END
$args4
$args4
END

check_echo "$args4 $args4 x" <<END
$args4
$args4
x
END

check_echo "$args4 $args4 x" '.:.' <<END
$args4 -- .:.
$args4 -- .:.
x -- .:.
END

check_echo "$args4 01 02 03 04 05 06 07" <<END
$args4
01 02 03 04 05 06 07
END

check_echo "$args4 01 2 03" "+++" <<END
$args4 -- +++
01 2 03 -- +++
END

check_echo '$(args32) 11 12 13 67' <<END
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
11 12 13 67
END

check_echo '$(args32) 11 12 13 67' 'lol cat' <<END
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
$args4 -- lol cat
11 12 13 67 -- lol cat
END

check_echo '$(args64)' <<END
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
$args4
END

: