nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 1 | # -*- ruby -*- |
| 2 | require 'rake/extensiontask' |
| 3 | require 'rspec/core/rake_task' |
Tim Emiola | e2860c5 | 2015-01-16 02:58:41 -0800 | [diff] [blame] | 4 | require 'rubocop/rake_task' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 5 | require 'bundler/gem_tasks' |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 6 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 7 | # Add rubocop style checking tasks |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 8 | RuboCop::RakeTask.new(:rubocop) do |task| |
| 9 | task.options = ['-c', 'src/ruby/.rubocop.yml'] |
| 10 | task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] |
| 11 | end |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 12 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 13 | # Add the extension compiler task |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 14 | Rake::ExtensionTask.new 'grpc' do |ext| |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 15 | 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') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 18 | end |
| 19 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 20 | # Define the test suites |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 21 | SPEC_SUITES = [ |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 22 | { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, |
| 23 | { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 24 | tags: ['~bidi', '~server'] }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 25 | { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 26 | tag: 'bidi' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 27 | { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 28 | tag: 'server' }, |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 29 | { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 30 | ] |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 31 | namespace :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 Emiola | c85c1ae | 2015-04-17 18:12:32 -0700 | [diff] [blame] | 35 | ENV['COVERAGE_NAME'] = suite[:id].to_s |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 36 | spec_files = [] |
| 37 | suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 38 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 39 | if suite[:dir] |
| 40 | suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } |
| 41 | end |
murgatroid99 | d7e1a10 | 2015-12-18 11:16:16 -0800 | [diff] [blame] | 42 | helper = 'src/ruby/spec/spec_helper.rb' |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 43 | spec_files << helper unless spec_files.include?(helper) |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 44 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 45 | 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(' ') |
nnoble | 097ef9b | 2014-12-01 17:06:10 -0800 | [diff] [blame] | 49 | end |
| 50 | end |
| 51 | end |
| 52 | end |
| 53 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 54 | # Define dependencies between the suites. |
| 55 | task 'suite:wrapper' => [:compile, :rubocop] |
| 56 | task 'suite:idiomatic' => 'suite:wrapper' |
| 57 | task 'suite:bidi' => 'suite:wrapper' |
| 58 | task 'suite:server' => 'suite:wrapper' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 59 | task 'suite:pb' => 'suite:server' |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 60 | |
Tim Emiola | f20d760 | 2015-03-24 08:11:47 -0700 | [diff] [blame] | 61 | desc 'Compiles the gRPC extension then runs all the tests' |
Tim Emiola | 975d0cb | 2015-08-14 10:44:17 -0700 | [diff] [blame] | 62 | task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] |
Tim Emiola | 397fda0 | 2015-01-29 13:26:21 -0800 | [diff] [blame] | 63 | task default: :all |