Blame SOURCES/test_dependent_scls.rb

e076ba
require 'test/unit'
e076ba
require 'rbconfig'
e076ba
require 'rubygems'
e076ba
require 'rubygems/defaults/operating_system'
e076ba
e076ba
class TestDependentSCLS < Test::Unit::TestCase
e076ba
e076ba
  def setup
e076ba
    # TODO: Different bin dir during build ("/builddir/build/BUILD/ruby-2.0.0-p247")
e076ba
    @bin_dir = Gem::ConfigMap[:bindir].split(File::SEPARATOR).last
e076ba
    @scl_root = '/opt/rh/@SCL@/root'
e076ba
e076ba
    @env_orig = ['X_SCLS', 'GEM_PATH'].inject({}) do |env_orig, key|
e076ba
      env_orig[key] = ENV[key].dup
e076ba
      env_orig
e076ba
    end
e076ba
  end
e076ba
e076ba
  def teardown
e076ba
    # Avoid caching
e076ba
    Gem.class_eval("@x_scls, @default_locations, @default_dirs, @get_default_dirs = nil, nil, nil, nil")
e076ba
e076ba
    @env_orig.each { |key, val| ENV[key] = val }
e076ba
  end
e076ba
e076ba
  def test_default_paths
e076ba
    ENV['X_SCLS'] = '@SCL@' # enabled scls
e076ba
e076ba
    default_locations = { :system => "#{@scl_root}/usr",
e076ba
                          :local  => "#{@scl_root}/usr/local" }
e076ba
    assert_equal default_locations, Gem.default_locations
e076ba
e076ba
    default_dirs = { :system => { :bin_dir => "#{@scl_root}/usr/#{@bin_dir}",
e076ba
                                  :gem_dir => "#{@scl_root}/usr/share/gems",
e076ba
                                  :ext_dir => "#{@scl_root}/usr/lib64/gems" },
e076ba
                     :local  => { :bin_dir => "#{@scl_root}/usr/local/#{@bin_dir}",
e076ba
                                  :gem_dir => "#{@scl_root}/usr/local/share/gems",
e076ba
                                  :ext_dir => "#{@scl_root}/usr/local/lib64/gems" } }
e076ba
    assert_equal default_dirs, Gem.default_dirs
e076ba
  end
e076ba
e076ba
  # Gem.default_locations and Gem.default_dirs
e076ba
  # should contain paths to dependent scls binary extensions
e076ba
  # if the dependent scl adds itself on $GEM_PATH
e076ba
  #
e076ba
  # See rhbz#1034639
e076ba
  def test_paths_with_dependent_scl
e076ba
    test_scl = 'ruby_x'
e076ba
    test_root = "/some/prefix/#{test_scl}/root"
e076ba
e076ba
    ENV['X_SCLS'] = "@SCL@ #{test_scl}" # enabled scls
e076ba
    ENV['GEM_PATH'] = "#{test_root}/usr/share/gems"
e076ba
e076ba
    default_locations = { :system => "#{@scl_root}/usr",
e076ba
                          :local  => "#{@scl_root}/usr/local",
e076ba
                          :"#{test_scl}_system" => "#{test_root}/usr",
e076ba
                          :"#{test_scl}_local"  => "#{test_root}/usr/local" }
e076ba
    assert_equal default_locations, Gem.default_locations
e076ba
e076ba
    default_dirs =  { :system => { :bin_dir => "#{@scl_root}/usr/#{@bin_dir}",
e076ba
                                   :gem_dir => "#{@scl_root}/usr/share/gems",
e076ba
                                   :ext_dir => "#{@scl_root}/usr/lib64/gems" },
e076ba
                      :local  => { :bin_dir => "#{@scl_root}/usr/local/#{@bin_dir}",
e076ba
                                   :gem_dir => "#{@scl_root}/usr/local/share/gems",
e076ba
                                   :ext_dir => "#{@scl_root}/usr/local/lib64/gems" },
e076ba
                      :"#{test_scl}_system" => { :bin_dir => "#{test_root}/usr/#{@bin_dir}",
e076ba
                                                 :gem_dir => "#{test_root}/usr/share/gems",
e076ba
                                                 :ext_dir => "#{test_root}/usr/lib64/gems" },
e076ba
                      :"#{test_scl}_local"  => { :bin_dir => "#{test_root}/usr/local/#{@bin_dir}",
e076ba
                                                 :gem_dir => "#{test_root}/usr/local/share/gems",
e076ba
                                                 :ext_dir => "#{test_root}/usr/local/lib64/gems" } }
e076ba
    assert_equal default_dirs, Gem.default_dirs
e076ba
  end
e076ba
e076ba
  def test_empty_x_scls
e076ba
    ENV['X_SCLS'] = nil # no enabled scls
e076ba
e076ba
    default_locations = { :system => "#{@scl_root}/usr",
e076ba
                          :local  => "#{@scl_root}/usr/local" }
e076ba
    assert_equal default_locations, Gem.default_locations
e076ba
e076ba
    default_dirs = { :system => { :bin_dir => "#{@scl_root}/usr/#{@bin_dir}",
e076ba
                                  :gem_dir => "#{@scl_root}/usr/share/gems",
e076ba
                                  :ext_dir => "#{@scl_root}/usr/lib64/gems" },
e076ba
                     :local  => { :bin_dir => "#{@scl_root}/usr/local/#{@bin_dir}",
e076ba
                                  :gem_dir => "#{@scl_root}/usr/local/share/gems",
e076ba
                                  :ext_dir => "#{@scl_root}/usr/local/lib64/gems" } }
e076ba
    assert_equal default_dirs, Gem.default_dirs
e076ba
  end
e076ba
e076ba
end