Blame SOURCES/test_dependent_scls.rb

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