You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testing.rake 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. namespace :test do
  2. desc 'Measures test coverage'
  3. task :coverage do
  4. rm_f "coverage"
  5. ENV["COVERAGE"] = "1"
  6. Rake::Task["test"].invoke
  7. end
  8. desc 'Run unit and functional scm tests'
  9. task :scm do
  10. errors = %w(test:scm:units test:scm:functionals).collect do |task|
  11. begin
  12. Rake::Task[task].invoke
  13. nil
  14. rescue => e
  15. task
  16. end
  17. end.compact
  18. abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?
  19. end
  20. namespace :scm do
  21. namespace :setup do
  22. desc "Creates directory for test repositories"
  23. task :create_dir => :environment do
  24. FileUtils.mkdir_p Rails.root + '/tmp/test'
  25. end
  26. supported_scms = [:subversion, :cvs, :bazaar, :mercurial, :git, :filesystem]
  27. desc "Creates a test subversion repository"
  28. task :subversion => :create_dir do
  29. repo_path = "tmp/test/subversion_repository"
  30. unless File.exists?(repo_path)
  31. system "svnadmin create #{repo_path}"
  32. system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}"
  33. end
  34. end
  35. desc "Creates a test mercurial repository"
  36. task :mercurial => :create_dir do
  37. repo_path = "tmp/test/mercurial_repository"
  38. unless File.exists?(repo_path)
  39. bundle_path = "test/fixtures/repositories/mercurial_repository.hg"
  40. system "hg init #{repo_path}"
  41. system "hg -R #{repo_path} pull #{bundle_path}"
  42. end
  43. end
  44. def extract_tar_gz(prefix)
  45. unless File.exists?("tmp/test/#{prefix}_repository")
  46. # system "gunzip < test/fixtures/repositories/#{prefix}_repository.tar.gz | tar -xv -C tmp/test"
  47. system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{prefix}_repository.tar.gz"
  48. end
  49. end
  50. (supported_scms - [:subversion, :mercurial]).each do |scm|
  51. desc "Creates a test #{scm} repository"
  52. task scm => :create_dir do
  53. extract_tar_gz(scm)
  54. end
  55. end
  56. desc "Creates all test repositories"
  57. task :all => supported_scms
  58. end
  59. desc "Updates installed test repositories"
  60. task :update => :environment do
  61. require 'fileutils'
  62. Dir.glob("tmp/test/*_repository").each do |dir|
  63. next unless File.basename(dir) =~ %r{^(.+)_repository$} && File.directory?(dir)
  64. scm = $1
  65. next unless fixture = Dir.glob("test/fixtures/repositories/#{scm}_repository.*").first
  66. next if File.stat(dir).ctime > File.stat(fixture).mtime
  67. FileUtils.rm_rf dir
  68. Rake::Task["test:scm:setup:#{scm}"].execute
  69. end
  70. end
  71. task(:units => "db:test:prepare") do |t|
  72. $: << "test"
  73. Rails::TestUnit::Runner.rake_run FileList['test/unit/repository*_test.rb'] + FileList['test/unit/lib/redmine/scm/**/*_test.rb']
  74. end
  75. Rake::Task['test:scm:units'].comment = "Run the scm unit tests"
  76. task(:functionals => "db:test:prepare") do |t|
  77. $: << "test"
  78. Rails::TestUnit::Runner.rake_run FileList['test/functional/repositories*_test.rb']
  79. end
  80. Rake::Task['test:scm:functionals'].comment = "Run the scm functional tests"
  81. end
  82. task(:routing) do |t|
  83. $: << "test"
  84. Rails::TestUnit::Runner.rake_run FileList['test/integration/routing/*_test.rb'] + FileList['test/integration/api_test/*_routing_test.rb']
  85. end
  86. Rake::Task['test:routing'].comment = "Run the routing tests"
  87. end