summaryrefslogtreecommitdiff
path: root/tests/scripts/features/order_only
blob: 82a7253572fb4562d95f2c70d6569d64ee767c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#                                                                    -*-perl-*-
$description = "Test order-only prerequisites.";

$details = "\
Create makefiles with various combinations of normal and order-only
prerequisites and ensure they behave properly.  Test the \$| variable.";

open(MAKEFILE,"> $makefile");

print MAKEFILE <<'EOF';
foo: bar | baz
	@echo '$$^ = $^'
	@echo '$$| = $|'
	touch $@

.PHONY: baz

bar baz:
	touch $@
EOF

close(MAKEFILE);


# TEST #1 -- just the syntax

&run_make_with_options($makefile, "", &get_logfile);
$answer = "touch bar\ntouch baz\n\$^ = bar\n\$| = baz\ntouch foo\n";
&compare_output($answer,&get_logfile(1));


# TEST #2 -- now we do it again: baz is PHONY but foo should _NOT_ be updated

&run_make_with_options($makefile, "", &get_logfile);
$answer = "touch baz\n";
&compare_output($answer,&get_logfile(1));

unlink(qw(foo bar baz));

# Test prereqs that are both order and non-order

$makefile2 = &get_tmpfile;

open(MAKEFILE,"> $makefile2");

print MAKEFILE <<'EOF';
foo: bar | baz
	@echo '$$^ = $^'
	@echo '$$| = $|'
	touch $@

foo: baz

.PHONY: baz

bar baz:
	touch $@
EOF

close(MAKEFILE);

# TEST #3 -- Make sure the order-only prereq was promoted to normal.

&run_make_with_options($makefile2, "", &get_logfile);
$answer = "touch bar\ntouch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
&compare_output($answer,&get_logfile(1));


# TEST #4 -- now we do it again

&run_make_with_options($makefile2, "", &get_logfile);
$answer = "touch baz\n\$^ = bar baz\n\$| = \ntouch foo\n";
&compare_output($answer,&get_logfile(1));

unlink(qw(foo bar baz));

# Test empty normal prereqs

$makefile3 = &get_tmpfile;

open(MAKEFILE,"> $makefile3");

print MAKEFILE <<'EOF';
foo:| baz
	@echo '$$^ = $^'
	@echo '$$| = $|'
	touch $@

.PHONY: baz

baz:
	touch $@
EOF

close(MAKEFILE);

# TEST #5 -- make sure the parser was correct.

&run_make_with_options($makefile3, "", &get_logfile);
$answer = "touch baz\n\$^ = \n\$| = baz\ntouch foo\n";
&compare_output($answer,&get_logfile(1));


# TEST #6 -- now we do it again: this time foo won't be built

&run_make_with_options($makefile3, "", &get_logfile);
$answer = "touch baz\n";
&compare_output($answer,&get_logfile(1));

unlink(qw(foo baz));

# Test order-only in pattern rules

$makefile4 = &get_tmpfile;

open(MAKEFILE,"> $makefile4");

print MAKEFILE <<'EOF';
%.w : %.x | baz
	@echo '$$^ = $^'
	@echo '$$| = $|'
	touch $@

all: foo.w

.PHONY: baz
foo.x baz:
	touch $@
EOF

close(MAKEFILE);

# TEST #7 -- make sure the parser was correct.

&run_make_with_options($makefile4, "", &get_logfile);
$answer = "touch foo.x\ntouch baz\n\$^ = foo.x\n\$| = baz\ntouch foo.w\n";
&compare_output($answer,&get_logfile(1));

# TEST #8 -- now we do it again: this time foo.w won't be built

&run_make_with_options($makefile4, "", &get_logfile);
$answer = "touch baz\n";
&compare_output($answer,&get_logfile(1));

unlink(qw(foo.w foo.x baz));

# TEST #9 -- make sure that $< is set correctly in the face of order-only
# prerequisites in pattern rules.

run_make_test('
%r: | baz ; @echo $< $^ $|
bar: foo
foo:;@:
baz:;@:
', '', "foo foo baz\n");


1;