class Rcov::RcovTask


rake rcov RCOVOPTS=“-T” # generate text report
rake rcov RCOVOPTS=“-p” # run in profile mode
rake rcov TEST=just_one_file.rb # run just one test file.
rake rcov # run tests normally
Examples:
PATH will be used.
then the given rcov executable will be used; otherwise the one in your
If rake is invoked with a “RCOVPATH=path/to/rcov” command line option,
then the given options are passed to rcov.
If rake is invoked with a “RCOVOPTS=options” command line option,
to run just one test.
filename specified on the command line. This provides an easy way
then the list of test files will be overridden to include only the
If rake is invoked with a “TEST=filename” command line option,
end
t.verbose = true
t.test_files = FileList[‘test/test*.rb’]
t.libs << “test”
Rcov::RcovTask.new do |t|
require ‘rcov/rcovtask’
Example:
coverage reports.
Create a task that runs a set of tests through rcov, generating code

def define

Create the tasks defined by this task lib.
def define
  lib_path = @libs.join(File::PATH_SEPARATOR)
  actual_name = Hash === name ? name.keys.first : name
  unless Rake.application.last_comment
    desc "Analyze code coverage with tests" + 
      (@name==:rcov ? "" : " for #{actual_name}")
  end
  task @name do
    run_code = ''
    RakeFileUtils.verbose(@verbose) do
      run_code =
      case rcov_path
      when nil, ''
        "-S rcov"
      else %!"#{rcov_path}"!
      end
      ruby_opts = @ruby_opts.clone
      ruby_opts.push( "-I#{lib_path}" )
      ruby_opts.push run_code
      ruby_opts.push( "-w" ) if @warning
      ruby ruby_opts.join(" ") + " " + option_list +
      %[ -o "#{@output_dir}" ] +
      file_list.collect { |fn| %["#{fn}"] }.join(' ')
    end
  end
  desc "Remove rcov products for #{actual_name}"
  task paste("clobber_", actual_name) do
    rm_r @output_dir rescue nil
  end
  clobber_task = paste("clobber_", actual_name)
  task :clobber => [clobber_task]
  task actual_name => clobber_task
  self
end

def file_list # :nodoc:

:nodoc:
def file_list # :nodoc:
  if ENV['TEST']
    FileList[ ENV['TEST'] ]
  else
    result = []
    result += @test_files.to_a if @test_files
    result += FileList[ @pattern ].to_a if @pattern
    FileList[result]
  end
end

def initialize(name=:rcov)

Create a testing task.
def initialize(name=:rcov)
  @name = name
  @libs = ["lib"]
  @pattern = nil
  @test_files = nil
  @verbose = false
  @warning = false
  @rcov_opts = ["--text-report"]
  @ruby_opts = []
  @ruby_opts << "--debug" if RUBY_PLATFORM == 'java'
  @output_dir = "coverage"
  yield self if block_given?
  @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
  define
end

def option_list # :nodoc:

:nodoc:
def option_list # :nodoc:
  ENV['RCOVOPTS'] || @rcov_opts.join(" ") || ""
end

def rcov_path # :nodoc:

:nodoc:
def rcov_path # :nodoc:
  ENV['RCOVPATH']
end

def test_files=(list)

used, then the list of test files is the union of the two.
FileList is acceptable). If both +pattern+ and +test_files+ are
test. +list+ is expected to be an array of file names (a
Explicitly define the list of test files to be included in a
def test_files=(list)
  @test_files = list
end