blob: 079df6799628d9f1d8147480c8e10c038822f3d0 [file] [log] [blame]
nnoble097ef9b2014-12-01 17:06:10 -08001# -*- ruby -*-
2require 'rake/extensiontask'
3require 'rspec/core/rake_task'
Tim Emiolae2860c52015-01-16 02:58:41 -08004require 'rubocop/rake_task'
Tim Emiolaf20d7602015-03-24 08:11:47 -07005require 'bundler/gem_tasks'
nnoble097ef9b2014-12-01 17:06:10 -08006
Tim Emiolaf20d7602015-03-24 08:11:47 -07007# Add rubocop style checking tasks
murgatroid99d7e1a102015-12-18 11:16:16 -08008RuboCop::RakeTask.new(:rubocop) do |task|
9 task.options = ['-c', 'src/ruby/.rubocop.yml']
10 task.patterns = ['src/ruby/{lib,spec}/**/*.rb']
11end
nnoble097ef9b2014-12-01 17:06:10 -080012
Tim Emiolaf20d7602015-03-24 08:11:47 -070013# Add the extension compiler task
nnoble097ef9b2014-12-01 17:06:10 -080014Rake::ExtensionTask.new 'grpc' do |ext|
murgatroid99d7e1a102015-12-18 11:16:16 -080015 ext.source_pattern = '**/*.{c,h}'
16 ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc')
17 ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
nnoble097ef9b2014-12-01 17:06:10 -080018end
19
Tim Emiolaf20d7602015-03-24 08:11:47 -070020# Define the test suites
nnoble097ef9b2014-12-01 17:06:10 -080021SPEC_SUITES = [
murgatroid99d7e1a102015-12-18 11:16:16 -080022 { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) },
23 { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080024 tags: ['~bidi', '~server'] },
murgatroid99d7e1a102015-12-18 11:16:16 -080025 { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic),
Tim Emiola397fda02015-01-29 13:26:21 -080026 tag: 'bidi' },
murgatroid99d7e1a102015-12-18 11:16:16 -080027 { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic),
Tim Emiola975d0cb2015-08-14 10:44:17 -070028 tag: 'server' },
murgatroid99d7e1a102015-12-18 11:16:16 -080029 { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) }
nnoble097ef9b2014-12-01 17:06:10 -080030]
Tim Emiolaf20d7602015-03-24 08:11:47 -070031namespace :suite do
32 SPEC_SUITES.each do |suite|
33 desc "Run all specs in the #{suite[:title]} spec suite"
34 RSpec::Core::RakeTask.new(suite[:id]) do |t|
Tim Emiolac85c1ae2015-04-17 18:12:32 -070035 ENV['COVERAGE_NAME'] = suite[:id].to_s
Tim Emiolaf20d7602015-03-24 08:11:47 -070036 spec_files = []
37 suite[:files].each { |f| spec_files += Dir[f] } if suite[:files]
nnoble097ef9b2014-12-01 17:06:10 -080038
Tim Emiolaf20d7602015-03-24 08:11:47 -070039 if suite[:dir]
40 suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] }
41 end
murgatroid99d7e1a102015-12-18 11:16:16 -080042 helper = 'src/ruby/spec/spec_helper.rb'
Tim Emiolaf20d7602015-03-24 08:11:47 -070043 spec_files << helper unless spec_files.include?(helper)
nnoble097ef9b2014-12-01 17:06:10 -080044
Tim Emiolaf20d7602015-03-24 08:11:47 -070045 t.pattern = spec_files
46 t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag]
47 if suite[:tags]
48 t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ')
nnoble097ef9b2014-12-01 17:06:10 -080049 end
50 end
51 end
52end
53
Tim Emiolaf20d7602015-03-24 08:11:47 -070054# Define dependencies between the suites.
55task 'suite:wrapper' => [:compile, :rubocop]
56task 'suite:idiomatic' => 'suite:wrapper'
57task 'suite:bidi' => 'suite:wrapper'
58task 'suite:server' => 'suite:wrapper'
Tim Emiola975d0cb2015-08-14 10:44:17 -070059task 'suite:pb' => 'suite:server'
Tim Emiola397fda02015-01-29 13:26:21 -080060
Tim Emiolaf20d7602015-03-24 08:11:47 -070061desc 'Compiles the gRPC extension then runs all the tests'
Tim Emiola975d0cb2015-08-14 10:44:17 -070062task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server']
Tim Emiola397fda02015-01-29 13:26:21 -080063task default: :all