Blame SOURCES/test_dependent_scls.rb

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