~ubuntu-branches/ubuntu/oneiric/rake/oneiric

« back to all changes in this revision

Viewing changes to test/test_rules.rb

  • Committer: Bazaar Package Importer
  • Author(s): Adam Majer
  • Date: 2007-05-06 17:15:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070506171536-qy40vbx5a248gsak
Tags: 0.7.3-1
* New upstream release
* Updated flexmock from 0.1.7 to 0.6.0
* Updated Standards to 0.7.2 - no changes
* Fixed Build-Depends on debhelper

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
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_pathmap_automatically_applies_to_name
 
138
    verbose(false) do
 
139
      chdir("testdata") do
 
140
        create_file("abc.c")
 
141
        rule ".o" => '%{x,a}n.c' do |t|
 
142
          @runs << "#{t.name} - #{t.source}"
 
143
        end
 
144
        Task["xbc.o"].invoke
 
145
        assert_equal ["xbc.o - abc.c"], @runs
 
146
      end
 
147
    end
 
148
  end
 
149
 
 
150
  def test_rule_runs_when_explicit_task_has_no_actions
79
151
    create_file(SRCFILE)
80
152
    create_file(SRCFILE2)
81
153
    delete_file(OBJFILE)
87
159
    assert_equal [SRCFILE], @runs
88
160
  end
89
161
 
90
 
  def test_string_close_matches
 
162
  def test_close_matches_on_name_do_not_trigger_rule
91
163
    create_file("testdata/x.c")
92
164
    rule '.o' => ['.c'] do |t|
93
165
      @runs << t.name
96
168
    assert_raises(RuntimeError) { Task['testdata/x.xyo'].invoke }
97
169
  end
98
170
 
99
 
  def test_precedence_rule_vs_implicit
 
171
  def test_rule_rebuilds_obj_when_source_is_newer
100
172
    create_timed_files(OBJFILE, SRCFILE)
101
173
    rule(/\.o$/ => ['.c']) do
102
174
      @runs << :RULE
105
177
    assert_equal [:RULE], @runs
106
178
  end
107
179
 
108
 
  def test_rule_with_two_sources
 
180
  def test_rule_with_two_sources_runs_if_both_sources_are_present
109
181
    create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
110
182
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
111
183
      @runs << :RULE
114
186
    assert_equal [:RULE], @runs
115
187
  end
116
188
 
117
 
  def test_rule_with_two_sources_but_one_missing
 
189
  def test_rule_with_two_sources_but_one_missing_does_not_run
118
190
    create_timed_files(OBJFILE, SRCFILE)
119
191
    delete_file(SRCFILE2)
120
192
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
124
196
    assert_equal [], @runs
125
197
  end
126
198
 
127
 
  def test_rule_ordering_finding_second_rule
 
199
  def test_second_rule_runs_when_first_rule_doesnt
128
200
    create_timed_files(OBJFILE, SRCFILE)
129
201
    delete_file(SRCFILE2)
130
202
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
137
209
    assert_equal [:RULE2], @runs
138
210
  end
139
211
 
140
 
  def test_rule_ordering_finding_first_rule
141
 
    create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
142
 
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
143
 
      @runs << :RULE1
144
 
    end
145
 
    rule OBJFILE => [lambda{SRCFILE}] do
146
 
      @runs << :RULE2
147
 
    end
148
 
    Task[OBJFILE].invoke
149
 
    assert_equal [:RULE1], @runs
150
 
  end
151
 
 
152
 
  def test_rule_ordering_not_finding_second_rule
153
 
    create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
154
 
    rule OBJFILE => [lambda{SRCFILE}] do
155
 
      @runs << :RULE1
156
 
    end
157
 
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
158
 
      @runs << :RULE2
159
 
    end
160
 
    Task[OBJFILE].invoke
161
 
    assert_equal [:RULE1], @runs
162
 
  end
163
 
 
164
 
  def test_proc_dependent
 
212
  def test_second_rule_doest_run_if_first_triggers
 
213
    create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
 
214
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
 
215
      @runs << :RULE1
 
216
    end
 
217
    rule OBJFILE => [lambda{SRCFILE}] do
 
218
      @runs << :RULE2
 
219
    end
 
220
    Task[OBJFILE].invoke
 
221
    assert_equal [:RULE1], @runs
 
222
  end
 
223
 
 
224
  def test_second_rule_doest_run_if_first_triggers_with_reversed_rules
 
225
    create_timed_files(OBJFILE, SRCFILE, SRCFILE2)
 
226
    rule OBJFILE => [lambda{SRCFILE}] do
 
227
      @runs << :RULE1
 
228
    end
 
229
    rule OBJFILE => [lambda{SRCFILE}, lambda{SRCFILE2}] do
 
230
      @runs << :RULE2
 
231
    end
 
232
    Task[OBJFILE].invoke
 
233
    assert_equal [:RULE1], @runs
 
234
  end
 
235
 
 
236
  def test_rule_with_proc_dependent_will_trigger
165
237
    ran = false
166
238
    File.makedirs("testdata/src/jw")
167
239
    create_file("testdata/src/jw/X.java")
168
240
    rule %r(classes/.*\.class) => [
169
 
      proc { |fn| fn.sub(/^classes/, 'testdata/src').sub(/\.class$/, '.java') }
 
241
      proc { |fn| fn.pathmap("%{classes,testdata/src}d/%n.java") }
170
242
    ] do |task|
171
243
      assert_equal task.name, 'classes/jw/X.class'
172
244
      assert_equal task.source, 'testdata/src/jw/X.java'
173
 
      ran = true
 
245
      @runs << :RULE
174
246
    end
175
247
    Task['classes/jw/X.class'].invoke
176
 
    assert ran, "Should have triggered rule"
 
248
    assert_equal [:RULE], @runs
177
249
  ensure
178
250
    rm_r("testdata/src", :verbose=>false) rescue nil
179
251
  end
200
272
    rm_r("testdata/flatten", :verbose=>false) rescue nil
201
273
  end
202
274
 
203
 
  def test_recursive_rules
 
275
  def test_recursive_rules_will_work_as_long_as_they_terminate
204
276
    actions = []
205
277
    create_file("testdata/abc.xml")
206
278
    rule '.y' => '.xml' do actions << 'y' end
211
283
    assert_equal ['y', 'c', 'o', 'exe'], actions
212
284
  end
213
285
 
214
 
  def test_recursive_overflow
 
286
  def test_recursive_rules_that_dont_terminate_will_overflow
215
287
    create_file("testdata/a.a")
216
288
    prev = 'a'
217
289
    ('b'..'z').each do |letter|
224
296
    assert_match(/a\.z => testdata\/a.y/, ex.message)
225
297
  end
226
298
 
 
299
  def test_rules_with_bad_dependents_will_fail
 
300
    rule "a" => [ 1 ] do |t| puts t.name end
 
301
    assert_raise(RuntimeError) do Task['a'].invoke end
 
302
  end
 
303
 
227
304
end
228
305