|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +if File.exist?('Gemfile') |
| 4 | + puts <<-WARNING |
| 5 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6 | +!! A Gemfile has been detected. This will likely cause some tests !! |
| 7 | +!! to erroneously fail (RSpec + Bundler shenanigans!). You may need !! |
| 8 | +!! to run tests from a different directory. !! |
| 9 | +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 10 | + WARNING |
| 11 | +end |
| 12 | + |
| 13 | +$:.push File.join(File.dirname(__FILE__), '..', 'lib') |
| 14 | + |
| 15 | +require 'concurrent/version' |
| 16 | +require_relative 'platform_helpers' |
| 17 | + |
| 18 | +EXT_PLATFORMS = { |
| 19 | + 'i686-linux' => 'x86-linux', |
| 20 | + 'x86_64-linux' => 'x86_64-linux', |
| 21 | + 'x86-mingw32' => 'x86-mingw32', |
| 22 | + 'x64-mingw32' => 'x64-mingw32', |
| 23 | + 'i386-solaris2.11' => 'x86-solaris-2.11', |
| 24 | + 'x86_64-darwin14.0' => 'x86_64-darwin-14', |
| 25 | +} |
| 26 | + |
| 27 | +TEST_PATH = File.dirname(__FILE__) |
| 28 | +PKG_PATH = File.join(File.dirname(__FILE__), '..', 'pkg') |
| 29 | + |
| 30 | +RSPEC = "rspec --default-path #{TEST_PATH} -fd --color --seed 0" |
| 31 | + |
| 32 | +UNINSTALL_GEMS_COMMAND = <<-CMD |
| 33 | +gem uninstall -q -a -I concurrent-ruby-ext |
| 34 | +gem uninstall -q -a -I concurrent-ruby |
| 35 | +gem uninstall -q -a -I ref |
| 36 | +CMD |
| 37 | + |
| 38 | +SUITE_BREAK = "######################################################################\n" |
| 39 | +GEM_BREAK = "----------------------------------------------------------------------\n" |
| 40 | + |
| 41 | +def platform_specific_extensions?(platform = RUBY_PLATFORM) |
| 42 | + EXT_PLATFORMS.keys.include?(platform) && |
| 43 | + File.exists?("#{PKG_PATH}/#{extension_gem_name(platform)}") |
| 44 | +end |
| 45 | + |
| 46 | +def extension_gem_name(platform = RUBY_PLATFORM) |
| 47 | + platform = EXT_PLATFORMS.fetch(platform, '') |
| 48 | + platform = '-' + platform unless platform.empty? |
| 49 | + "concurrent-ruby-ext-#{Concurrent::EXT_VERSION}#{platform}.gem" |
| 50 | +end |
| 51 | + |
| 52 | +def install_gems_command(ext, platform = '') |
| 53 | + cmd = "gem install #{PKG_PATH}/concurrent-ruby-#{Concurrent::VERSION}.gem" |
| 54 | + if ext |
| 55 | + cmd << "\ngem install #{PKG_PATH}/#{extension_gem_name(platform)}" |
| 56 | + end |
| 57 | + cmd |
| 58 | +end |
| 59 | + |
| 60 | +def install_java_gem_command |
| 61 | + "gem install #{PKG_PATH}/concurrent-ruby-#{Concurrent::VERSION}-java.gem" |
| 62 | +end |
| 63 | + |
| 64 | +def run_tests_cmd(file, ext, platform = '') |
| 65 | + test_platform = if ext |
| 66 | + 'EXT' |
| 67 | + elsif jruby?(platform) |
| 68 | + 'JRUBY' |
| 69 | + else |
| 70 | + 'RUBY' |
| 71 | + end |
| 72 | + |
| 73 | + cmd = if jruby?(platform) |
| 74 | + install_java_gem_command |
| 75 | + else |
| 76 | + install_gems_command(ext, platform) |
| 77 | + end |
| 78 | + |
| 79 | + cmd << "\n" |
| 80 | + cmd << "TEST_PLATFORM='#{test_platform}' #{RSPEC} #{file}" |
| 81 | + cmd << "\n" |
| 82 | + cmd << UNINSTALL_GEMS_COMMAND |
| 83 | + cmd |
| 84 | +end |
| 85 | + |
| 86 | +TESTS = Dir["#{TEST_PATH}/*_spec.rb"] |
| 87 | +ok = system(UNINSTALL_GEMS_COMMAND) |
| 88 | + |
| 89 | +TESTS.each do |file| |
| 90 | + puts SUITE_BREAK |
| 91 | + puts "Running #{file}" |
| 92 | + puts GEM_BREAK |
| 93 | + ok = system(run_tests_cmd(file, false)) |
| 94 | + if jruby? |
| 95 | + puts GEM_BREAK |
| 96 | + ok = system(run_tests_cmd(file, false, 'jruby')) |
| 97 | + elsif mri? |
| 98 | + puts GEM_BREAK |
| 99 | + ok = system(run_tests_cmd(file, true)) |
| 100 | + if platform_specific_extensions?(RUBY_PLATFORM) |
| 101 | + puts GEM_BREAK |
| 102 | + ok = system(run_tests_cmd(file, true, RUBY_PLATFORM)) |
| 103 | + end |
| 104 | + end |
| 105 | +end |
0 commit comments