1require 'rubygems/test_case'
2require 'rubygems/ext'
3
4class TestGemExtBuilder < Gem::TestCase
5
6  def setup
7    super
8
9    @ext = File.join @tempdir, 'ext'
10    @dest_path = File.join @tempdir, 'prefix'
11
12    FileUtils.mkdir_p @ext
13    FileUtils.mkdir_p @dest_path
14
15    @orig_DESTDIR = ENV['DESTDIR']
16  end
17
18  def teardown
19    ENV['DESTDIR'] = @orig_DESTDIR
20
21    super
22  end
23
24  def test_class_make
25    ENV['DESTDIR'] = 'destination'
26    results = []
27
28    Dir.chdir @ext do
29      open 'Makefile', 'w' do |io|
30        io.puts <<-MAKEFILE
31all:
32\t@#{Gem.ruby} -e "puts %Q{all: \#{ENV['DESTDIR']}}"
33
34install:
35\t@#{Gem.ruby} -e "puts %Q{install: \#{ENV['DESTDIR']}}"
36        MAKEFILE
37      end
38
39      Gem::Ext::Builder.make @dest_path, results
40    end
41
42    results = results.join "\n"
43
44
45    if RUBY_VERSION > '2.0' then
46      assert_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%,         results
47      assert_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
48    else
49      refute_match %r%"DESTDIR=#{ENV['DESTDIR']}"$%,         results
50      refute_match %r%"DESTDIR=#{ENV['DESTDIR']}" install$%, results
51    end
52
53    if /nmake/ !~ results
54      assert_match %r%^all: destination$%,     results
55      assert_match %r%^install: destination$%, results
56    end
57  end
58
59end
60
61