require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/testtask'

merge_path_functionals = [
  'test/cart_functional/application_repository_func_test.rb',
  'test/cart_functional/application_state_func_test.rb',
  'test/cart_functional/bash_sdk_test.rb',
  'test/cart_functional/v2_cart_model_func_test.rb',
  'test/cart_functional/version_func_test.rb',
  'test/node_functional/application_container_func_test.rb',
  'test/node_functional/cartridge_repository_func_test.rb',
  'test/node_functional/cartridge_repository_web_func_test.rb',
  'test/node_functional/node_func_test.rb',
  'test/node_functional/oo_trap_user_func_test.rb',
  'test/node_functional/path_utils_test.rb',
  'test/node_functional/shell_exec_func_test.rb',
  'test/node_functional/unix_user_func_test.rb'
]

desc "Print environment to run from checkout - eval $( rake local_env | tail -n +1 )"
task :local_env do
  pwd = Dir.pwd
  puts "RUBYLIB='#{pwd}/lib/'; export RUBYLIB"
  puts "PATH='#{pwd}/bin/:#{ENV['PATH']}'; export PATH"
  puts "SS_CONFIG_DIR='#{pwd}/conf'; export SS_CONFIG_DIR"
end

desc "Unit tests"
Rake::TestTask.new(:unit_test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../lib', __FILE__)
  t.libs << File.expand_path('../../common/lib', __FILE__)
  t.pattern = 'test/unit/*_test.rb'
end

desc "Functional tests"
Rake::TestTask.new(:func_test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../lib', __FILE__)
  t.libs << File.expand_path('../../common/lib', __FILE__)
  t.pattern = 'test/*_functional/*_test.rb'
end

desc "All tests"
Rake::TestTask.new(:test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../lib', __FILE__)
  t.libs << File.expand_path('../../common/lib', __FILE__)
  t.pattern = 'test/**/*_test.rb'
end

desc "Merge-path tests"
Rake::TestTask.new(:essentials_test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../../common/lib', __FILE__)
  files = [ 'test/unit/*_test.rb' ]
  files.concat(merge_path_functionals)
  t.test_files = files
end

desc "Extended cart functional tests"
Rake::TestTask.new(:ext_cart_func_test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../../common/lib', __FILE__)

  all_functionals = Dir.glob('test/cart_functional/*_test.rb')

  t.test_files = all_functionals - merge_path_functionals
end

desc "Extended node functional tests"
Rake::TestTask.new(:ext_node_func_test) do |t|
  t.verbose = true
  t.libs << File.expand_path('../../common/lib', __FILE__)

  all_functionals = Dir.glob('test/node_functional/*_test.rb')

  t.test_files = all_functionals - merge_path_functionals
end

desc "Generate RDoc"
task :doc do
  sh "rdoc ."
end
