How to implement a new TaskLib in Rake

Hi all,

so my last attempt [1] at building a task for running RubyFIT tests
from within Rake has been successful, and simpler than I thought. In
fact, thanks to the online examples in the Rake wiki, I've been able to
come up with something nice enough to be a good first step for my aim.

But now I'd like to turn those tasks in a proper TaskLib, and things
seems to be really a bit thougher here. Has anyone had experience
doing that, and would like to share some insights? I've tried mimicking
the structure of testtask.rb, the TaskLib for running Unit Tests, but
Rake aborts every time I run my script because "don't know how to build
task". I've seen the error comes from rake.rb, but I didn't manage to
understand what the code is trying to do right there.

Thanks in advance to anyone willing to help.

Best Regards,
Giulio Piancastelli.

One of the things I've been thinking about for the next major version of Rake
is a better way to specify and use libraries of related tasks. Its still at
the "thinking about" stage yet, so don't hold your breath.

If you can post the details of what you are doing, I'd be glad to give a hand.

ยทยทยท

On Monday 21 March 2005 05:29 pm, Giulio Piancastelli wrote:

Hi all,

so my last attempt [1] at building a task for running RubyFIT tests
from within Rake has been successful, and simpler than I thought. In
fact, thanks to the online examples in the Rake wiki, I've been able to
come up with something nice enough to be a good first step for my aim.

But now I'd like to turn those tasks in a proper TaskLib, and things
seems to be really a bit thougher here. Has anyone had experience
doing that, and would like to share some insights? I've tried mimicking
the structure of testtask.rb, the TaskLib for running Unit Tests, but
Rake aborts every time I run my script because "don't know how to build
task". I've seen the error comes from rake.rb, but I didn't manage to
understand what the code is trying to do right there.

Thanks in advance to anyone willing to help.

--
-- Jim Weirich jim@weirichhouse.org http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

Jim Weirich wrote:

If you can post the details of what you are doing, I'd be glad to

give a hand.

Well, I took another shot at a TaskLib implementation, and perhaps
found what was wrong with my code. Initially I wrote:

module Rake
  class FitTestTask < TaskLib
    attr_accessor :name, :libs, :pattern
    def test_files=(list)
      @test_files = list
    end
    def initialize(name=:fittest)
      @name = name
      @libs = ["lib"]
      @pattern = nil
      @test_files = nil
      yield self if block_given?
      define
    end
    def define
      puts "Running FitTest tasklib with #@libs and tests #@test_files"
      self
    end
  end
end

And rake aborted with the error message I reported. Then,
reimplementing, I noticed that you were actually *defining* a task in
TestTask#define, so I came up with:

def define
  task @name do
    puts "Running FitTest tasklib with #@libs and tests #@test_files"
  end
  self
end

This way, Rake runs fine, even if I don't understand the internal
mechanics. So, must every task in the lib be defined at once in a
method called by the constructor? The pattern usage of tasks seems to
suggest that (it's always Rake::SomeTask.new {...}) but I'd like to
hear more about this.

And... is it just *that* easy? Or are there other details I should be
aware of?

I'll try to define my tasks in a lib now; I'll get back to the
newsgroup if I happen to face some problems, perhaps harder to think
about than the latest. Sorry to bother.

Best Regards,
Giulio Piancastelli.