| 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 | 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)
|
|---|
| 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 $(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))
|
|---|
| 28 | EOF
|
|---|
| 29 | close(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 |
|
|---|
| 49 | $makefile2 = &get_tmpfile;
|
|---|
| 50 |
|
|---|
| 51 | open(MAKEFILE, "> $makefile2");
|
|---|
| 52 | print MAKEFILE <<'EOF';
|
|---|
| 53 | FOO = foo bar biz baz
|
|---|
| 54 |
|
|---|
| 55 | word-e1: ; @echo $(word ,$(FOO))
|
|---|
| 56 | word-e2: ; @echo $(word abc ,$(FOO))
|
|---|
| 57 | word-e3: ; @echo $(word 1a,$(FOO))
|
|---|
| 58 |
|
|---|
| 59 | wordlist-e1: ; @echo $(wordlist ,,$(FOO))
|
|---|
| 60 | wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
|
|---|
| 61 | wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))
|
|---|
| 62 |
|
|---|
| 63 | EOF
|
|---|
| 64 |
|
|---|
| 65 | close(MAKEFILE);
|
|---|
| 66 |
|
|---|
| 67 | &run_make_with_options($makefile2, 'word-e1', &get_logfile, 512);
|
|---|
| 68 | $answer = "$makefile2:3: *** non-numeric first argument to `word' function: ''. Stop.\n";
|
|---|
| 69 | &compare_output($answer, &get_logfile(1));
|
|---|
| 70 |
|
|---|
| 71 | &run_make_with_options($makefile2, 'word-e2', &get_logfile, 512);
|
|---|
| 72 | $answer = "$makefile2:4: *** non-numeric first argument to `word' function: 'abc '. Stop.\n";
|
|---|
| 73 | &compare_output($answer, &get_logfile(1));
|
|---|
| 74 |
|
|---|
| 75 | &run_make_with_options($makefile2, 'word-e3', &get_logfile, 512);
|
|---|
| 76 | $answer = "$makefile2:5: *** non-numeric first argument to `word' function: '1a'. Stop.\n";
|
|---|
| 77 | &compare_output($answer, &get_logfile(1));
|
|---|
| 78 |
|
|---|
| 79 | &run_make_with_options($makefile2, 'wordlist-e1', &get_logfile, 512);
|
|---|
| 80 | $answer = "$makefile2:7: *** non-numeric first argument to `wordlist' function: ''. Stop.\n";
|
|---|
| 81 | &compare_output($answer, &get_logfile(1));
|
|---|
| 82 |
|
|---|
| 83 | &run_make_with_options($makefile2, 'wordlist-e2', &get_logfile, 512);
|
|---|
| 84 | $answer = "$makefile2:8: *** non-numeric first argument to `wordlist' function: 'abc '. Stop.\n";
|
|---|
| 85 | &compare_output($answer, &get_logfile(1));
|
|---|
| 86 |
|
|---|
| 87 | &run_make_with_options($makefile2, 'wordlist-e3', &get_logfile, 512);
|
|---|
| 88 | $answer = "$makefile2:9: *** non-numeric second argument to `wordlist' function: ' 12a '. Stop.\n";
|
|---|
| 89 | &compare_output($answer, &get_logfile(1));
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | # TEST #8 -- test $(firstword )
|
|---|
| 93 | #
|
|---|
| 94 | run_make_test('
|
|---|
| 95 | void :=
|
|---|
| 96 | list := $(void) foo bar baz #
|
|---|
| 97 |
|
|---|
| 98 | a := $(word 1,$(list))
|
|---|
| 99 | b := $(firstword $(list))
|
|---|
| 100 |
|
|---|
| 101 | .PHONY: all
|
|---|
| 102 |
|
|---|
| 103 | all:
|
|---|
| 104 | @test "$a" = "$b" && echo $a
|
|---|
| 105 | ',
|
|---|
| 106 | '',
|
|---|
| 107 | 'foo');
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | # TEST #9 -- test $(lastword )
|
|---|
| 111 | #
|
|---|
| 112 | run_make_test('
|
|---|
| 113 | void :=
|
|---|
| 114 | list := $(void) foo bar baz #
|
|---|
| 115 |
|
|---|
| 116 | a := $(word $(words $(list)),$(list))
|
|---|
| 117 | b := $(lastword $(list))
|
|---|
| 118 |
|
|---|
| 119 | .PHONY: all
|
|---|
| 120 |
|
|---|
| 121 | all:
|
|---|
| 122 | @test "$a" = "$b" && echo $a
|
|---|
| 123 | ',
|
|---|
| 124 | '',
|
|---|
| 125 | 'baz');
|
|---|
| 126 |
|
|---|
| 127 | # This tells the test driver that the perl test script executed properly.
|
|---|
| 128 | 1;
|
|---|