2011-06-23 18:11:55 -04:00
|
|
|
require File.expand_path('../helper', __FILE__)
|
2009-10-02 15:07:55 -04:00
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
######################################################################
|
2011-06-23 18:11:55 -04:00
|
|
|
class TestRakeFileCreationTask < Rake::TestCase
|
2009-10-02 15:07:55 -04:00
|
|
|
include Rake
|
2011-06-23 18:11:55 -04:00
|
|
|
include Rake::DSL
|
2009-10-02 15:07:55 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
DUMMY_DIR = 'dummy_dir'
|
2009-10-02 15:07:55 -04:00
|
|
|
|
|
|
|
def setup
|
2011-06-23 18:11:55 -04:00
|
|
|
super
|
2009-10-02 15:07:55 -04:00
|
|
|
|
2011-06-23 18:11:55 -04:00
|
|
|
Task.clear
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_needed
|
|
|
|
create_dir DUMMY_DIR
|
|
|
|
fc_task = Task[DUMMY_DIR]
|
|
|
|
assert_equal DUMMY_DIR, fc_task.name
|
|
|
|
FileUtils.rm_rf fc_task.name
|
|
|
|
assert fc_task.needed?, "file should be needed"
|
|
|
|
FileUtils.mkdir fc_task.name
|
2013-10-11 17:35:01 -04:00
|
|
|
assert_equal nil, fc_task.prerequisites.map { |n| Task[n].timestamp }.max
|
2009-10-02 15:07:55 -04:00
|
|
|
assert ! fc_task.needed?, "file should not be needed"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_directory
|
|
|
|
directory DUMMY_DIR
|
|
|
|
fc_task = Task[DUMMY_DIR]
|
|
|
|
assert_equal DUMMY_DIR, fc_task.name
|
|
|
|
assert FileCreationTask === fc_task
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_retriggers_on_filecreate_task
|
|
|
|
create_timed_files(OLDFILE, NEWFILE)
|
|
|
|
t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
|
|
|
|
t2 = Rake.application.intern(FileCreationTask, NEWFILE)
|
|
|
|
assert ! t2.needed?, "Should not need to build new file"
|
|
|
|
assert ! t1.needed?, "Should not need to rebuild old file because of new"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_retriggers_on_file_task
|
|
|
|
create_timed_files(OLDFILE, NEWFILE)
|
|
|
|
t1 = Rake.application.intern(FileCreationTask, OLDFILE).enhance([NEWFILE])
|
|
|
|
t2 = Rake.application.intern(FileCreationTask, NEWFILE)
|
|
|
|
assert ! t2.needed?, "Should not need to build new file"
|
|
|
|
assert ! t1.needed?, "Should not need to rebuild old file because of new"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_very_early_timestamp
|
|
|
|
t1 = Rake.application.intern(FileCreationTask, OLDFILE)
|
|
|
|
assert t1.timestamp < Time.now
|
2013-10-11 17:35:01 -04:00
|
|
|
assert t1.timestamp < Time.now - 1_000_000
|
2009-10-02 15:07:55 -04:00
|
|
|
end
|
|
|
|
end
|