require 'rake/testtask'
require 'rake/rdoctask'

desc "Genetate the parser using racc"
task :generate_parser do
  source = "lib/r2p/parser/parser.y"
  target = "lib/r2p/parser/parser.rb"
  unless uptodate?(target, source)
    sh "racc -g -o #{target} #{source}"
  end
end

namespace :test do
  Rake::TestTask.new(:unit) do |t|
    t.libs << "lib/r2p"
    t.pattern = "test/unit/**/*.rb"
  end
  task :unit => :generate_parser

  namespace :unit do
    desc "Run the unit tests coverage analysis using \"rcov\""
    task :rcov => :generate_parser do
      sh "rcov -Isrc -x 'test/unit/.*/.*\.rb' " +
        FileList["test/unit/**/*.rb"].to_s
    end

    desc "Clean the directory with results of the unit tests coverage analysis"
    task "rcov_clean" do
      rm_rf "coverage"
    end
  end

  desc "Run the command-line handling tests"
  task :command_line => :generate_parser do
    sh "test/command_line/run_tests.sh"
  end
end

desc "Run the unit, functional and command-line handling tests"
task :test => ["test:unit", "test:command_line"]

Rake::RDocTask.new do |rdoc|
  rdoc.template = "doc/jamis.rb"
  rdoc.options << "--line-numbers" << "--inline-source"
  rdoc.rdoc_files.add("lib/**/*.rb")
  rdoc.title = "R2P"
end

task :default  => :test

