3 Test the word, words, wordlist, firstword, and lastword functions.\n";
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";
9 open(MAKEFILE,"> $makefile");
10 print MAKEFILE <<'EOF';
11 string := word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl
12 string2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string)
13 string3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2)
14 string4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3)
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 $(wordlist 3, 4, $(string))
23 @echo $(wordlist 4, 3, $(string))
24 @echo $(wordlist 1, 6, $(string))
25 @echo $(wordlist 5, 7, $(string))
26 @echo $(wordlist 100, 110, $(string))
27 @echo $(wordlist 7, 10, $(string2))
31 &run_make_with_options($makefile, "", &get_logfile);
40 ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n"
41 ."generic_test.perl MAKEFILES_variable.pl\n"
43 ."word.pl general_test2.pl FORCE.pl word.pl\n";
44 &compare_output($answer, &get_logfile(1));
47 # Test error conditions
49 run_make_test('FOO = foo bar biz baz
51 word-e1: ; @echo $(word ,$(FOO))
52 word-e2: ; @echo $(word abc ,$(FOO))
53 word-e3: ; @echo $(word 1a,$(FOO))
55 wordlist-e1: ; @echo $(wordlist ,,$(FOO))
56 wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
57 wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))',
59 "#MAKEFILE#:3: *** non-numeric first argument to `word' function: ''. Stop.",
64 "#MAKEFILE#:4: *** non-numeric first argument to `word' function: 'abc '. Stop.",
69 "#MAKEFILE#:5: *** non-numeric first argument to `word' function: '1a'. Stop.",
74 "#MAKEFILE#:7: *** non-numeric first argument to `wordlist' function: ''. Stop.",
79 "#MAKEFILE#:8: *** non-numeric first argument to `wordlist' function: 'abc '. Stop.",
84 "#MAKEFILE#:9: *** non-numeric second argument to `wordlist' function: ' 12a '. Stop.",
87 # Test error conditions again, but this time in a variable reference
89 run_make_test('FOO = foo bar biz baz
92 WL = $(wordlist $s,$e,$(FOO))
95 wordlist-e: ; @echo $(WL)',
97 "#MAKEFILE#:3: *** non-numeric first argument to `word' function: ''. Stop.",
102 "#MAKEFILE#:3: *** non-numeric first argument to `word' function: 'abc'. Stop.",
107 "#MAKEFILE#:3: *** first argument to `word' function must be greater than 0. Stop.",
112 "#MAKEFILE#:4: *** non-numeric first argument to `wordlist' function: ''. Stop.",
116 'wordlist-e s=abc e=',
117 "#MAKEFILE#:4: *** non-numeric first argument to `wordlist' function: 'abc'. Stop.",
121 'wordlist-e s=4 e=12a',
122 "#MAKEFILE#:4: *** non-numeric second argument to `wordlist' function: '12a'. Stop.",
126 'wordlist-e s=0 e=12',
127 "#MAKEFILE#:4: *** invalid first argument to `wordlist' function: `0'. Stop.",
131 # TEST #8 -- test $(firstword )
135 list := $(void) foo bar baz #
137 a := $(word 1,$(list))
138 b := $(firstword $(list))
143 @test "$a" = "$b" && echo $a
149 # TEST #9 -- test $(lastword )
153 list := $(void) foo bar baz #
155 a := $(word $(words $(list)),$(list))
156 b := $(lastword $(list))
161 @test "$a" = "$b" && echo $a
166 # This tells the test driver that the perl test script executed properly.