2841f5d56d65e4a191eb2d2a52226230dddb01b8
[platform/upstream/make.git] / tests / scripts / functions / wildcard
1 #                                                                    -*-perl-*-
2
3 $description = "The following test creates a makefile to test wildcard
4 expansions and the ability to put a command on the same
5 line as the target name separated by a semi-colon.";
6
7 $details = "\
8 This test creates 4 files by the names of 1.example,
9 two.example and 3.example.  We execute three tests.  The first
10 executes the print1 target which tests the '*' wildcard by
11 echoing all filenames by the name of '*.example'.  The second
12 test echo's all files which match '?.example' and
13 [a-z0-9].example.  Lastly we clean up all of the files using
14 the '*' wildcard as in the first test";
15
16 open(MAKEFILE,"> $makefile");
17
18 # The Contents of the MAKEFILE ...
19
20 print MAKEFILE <<EOM;
21 .PHONY: print1 print2 clean
22 print1: ;\@echo \$(sort \$(wildcard example.*))
23 print2:
24 \t\@echo \$(sort \$(wildcard example.?))
25 \t\@echo \$(sort \$(wildcard example.[a-z0-9]))
26 \t\@echo \$(sort \$(wildcard example.[!A-Za-z_\\!]))
27 clean:
28 \t$delete_command \$(sort \$(wildcard example.*))
29 EOM
30
31 # END of Contents of MAKEFILE
32
33 close(MAKEFILE);
34
35 &touch("example.1");
36 &touch("example.two");
37 &touch("example.3");
38 &touch("example.for");
39 &touch("example._");
40
41 # TEST #1
42 # -------
43
44 $answer = "example.1 example.3 example._ example.for example.two\n";
45
46 &run_make_with_options($makefile,"print1",&get_logfile);
47
48 &compare_output($answer,&get_logfile(1));
49
50
51 # TEST #2
52 # -------
53
54 $answer = "example.1 example.3 example._\n"
55          ."example.1 example.3\n"
56          ."example.1 example.3\n";
57
58 &run_make_with_options($makefile,"print2",&get_logfile);
59
60 &compare_output($answer,&get_logfile(1));
61
62
63 # TEST #3
64 # -------
65
66 $answer = "$delete_command example.1 example.3 example._ example.for example.two";
67 if ($vos)
68 {
69    $answer .= " \n";
70 }
71 else
72 {
73    $answer .= "\n";
74 }
75
76 &run_make_with_options($makefile,"clean",&get_logfile);
77
78 if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for")) {
79    $test_passed = 0;
80 }
81
82 &compare_output($answer,&get_logfile(1));
83
84 # TEST #4: Verify that failed wildcards don't return the pattern
85
86 run_make_test(q!
87 all: ; @echo $(wildcard xz--y*.7)
88 !,
89               '', "\n");
90
91 1;