Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / functions / word
1 #                                                                    -*-perl-*-
2 $description = "\
3 Test the word, words, wordlist, firstword, and lastword functions.\n";
4
5 $details = "\
6 Produce a variable with a large number of words in it,
7 determine the number of words, and then read each one back.\n";
8
9 run_make_test('
10 string  := word.pl general_test2.pl   FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl
11 string2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string)
12 string3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2)
13 string4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3)
14 .RECIPEPREFIX = >
15 all:
16 > @echo $(words $(string))
17 > @echo $(words $(string4))
18 > @echo $(word 1, $(string))
19 > @echo $(word 100, $(string))
20 > @echo $(word 1  , $(string))
21 > @echo $(word 1000, $(string3))
22 > @echo $(word 9223372036854775807, $(string2))
23 > @echo $(wordlist 3, 4, $(string))
24 > @echo $(wordlist 4, 3, $(string))
25 > @echo $(wordlist 1 , 6  , $(string))
26 > @echo $(wordlist 5,7, $(string))
27 > @echo $(wordlist 100, 110, $(string))
28 > @echo $(wordlist 7, 10, $(string2))
29 > @echo $(wordlist 9223372036854775807, 0, $(string2))
30 ', '', "6\n"
31       ."2058\n"
32       ."word.pl\n"
33       ."\n"
34       ."word.pl\n"
35       ."\n"
36       ."\n"
37       ."FORCE.pl word.pl\n"
38       ."\n"
39       ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n"
40       ."generic_test.perl MAKEFILES_variable.pl\n"
41       ."\n"
42       ."word.pl general_test2.pl FORCE.pl word.pl\n"
43       ."\n"
44 );
45
46 # Test error conditions
47
48 run_make_test('FOO = foo bar biz baz
49
50 word-e1: ; @echo $(word ,$(FOO))
51 word-e2: ; @echo $(word abc ,$(FOO))
52 word-e3: ; @echo $(word 1a,$(FOO))
53 word-e4: ; @echo $(word 9999999999999999999,$(FOO))
54
55 wordlist-e1: ; @echo $(wordlist ,,$(FOO))
56 wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
57 wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))',
58               'word-e1',
59               "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value.  Stop.",
60               512);
61
62 run_make_test(undef,
63               'word-e2',
64               "#MAKEFILE#:4: *** invalid first argument to 'word' function: 'abc '.  Stop.",
65               512);
66
67 run_make_test(undef,
68               'word-e3',
69               "#MAKEFILE#:5: *** invalid first argument to 'word' function: '1a'.  Stop.",
70               512);
71
72 run_make_test(undef,
73               'word-e4',
74               "#MAKEFILE#:6: *** invalid first argument to 'word' function: '9999999999999999999' out of range.  Stop.",
75               512);
76
77 run_make_test(undef,
78               'wordlist-e1',
79               "#MAKEFILE#:8: *** invalid first argument to 'wordlist' function: empty value.  Stop.",
80               512);
81
82 run_make_test(undef,
83               'wordlist-e2',
84               "#MAKEFILE#:9: *** invalid first argument to 'wordlist' function: 'abc '.  Stop.",
85               512);
86
87 run_make_test(undef,
88               'wordlist-e3',
89               "#MAKEFILE#:10: *** invalid second argument to 'wordlist' function: ' 12a '.  Stop.",
90               512);
91
92 # Test error conditions again, but this time in a variable reference
93
94 run_make_test('FOO = foo bar biz baz
95
96 W = $(word $x,$(FOO))
97 WL = $(wordlist $s,$e,$(FOO))
98
99 word-e: ; @echo $(W)
100 wordlist-e: ; @echo $(WL)',
101               'word-e x=',
102               "#MAKEFILE#:3: *** invalid first argument to 'word' function: empty value.  Stop.",
103               512);
104
105 run_make_test(undef,
106               'word-e x=abc',
107               "#MAKEFILE#:3: *** invalid first argument to 'word' function: 'abc'.  Stop.",
108               512);
109
110 run_make_test(undef,
111               'word-e x=0',
112               "#MAKEFILE#:3: *** first argument to 'word' function must be greater than 0.  Stop.",
113               512);
114
115 run_make_test(undef,
116               'wordlist-e s= e=',
117               "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: empty value.  Stop.",
118               512);
119
120 run_make_test(undef,
121               'wordlist-e s=abc e=',
122               "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: 'abc'.  Stop.",
123               512);
124
125 run_make_test(undef,
126               'wordlist-e s=4 e=12a',
127               "#MAKEFILE#:4: *** invalid second argument to 'wordlist' function: '12a'.  Stop.",
128               512);
129
130 run_make_test(undef,
131               'wordlist-e s=0 e=12',
132               "#MAKEFILE#:4: *** invalid first argument to 'wordlist' function: '0'.  Stop.",
133               512);
134
135 run_make_test(undef,
136               'wordlist-e s=1 e=-1',
137               "#MAKEFILE#:4: *** invalid second argument to 'wordlist' function: '-1'.  Stop.",
138               512);
139
140
141 # TEST #8 -- test $(firstword )
142 #
143 run_make_test('
144 void :=
145 list := $(void) foo bar baz #
146
147 a := $(word 1,$(list))
148 b := $(firstword $(list))
149
150 .PHONY: all
151
152 all: ; @test "$a" = "$b" && echo $a
153 ',
154 '',
155 'foo');
156
157
158 # TEST #9 -- test $(lastword )
159 #
160 run_make_test('
161 void :=
162 list := $(void) foo bar baz #
163
164 a := $(word $(words $(list)),$(list))
165 b := $(lastword $(list))
166
167 .PHONY: all
168
169 all: ; @test "$a" = "$b" && echo $a
170 ',
171 '',
172 'baz');
173
174 # This tells the test driver that the perl test script executed properly.
175 1;