Blame SOURCES/test_dependent_scls.rb

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