@@ -14,6 +14,8 @@ class TestRules < Test::Unit::TestCase
14
14
SRCFILE2 = "testdata/xyz.c"
15
15
FTNFILE = "testdata/abc.f"
16
16
OBJFILE = "testdata/abc.o"
17
+ FOOFILE = "testdata/foo"
18
+ DOTFOOFILE = "testdata/.foo"
17
19
18
20
def setup
19
21
Task . clear
@@ -66,7 +68,7 @@ def test_single_dependent
66
68
assert_equal [ OBJFILE ] , @runs
67
69
end
68
70
69
- def test_create_by_string
71
+ def test_rule_can_be_created_by_string
70
72
create_file ( SRCFILE )
71
73
rule '.o' => [ '.c' ] do |t |
72
74
@runs << t . name
@@ -75,7 +77,64 @@ def test_create_by_string
75
77
assert_equal [ OBJFILE ] , @runs
76
78
end
77
79
78
- def test_rule_and_no_action_task
80
+ def test_rule_prereqs_can_be_created_by_string
81
+ create_file ( SRCFILE )
82
+ rule '.o' => '.c' do |t |
83
+ @runs << t . name
84
+ end
85
+ Task [ OBJFILE ] . invoke
86
+ assert_equal [ OBJFILE ] , @runs
87
+ end
88
+
89
+ def test_plain_strings_as_dependents_refer_to_files
90
+ create_file ( SRCFILE )
91
+ rule '.o' => SRCFILE do |t |
92
+ @runs << t . name
93
+ end
94
+ Task [ OBJFILE ] . invoke
95
+ assert_equal [ OBJFILE ] , @runs
96
+ end
97
+
98
+ def test_file_names_beginning_with_dot_can_be_tricked_into_refering_to_file
99
+ verbose ( false ) do
100
+ chdir ( "testdata" ) do
101
+ create_file ( '.foo' )
102
+ rule '.o' => "./.foo" do |t |
103
+ @runs << t . name
104
+ end
105
+ Task [ OBJFILE ] . invoke
106
+ assert_equal [ OBJFILE ] , @runs
107
+ end
108
+ end
109
+ end
110
+
111
+ def test_file_names_beginning_with_dot_can_be_wrapped_in_lambda
112
+ verbose ( false ) do
113
+ chdir ( "testdata" ) do
114
+ create_file ( ".foo" )
115
+ rule '.o' => lambda { ".foo" } do |t |
116
+ @runs << t . name
117
+ end
118
+ Task [ OBJFILE ] . invoke
119
+ assert_equal [ OBJFILE ] , @runs
120
+ end
121
+ end
122
+ end
123
+
124
+ def test_non_extension_rule_name_refers_to_file
125
+ verbose ( false ) do
126
+ chdir ( "testdata" ) do
127
+ create_file ( "abc.c" )
128
+ rule "abc" => '.c' do |t |
129
+ @runs << t . name
130
+ end
131
+ Task [ "abc" ] . invoke
132
+ assert_equal [ "abc" ] , @runs
133
+ end
134
+ end
135
+ end
136
+
137
+ def test_rule_runs_when_explicit_task_has_no_actions
79
138
create_file ( SRCFILE )
80
139
create_file ( SRCFILE2 )
81
140
delete_file ( OBJFILE )
@@ -87,7 +146,7 @@ def test_rule_and_no_action_task
87
146
assert_equal [ SRCFILE ] , @runs
88
147
end
89
148
90
- def test_string_close_matches
149
+ def test_close_matches_on_name_do_not_trigger_rule
91
150
create_file ( "testdata/x.c" )
92
151
rule '.o' => [ '.c' ] do |t |
93
152
@runs << t . name
@@ -96,7 +155,7 @@ def test_string_close_matches
96
155
assert_raises ( RuntimeError ) { Task [ 'testdata/x.xyo' ] . invoke }
97
156
end
98
157
99
- def test_precedence_rule_vs_implicit
158
+ def test_rule_rebuilds_obj_when_source_is_newer
100
159
create_timed_files ( OBJFILE , SRCFILE )
101
160
rule ( /\. o$/ => [ '.c' ] ) do
102
161
@runs << :RULE
@@ -105,7 +164,7 @@ def test_precedence_rule_vs_implicit
105
164
assert_equal [ :RULE ] , @runs
106
165
end
107
166
108
- def test_rule_with_two_sources
167
+ def test_rule_with_two_sources_runs_if_both_sources_are_present
109
168
create_timed_files ( OBJFILE , SRCFILE , SRCFILE2 )
110
169
rule OBJFILE => [ lambda { SRCFILE } , lambda { SRCFILE2 } ] do
111
170
@runs << :RULE
@@ -114,7 +173,7 @@ def test_rule_with_two_sources
114
173
assert_equal [ :RULE ] , @runs
115
174
end
116
175
117
- def test_rule_with_two_sources_but_one_missing
176
+ def test_rule_with_two_sources_but_one_missing_does_not_run
118
177
create_timed_files ( OBJFILE , SRCFILE )
119
178
delete_file ( SRCFILE2 )
120
179
rule OBJFILE => [ lambda { SRCFILE } , lambda { SRCFILE2 } ] do
@@ -124,7 +183,7 @@ def test_rule_with_two_sources_but_one_missing
124
183
assert_equal [ ] , @runs
125
184
end
126
185
127
- def test_rule_ordering_finding_second_rule
186
+ def test_second_rule_runs_when_first_rule_doesnt
128
187
create_timed_files ( OBJFILE , SRCFILE )
129
188
delete_file ( SRCFILE2 )
130
189
rule OBJFILE => [ lambda { SRCFILE } , lambda { SRCFILE2 } ] do
@@ -137,7 +196,7 @@ def test_rule_ordering_finding_second_rule
137
196
assert_equal [ :RULE2 ] , @runs
138
197
end
139
198
140
- def test_rule_ordering_finding_first_rule
199
+ def test_second_rule_doest_run_if_first_triggers
141
200
create_timed_files ( OBJFILE , SRCFILE , SRCFILE2 )
142
201
rule OBJFILE => [ lambda { SRCFILE } , lambda { SRCFILE2 } ] do
143
202
@runs << :RULE1
@@ -149,7 +208,7 @@ def test_rule_ordering_finding_first_rule
149
208
assert_equal [ :RULE1 ] , @runs
150
209
end
151
210
152
- def test_rule_ordering_not_finding_second_rule
211
+ def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
153
212
create_timed_files ( OBJFILE , SRCFILE , SRCFILE2 )
154
213
rule OBJFILE => [ lambda { SRCFILE } ] do
155
214
@runs << :RULE1
@@ -161,19 +220,19 @@ def test_rule_ordering_not_finding_second_rule
161
220
assert_equal [ :RULE1 ] , @runs
162
221
end
163
222
164
- def test_proc_dependent
223
+ def test_rule_with_proc_dependent_will_trigger
165
224
ran = false
166
225
File . makedirs ( "testdata/src/jw" )
167
226
create_file ( "testdata/src/jw/X.java" )
168
227
rule %r(classes/.*\. class) => [
169
- proc { |fn | fn . sub ( /^ classes/ , ' testdata/src' ) . sub ( / \. class$/ , '. java' ) }
228
+ proc { |fn | fn . pathmap ( "%{ classes, testdata/src}d/%n. java" ) }
170
229
] do |task |
171
230
assert_equal task . name , 'classes/jw/X.class'
172
231
assert_equal task . source , 'testdata/src/jw/X.java'
173
- ran = true
232
+ @runs << :RULE
174
233
end
175
234
Task [ 'classes/jw/X.class' ] . invoke
176
- assert ran , "Should have triggered rule"
235
+ assert_equal [ :RULE ] , @runs
177
236
ensure
178
237
rm_r ( "testdata/src" , :verbose => false ) rescue nil
179
238
end
@@ -200,7 +259,7 @@ def test_proc_returning_lists_are_flattened_into_prereqs
200
259
rm_r ( "testdata/flatten" , :verbose => false ) rescue nil
201
260
end
202
261
203
- def test_recursive_rules
262
+ def test_recursive_rules_will_work_as_long_as_they_terminate
204
263
actions = [ ]
205
264
create_file ( "testdata/abc.xml" )
206
265
rule '.y' => '.xml' do actions << 'y' end
@@ -211,7 +270,7 @@ def test_recursive_rules
211
270
assert_equal [ 'y' , 'c' , 'o' , 'exe' ] , actions
212
271
end
213
272
214
- def test_recursive_overflow
273
+ def test_recursive_rules_that_dont_terminate_will_overflow
215
274
create_file ( "testdata/a.a" )
216
275
prev = 'a'
217
276
( 'b' ..'z' ) . each do |letter |
@@ -224,7 +283,7 @@ def test_recursive_overflow
224
283
assert_match ( /a\. z => testdata\/ a.y/ , ex . message )
225
284
end
226
285
227
- def test_bad_dependent
286
+ def test_rules_with_bad_dependents_will_fail
228
287
rule "a" => [ 1 ] do |t | puts t . name end
229
288
assert_raise ( RuntimeError ) do Task [ 'a' ] . invoke end
230
289
end
0 commit comments