rake icon indicating copy to clipboard operation
rake copied to clipboard

Request: An alternate FileTask that checks whether the file was made

Open bmundt6 opened this issue 4 years ago • 0 comments

I think the current implementation of the file task makes perfect sense: just trigger a series of actions based on a file's status, in case you don't necessarily want to actually produce that file.

However, in cases where you do want to produce that file, it would be nice to have a separate task type that supports that, i.e. fails if the task actions don't produce the file even when there are no exceptions thrown.

Example:

class Rake::RequiredFileTask < Rake::FileTask                  
  def execute(*args)                                          
    super(*args)                                              
    File.exists?(name) or raise "File #{name} was not created successfully"
  end                                                                      
end                                                                        

module Rake::DSL
  def required_file(*args, &block) # :doc:
    Rake::RequiredFileTask.define_task(*args, &block)
  end                                                
end

Then, if invoked as:

required_file 'a.out' do |t|
  # do nothing
end

an error would be thrown:

rake aborted!
File a.out was not created successfully

bmundt6 avatar Mar 11 '20 20:03 bmundt6