VirtualBox

source: kBuild/trunk/src/gmake/tests/scripts/functions/word@ 285

Last change on this file since 285 was 285, checked in by bird, 20 years ago

This commit was generated by cvs2svn to compensate for changes in r284,
which included commits to RCS files with non-trunk default branches.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
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
49$makefile2 = &get_tmpfile;
50
51open(MAKEFILE, "> $makefile2");
52print MAKEFILE <<'EOF';
53FOO = foo bar biz baz
54
55word-e1: ; @echo $(word ,$(FOO))
56word-e2: ; @echo $(word abc ,$(FOO))
57word-e3: ; @echo $(word 1a,$(FOO))
58
59wordlist-e1: ; @echo $(wordlist ,,$(FOO))
60wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
61wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))
62
63EOF
64
65close(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#
94run_make_test('
95void :=
96list := $(void) foo bar baz #
97
98a := $(word 1,$(list))
99b := $(firstword $(list))
100
101.PHONY: all
102
103all:
104 @test "$a" = "$b" && echo $a
105',
106'',
107'foo');
108
109
110# TEST #9 -- test $(lastword )
111#
112run_make_test('
113void :=
114list := $(void) foo bar baz #
115
116a := $(word $(words $(list)),$(list))
117b := $(lastword $(list))
118
119.PHONY: all
120
121all:
122 @test "$a" = "$b" && echo $a
123',
124'',
125'baz');
126
127# This tells the test driver that the perl test script executed properly.
1281;
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette