1require 'rubygems/test_case'
2require 'rubygems'
3require 'fileutils'
4
5class TestGemPathSupport < Gem::TestCase
6  def setup
7    super
8
9    ENV["GEM_HOME"] = @tempdir
10    ENV["GEM_PATH"] = [@tempdir, "something"].join(File::PATH_SEPARATOR)
11  end
12
13  def test_initialize
14    ps = Gem::PathSupport.new
15
16    assert_equal ENV["GEM_HOME"], ps.home
17
18    expected = util_path
19    assert_equal expected, ps.path, "defaults to GEM_PATH"
20  end
21
22  def test_initialize_home
23    ps = Gem::PathSupport.new "GEM_HOME" => "#{@tempdir}/foo"
24
25    assert_equal File.join(@tempdir, "foo"), ps.home
26
27    expected = util_path + [File.join(@tempdir, 'foo')]
28    assert_equal expected, ps.path
29  end
30
31  if defined?(File::ALT_SEPARATOR) and File::ALT_SEPARATOR
32    def test_initialize_home_normalize
33      alternate = @tempdir.gsub(File::SEPARATOR, File::ALT_SEPARATOR)
34      ps = Gem::PathSupport.new "GEM_HOME" => alternate
35
36      assert_equal @tempdir, ps.home, "normalize values"
37    end
38  end
39
40  def test_initialize_path
41    ps = Gem::PathSupport.new "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar]
42
43    assert_equal ENV["GEM_HOME"], ps.home
44
45    expected = [
46                File.join(@tempdir, 'foo'),
47                File.join(@tempdir, 'bar'),
48                ENV["GEM_HOME"],
49               ]
50
51    assert_equal expected, ps.path
52  end
53
54  def test_initialize_home_path
55    ps = Gem::PathSupport.new("GEM_HOME" => "#{@tempdir}/foo",
56                              "GEM_PATH" => %W[#{@tempdir}/foo #{@tempdir}/bar])
57
58    assert_equal File.join(@tempdir, "foo"), ps.home
59
60    expected = [File.join(@tempdir, 'foo'), File.join(@tempdir, 'bar')]
61    assert_equal expected, ps.path
62  end
63
64  def util_path
65    ENV["GEM_PATH"].split(File::PATH_SEPARATOR)
66  end
67end
68