Enhancement (bug #2407) Make error messages more clear.
[make/kirr.git] / tests / scripts / functions / word
blob5083cec528b8bfc3e1d18a24ac668eaf1098265b
1 #                                                                    -*-perl-*-
2 $description = "Test the word, words, and wordlist functions.\n";
4 $details = "\
5 Produce a variable with a large number of words in it,
6 determine the number of words, and then read each one back.\n";
8 open(MAKEFILE,"> $makefile");
9 print MAKEFILE <<'EOF';
10 string  := word.pl general_test2.pl   FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl
11 string2 := $(string) $(string) $(string) $(string) $(string) $(string) $(string)
12 string3 := $(string2) $(string2) $(string2) $(string2) $(string2) $(string2) $(string2)
13 string4 := $(string3) $(string3) $(string3) $(string3) $(string3) $(string3) $(string3)
14 all:
15         @echo $(words $(string))
16         @echo $(words $(string4))
17         @echo $(word 1, $(string))
18         @echo $(word 100, $(string))
19         @echo $(word 1, $(string))
20         @echo $(word 1000, $(string3))
21         @echo $(wordlist 3, 4, $(string))
22         @echo $(wordlist 4, 3, $(string))
23         @echo $(wordlist 1, 6, $(string))
24         @echo $(wordlist 5, 7, $(string))
25         @echo $(wordlist 100, 110, $(string))
26         @echo $(wordlist 7, 10, $(string2))
27 EOF
28 close(MAKEFILE);
30 &run_make_with_options($makefile, "", &get_logfile);
31 $answer = "6\n"
32          ."2058\n"
33          ."word.pl\n"
34          ."\n"
35          ."word.pl\n"
36          ."\n"
37          ."FORCE.pl word.pl\n"
38          ."\n"
39          ."word.pl general_test2.pl FORCE.pl word.pl generic_test.perl MAKEFILES_variable.pl\n"
40          ."generic_test.perl MAKEFILES_variable.pl\n"
41          ."\n"
42          ."word.pl general_test2.pl FORCE.pl word.pl\n";
43 &compare_output($answer, &get_logfile(1));
46 # Test error conditions
48 $makefile2 = &get_tmpfile;
50 open(MAKEFILE, "> $makefile2");
51 print MAKEFILE <<'EOF';
52 FOO = foo bar biz baz
54 word-e1: ; @echo $(word ,$(FOO))
55 word-e2: ; @echo $(word abc ,$(FOO))
56 word-e3: ; @echo $(word 1a,$(FOO))
58 wordlist-e1: ; @echo $(wordlist ,,$(FOO))
59 wordlist-e2: ; @echo $(wordlist abc ,,$(FOO))
60 wordlist-e3: ; @echo $(wordlist 1, 12a ,$(FOO))
62 EOF
64 close(MAKEFILE);
66 &run_make_with_options($makefile2, 'word-e1', &get_logfile, 512);
67 $answer = "$makefile2:3: *** non-numeric first argument to `word' function: ''.  Stop.\n";
68 &compare_output($answer, &get_logfile(1));
70 &run_make_with_options($makefile2, 'word-e2', &get_logfile, 512);
71 $answer = "$makefile2:4: *** non-numeric first argument to `word' function: 'abc '.  Stop.\n";
72 &compare_output($answer, &get_logfile(1));
74 &run_make_with_options($makefile2, 'word-e3', &get_logfile, 512);
75 $answer = "$makefile2:5: *** non-numeric first argument to `word' function: '1a'.  Stop.\n";
76 &compare_output($answer, &get_logfile(1));
78 &run_make_with_options($makefile2, 'wordlist-e1', &get_logfile, 512);
79 $answer = "$makefile2:7: *** non-numeric first argument to `wordlist' function: ''.  Stop.\n";
80 &compare_output($answer, &get_logfile(1));
82 &run_make_with_options($makefile2, 'wordlist-e2', &get_logfile, 512);
83 $answer = "$makefile2:8: *** non-numeric first argument to `wordlist' function: 'abc '.  Stop.\n";
84 &compare_output($answer, &get_logfile(1));
86 &run_make_with_options($makefile2, 'wordlist-e3', &get_logfile, 512);
87 $answer = "$makefile2:9: *** non-numeric second argument to `wordlist' function: ' 12a '.  Stop.\n";
88 &compare_output($answer, &get_logfile(1));
90 # This tells the test driver that the perl test script executed properly.