Documentation and tests for order-only prerequisites.
[make.git] / tests / scripts / features / order_only
blobe324d6812d0990f13f9f08e57f291f6f709d5bbb
1 #                                                                    -*-perl-*-
2 $description = "Test order-only prerequisites.";
4 $details = "\
5 Create makefiles with various combinations of normal and order-only
6 prerequisites and ensure they behave properly.  Test the \$| variable.";
8 open(MAKEFILE,"> $makefile");
10 print MAKEFILE <<'EOF';
11 foo: bar | baz
12         @echo '$$^ = $^'
13         @echo '$$| = $|'
14         touch $@
16 .PHONY: baz
18 bar baz:
19         touch $@
20 EOF
22 close(MAKEFILE);
25 # TEST #1 -- just the syntax
27 &run_make_with_options($makefile, "", &get_logfile);
28 $answer = "touch bar\ntouch baz\n\$^ = bar\n\$| = baz\ntouch foo\n";
29 &compare_output($answer,&get_logfile(1));
32 # TEST #2 -- now we do it again: baz is PHONY but foo should _NOT_ be updated
34 &run_make_with_options($makefile, "", &get_logfile);
35 $answer = "touch baz\n";
36 &compare_output($answer,&get_logfile(1));
38 unlink(qw(foo bar baz));
40 # Test prereqs that are both order and non-order
42 $makefile2 = &get_tmpfile;
44 open(MAKEFILE,"> $makefile2");
46 print MAKEFILE <<'EOF';
47 foo: bar | baz
48         @echo '$$^ = $^'
49         @echo '$$| = $|'
50         touch $@
52 foo: baz
54 .PHONY: baz
56 bar baz:
57         touch $@
58 EOF
60 close(MAKEFILE);
62 # TEST #3 -- Make sure the order-only prereq was promoted to normal.
64 &run_make_with_options($makefile2, "", &get_logfile);
65 $answer = "touch bar\ntouch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
66 &compare_output($answer,&get_logfile(1));
69 # TEST #4 -- now we do it again
71 &run_make_with_options($makefile2, "", &get_logfile);
72 $answer = "touch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
73 &compare_output($answer,&get_logfile(1));
75 unlink(qw(foo bar baz));
77 # Test empty normal prereqs
79 $makefile3 = &get_tmpfile;
81 open(MAKEFILE,"> $makefile3");
83 print MAKEFILE <<'EOF';
84 foo:| baz
85         @echo '$$^ = $^'
86         @echo '$$| = $|'
87         touch $@
89 .PHONY: baz
91 baz:
92         touch $@
93 EOF
95 close(MAKEFILE);
97 # TEST #5 -- make sure the parser was correct.
99 &run_make_with_options($makefile3, "", &get_logfile);
100 $answer = "touch baz\n\$^ = \n\$| = baz\ntouch foo\n";
101 &compare_output($answer,&get_logfile(1));
104 # TEST #6 -- now we do it again: this time foo won't be built
106 &run_make_with_options($makefile3, "", &get_logfile);
107 $answer = "touch baz\n";
108 &compare_output($answer,&get_logfile(1));
110 unlink(qw(foo baz));