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