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