summaryrefslogtreecommitdiff
path: root/test/rake/test_rake_file_task.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-23 22:11:55 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-23 22:11:55 +0000
commitd001539a0538cba0e48be2ebdafe29e67b006a4e (patch)
treeabf1591ca3b56f04f46cc2cce9918700620a3ab1 /test/rake/test_rake_file_task.rb
parent3fbc9440feb66cf762834b6d66e6f3a893bab5b7 (diff)
* lib/rake: Import Rake 0.9.2
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32217 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rake/test_rake_file_task.rb')
-rw-r--r--test/rake/test_rake_file_task.rb102
1 files changed, 102 insertions, 0 deletions
diff --git a/test/rake/test_rake_file_task.rb b/test/rake/test_rake_file_task.rb
new file mode 100644
index 00000000000..e586551237f
--- /dev/null
+++ b/test/rake/test_rake_file_task.rb
@@ -0,0 +1,102 @@
+require File.expand_path('../helper', __FILE__)
+require 'fileutils'
+
+class TestRakeFileTask < Rake::TestCase
+ include Rake
+
+ def setup
+ super
+
+ Task.clear
+ @runs = Array.new
+ FileUtils.rm_f NEWFILE
+ FileUtils.rm_f OLDFILE
+ end
+
+ def test_file_need
+ name = "dummy"
+ file name
+
+ ftask = Task[name]
+
+ assert_equal name.to_s, ftask.name
+ File.delete(ftask.name) rescue nil
+
+ assert ftask.needed?, "file should be needed"
+
+ open(ftask.name, "w") { |f| f.puts "HI" }
+
+ assert_equal nil, ftask.prerequisites.collect{|n| Task[n].timestamp}.max
+ assert ! ftask.needed?, "file should not be needed"
+ ensure
+ File.delete(ftask.name) rescue nil
+ end
+
+ def test_file_times_new_depends_on_old
+ create_timed_files(OLDFILE, NEWFILE)
+
+ t1 = Rake.application.intern(FileTask, NEWFILE).enhance([OLDFILE])
+ t2 = Rake.application.intern(FileTask, OLDFILE)
+ assert ! t2.needed?, "Should not need to build old file"
+ assert ! t1.needed?, "Should not need to rebuild new file because of old"
+ end
+
+ def test_file_times_old_depends_on_new
+ create_timed_files(OLDFILE, NEWFILE)
+
+ t1 = Rake.application.intern(FileTask,OLDFILE).enhance([NEWFILE])
+ t2 = Rake.application.intern(FileTask, NEWFILE)
+ assert ! t2.needed?, "Should not need to build new file"
+ preq_stamp = t1.prerequisites.collect{|t| Task[t].timestamp}.max
+ assert_equal t2.timestamp, preq_stamp
+ assert t1.timestamp < preq_stamp, "T1 should be older"
+ assert t1.needed?, "Should need to rebuild old file because of new"
+ end
+
+ def test_file_depends_on_task_depend_on_file
+ create_timed_files(OLDFILE, NEWFILE)
+
+ file NEWFILE => [:obj] do |t| @runs << t.name end
+ task :obj => [OLDFILE] do |t| @runs << t.name end
+ file OLDFILE do |t| @runs << t.name end
+
+ Task[:obj].invoke
+ Task[NEWFILE].invoke
+ assert ! @runs.include?(NEWFILE)
+ end
+
+ def test_existing_file_depends_on_non_existing_file
+ @ran = false
+
+ create_file(OLDFILE)
+ delete_file(NEWFILE)
+ file NEWFILE do
+ @ran = true
+ end
+
+ file OLDFILE => NEWFILE
+
+ Task[OLDFILE].invoke
+
+ assert @ran
+ end
+
+ # I have currently disabled this test. I'm not convinced that
+ # deleting the file target on failure is always the proper thing to
+ # do. I'm willing to hear input on this topic.
+ def ztest_file_deletes_on_failure
+ task :obj
+ file NEWFILE => [:obj] do |t|
+ FileUtils.touch NEWFILE
+ fail "Ooops"
+ end
+ assert Task[NEWFILE]
+ begin
+ Task[NEWFILE].invoke
+ rescue Exception
+ end
+ assert( ! File.exist?(NEWFILE), "NEWFILE should be deleted")
+ end
+
+end
+