# The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # the default task is to run both the unit and functional tests # functional tests require that a solr test server is running # but this Rakefil should take care of starting and stopping it # for you # # if you just want to run unit tests: # # rake test_units # # and if you just want to run functional tests # # rake test_functionals # # if you would like to see solr startup messages on STDERR # when starting solr test server during functional tests use: # # rake SOLR_CONSOLE=true SOLRB_VERSION = '0.0.1' require 'rubygems' require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'rake/packagetask' require 'rake/gempackagetask' require 'test/functional/test_solr_server' task :default => [:test_units] spec = Gem::Specification.new do |s| s.name = 'solrb' s.version = SOLRB_VERSION s.author = 'Apache Solr' s.email = 'solr-user@lucene.apache.org' s.homepage = 'http://wiki.apache.org/solr/Flare' s.platform = Gem::Platform::RUBY s.summary = 'Ruby library for working with Apache Solr' # Omit functional tests from gem for now, as that requires a Solr instance s.files = Dir.glob("lib/**/*").concat(Dir.glob("test/unit/**/*")) s.require_path = 'lib' s.autorequire = 'solr' s.has_rdoc = true end Rake::GemPackageTask.new(spec) do |pkg| pkg.need_zip = true pkg.need_tar = true end namespace :package do desc "Package solrb for use in Rails' /vendor directory. Takes an optional DIR parameter which is the root of the Rails app you'd like to package this for." task :vendor do require "fileutils" current_dir = File.dirname(__FILE__) vendor_dir = File.join(ENV["DIR"] || File.join(current_dir, "pkg"), "vendor") solr_dir = File.join(vendor_dir, "solr") File.makedirs(solr_dir) Dir.glob(File.join(current_dir, "lib", "**", "*")).each do |d| new_d = d.gsub(File.join(current_dir, "lib"), vendor_dir) if File.directory?(d) File.makedirs(new_d) elsif d =~ /solr\.rb$/ File.cp(d, File.join(solr_dir, "solr.rb")) elsif d !~ /.svn/ File.cp(d, new_d) end end end end desc "Generate rdoc documentation" Rake::RDocTask.new('doc') do |rd| rd.rdoc_files.include("lib/**/*.rb") rd.rdoc_files.include('README', 'CHANGES.txt', 'LICENSE.txt') rd.main = 'README' rd.rdoc_dir = 'doc' end desc "Run unit tests" Rake::TestTask.new(:test_units) do |t| t.pattern = 'test/unit/*_test.rb' t.verbose = true t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/unit'] end # NOTE: test_functionals does not work standalone currently. It needs the TestSolrServer wrapper in the :test task Rake::TestTask.new(:test_functionals) do |t| t.pattern = 'test/functional/*_test.rb' t.verbose = true t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/functional'] end desc "Run unit and functional tests" task :test => [:test_units] do rm_rf "test/data" # remove functional test temp data directory # wrap functional tests with a test-specific Solr server got_error = TestSolrServer.wrap(:quiet => ENV['SOLR_CONSOLE'] ? false : true) do Rake::Task[:test_functionals].invoke end raise "test failures" if got_error end # TODO: consider replacing system() to rcov with the included # Rake task: http://eigenclass.org/hiki.rb?cmd=view&p=rcov+FAQ&key=rake namespace :test do desc 'Measures test coverage' # borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask task :coverage do rm_rf "coverage" rm_rf "coverage.data" TestSolrServer.wrap(:quiet => ENV['SOLR_CONSOLE'] ? false : true) do system("rcov --aggregate coverage.data --text-summary -Ilib:test/functional test/functional/*_test.rb") end system("rcov --aggregate coverage.data --text-summary -Ilib:test/unit test/unit/*_test.rb") system("open coverage/index.html") if PLATFORM['darwin'] end end def egrep(pattern) Dir['**/*.rb'].each do |fn| count = 0 open(fn) do |f| while line = f.gets count += 1 if line =~ pattern puts "#{fn}:#{count}:#{line}" end end end end end desc "Report TODO/FIXME/TBD tags in the code" task :todo do egrep /#.*(FIXME|TODO|TBD)/ end