xref: /netbsd-src/external/gpl2/gmake/dist/tests/scripts/functions/word (revision 69606e3f5c9388e52aed8c120ad63c049ca45d8f)
1*69606e3fSchristos#                                                                    -*-perl-*-
2*69606e3fSchristos$description = "\
3*69606e3fSchristosTest the word, words, wordlist, firstword, and lastword functions.\n";
4*69606e3fSchristos
5*69606e3fSchristos$details = "\
6*69606e3fSchristosProduce a variable with a large number of words in it,
7*69606e3fSchristosdetermine the number of words, and then read each one back.\n";
8*69606e3fSchristos
9*69606e3fSchristosopen(MAKEFILE,"> $makefile");
10*69606e3fSchristosprint MAKEFILE <<'EOF';
11*69606e3fSchristosstring  := word.pl general_test2.pl   FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl
12*69606e3fSchristosstring2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string)
13*69606e3fSchristosstring3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2)
14*69606e3fSchristosstring4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3)
15*69606e3fSchristosall:
16*69606e3fSchristos	@echo $(words $(string))
17*69606e3fSchristos	@echo $(words $(string4))
18*69606e3fSchristos	@echo $(word 1, $(string))
19*69606e3fSchristos	@echo $(word 100, $(string))
20*69606e3fSchristos	@echo $(word 1, $(string))
21*69606e3fSchristos	@echo $(word 1000, $(string3))
22*69606e3fSchristos	@echo $(wordlist 3, 4, $(string))
23*69606e3fSchristos	@echo $(wordlist 4, 3, $(string))
24*69606e3fSchristos	@echo $(wordlist 1, 6, $(string))
25*69606e3fSchristos	@echo $(wordlist 5, 7, $(string))
26*69606e3fSchristos	@echo $(wordlist 100, 110, $(string))
27*69606e3fSchristos	@echo $(wordlist 7, 10, $(string2))
28*69606e3fSchristosEOF
29*69606e3fSchristosclose(MAKEFILE);
30*69606e3fSchristos
31*69606e3fSchristos&run_make_with_options($makefile, "", &get_logfile);
32*69606e3fSchristos$answer = "6\n"
33*69606e3fSchristos         ."2058\n"
34*69606e3fSchristos         ."word.pl\n"
35*69606e3fSchristos         ."\n"
36*69606e3fSchristos         ."word.pl\n"
37*69606e3fSchristos         ."\n"
38*69606e3fSchristos	 ."FORCE.pl word.pl\n"
39*69606e3fSchristos	 ."\n"
40*69606e3fSchristos	 ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n"
41*69606e3fSchristos	 ."generic_test.perl MAKEFILES_variable.pl\n"
42*69606e3fSchristos	 ."\n"
43*69606e3fSchristos	 ."word.pl general_test2.pl FORCE.pl word.pl\n";
44*69606e3fSchristos&compare_output($answer, &get_logfile(1));
45*69606e3fSchristos
46*69606e3fSchristos
47*69606e3fSchristos# Test error conditions
48*69606e3fSchristos
49*69606e3fSchristosrun_make_test('FOO = foo bar biz baz
50*69606e3fSchristos
51*69606e3fSchristosword-e1: ; @echo $(word ,$(FOO))
52*69606e3fSchristosword-e2: ; @echo $(word abc ,$(FOO))
53*69606e3fSchristosword-e3: ; @echo $(word 1a,$(FOO))
54*69606e3fSchristos
55*69606e3fSchristoswordlist-e1: ; @echo $(wordlist ,,$(FOO))
56*69606e3fSchristoswordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
57*69606e3fSchristoswordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))',
58*69606e3fSchristos              'word-e1',
59*69606e3fSchristos              "#MAKEFILE#:3: *** non-numeric first argument to `word' function: ''.  Stop.",
60*69606e3fSchristos              512);
61*69606e3fSchristos
62*69606e3fSchristosrun_make_test(undef,
63*69606e3fSchristos              'word-e2',
64*69606e3fSchristos              "#MAKEFILE#:4: *** non-numeric first argument to `word' function: 'abc '.  Stop.",
65*69606e3fSchristos              512);
66*69606e3fSchristos
67*69606e3fSchristosrun_make_test(undef,
68*69606e3fSchristos              'word-e3',
69*69606e3fSchristos              "#MAKEFILE#:5: *** non-numeric first argument to `word' function: '1a'.  Stop.",
70*69606e3fSchristos              512);
71*69606e3fSchristos
72*69606e3fSchristosrun_make_test(undef,
73*69606e3fSchristos              'wordlist-e1',
74*69606e3fSchristos              "#MAKEFILE#:7: *** non-numeric first argument to `wordlist' function: ''.  Stop.",
75*69606e3fSchristos              512);
76*69606e3fSchristos
77*69606e3fSchristosrun_make_test(undef,
78*69606e3fSchristos              'wordlist-e2',
79*69606e3fSchristos              "#MAKEFILE#:8: *** non-numeric first argument to `wordlist' function: 'abc '.  Stop.",
80*69606e3fSchristos              512);
81*69606e3fSchristos
82*69606e3fSchristosrun_make_test(undef,
83*69606e3fSchristos              'wordlist-e3',
84*69606e3fSchristos              "#MAKEFILE#:9: *** non-numeric second argument to `wordlist' function: ' 12a '.  Stop.",
85*69606e3fSchristos              512);
86*69606e3fSchristos
87*69606e3fSchristos# Test error conditions again, but this time in a variable reference
88*69606e3fSchristos
89*69606e3fSchristosrun_make_test('FOO = foo bar biz baz
90*69606e3fSchristos
91*69606e3fSchristosW = $(word $x,$(FOO))
92*69606e3fSchristosWL = $(wordlist $s,$e,$(FOO))
93*69606e3fSchristos
94*69606e3fSchristosword-e: ; @echo $(W)
95*69606e3fSchristoswordlist-e: ; @echo $(WL)',
96*69606e3fSchristos              'word-e x=',
97*69606e3fSchristos              "#MAKEFILE#:3: *** non-numeric first argument to `word' function: ''.  Stop.",
98*69606e3fSchristos              512);
99*69606e3fSchristos
100*69606e3fSchristosrun_make_test(undef,
101*69606e3fSchristos              'word-e x=abc',
102*69606e3fSchristos              "#MAKEFILE#:3: *** non-numeric first argument to `word' function: 'abc'.  Stop.",
103*69606e3fSchristos              512);
104*69606e3fSchristos
105*69606e3fSchristosrun_make_test(undef,
106*69606e3fSchristos              'word-e x=0',
107*69606e3fSchristos              "#MAKEFILE#:3: *** first argument to `word' function must be greater than 0.  Stop.",
108*69606e3fSchristos              512);
109*69606e3fSchristos
110*69606e3fSchristosrun_make_test(undef,
111*69606e3fSchristos              'wordlist-e s= e=',
112*69606e3fSchristos              "#MAKEFILE#:4: *** non-numeric first argument to `wordlist' function: ''.  Stop.",
113*69606e3fSchristos              512);
114*69606e3fSchristos
115*69606e3fSchristosrun_make_test(undef,
116*69606e3fSchristos              'wordlist-e s=abc e=',
117*69606e3fSchristos              "#MAKEFILE#:4: *** non-numeric first argument to `wordlist' function: 'abc'.  Stop.",
118*69606e3fSchristos              512);
119*69606e3fSchristos
120*69606e3fSchristosrun_make_test(undef,
121*69606e3fSchristos              'wordlist-e s=4 e=12a',
122*69606e3fSchristos              "#MAKEFILE#:4: *** non-numeric second argument to `wordlist' function: '12a'.  Stop.",
123*69606e3fSchristos              512);
124*69606e3fSchristos
125*69606e3fSchristosrun_make_test(undef,
126*69606e3fSchristos              'wordlist-e s=0 e=12',
127*69606e3fSchristos              "#MAKEFILE#:4: *** invalid first argument to `wordlist' function: `0'.  Stop.",
128*69606e3fSchristos              512);
129*69606e3fSchristos
130*69606e3fSchristos
131*69606e3fSchristos# TEST #8 -- test $(firstword )
132*69606e3fSchristos#
133*69606e3fSchristosrun_make_test('
134*69606e3fSchristosvoid :=
135*69606e3fSchristoslist := $(void) foo bar baz #
136*69606e3fSchristos
137*69606e3fSchristosa := $(word 1,$(list))
138*69606e3fSchristosb := $(firstword $(list))
139*69606e3fSchristos
140*69606e3fSchristos.PHONY: all
141*69606e3fSchristos
142*69606e3fSchristosall:
143*69606e3fSchristos	@test "$a" = "$b" && echo $a
144*69606e3fSchristos',
145*69606e3fSchristos'',
146*69606e3fSchristos'foo');
147*69606e3fSchristos
148*69606e3fSchristos
149*69606e3fSchristos# TEST #9 -- test $(lastword )
150*69606e3fSchristos#
151*69606e3fSchristosrun_make_test('
152*69606e3fSchristosvoid :=
153*69606e3fSchristoslist := $(void) foo bar baz #
154*69606e3fSchristos
155*69606e3fSchristosa := $(word $(words $(list)),$(list))
156*69606e3fSchristosb := $(lastword $(list))
157*69606e3fSchristos
158*69606e3fSchristos.PHONY: all
159*69606e3fSchristos
160*69606e3fSchristosall:
161*69606e3fSchristos	@test "$a" = "$b" && echo $a
162*69606e3fSchristos',
163*69606e3fSchristos'',
164*69606e3fSchristos'baz');
165*69606e3fSchristos
166*69606e3fSchristos# This tells the test driver that the perl test script executed properly.
167*69606e3fSchristos1;
168