~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to test/mkmf/base.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
$extout_prefix = "$(extout)$(target_prefix)/"
10
10
 
11
11
class TestMkmf < Test::Unit::TestCase
 
12
  MKMFLOG = proc {File.read("mkmf.log") rescue ""}
 
13
  class << MKMFLOG
 
14
    alias to_s call
 
15
  end
 
16
 
 
17
  class Capture
 
18
    def initialize
 
19
      @buffer = ""
 
20
      @filter = nil
 
21
      @out = true
 
22
    end
 
23
    def clear
 
24
      @buffer.clear
 
25
    end
 
26
    def flush
 
27
      STDOUT.print @filter ? @filter.call(@buffer) : @buffer
 
28
      clear
 
29
    end
 
30
    def reopen(io)
 
31
      case io
 
32
      when Capture
 
33
        initialize_copy(io)
 
34
      when File
 
35
        @out = false
 
36
      when IO
 
37
        @out = true
 
38
      else
 
39
        @out = false
 
40
      end
 
41
    end
 
42
    def filter(&block)
 
43
      @filter = block
 
44
    end
 
45
    def write(s)
 
46
      @buffer << s if @out
 
47
    end
 
48
  end
 
49
 
 
50
  attr_reader :stdout
 
51
 
 
52
  def mkmflog(msg)
 
53
    log = proc {MKMFLOG[] << msg}
 
54
    class << log
 
55
      alias to_s call
 
56
    end
 
57
    log
 
58
  end
 
59
 
12
60
  def setup
 
61
    @rbconfig = rbconfig0 = RbConfig::CONFIG
 
62
    @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
 
63
    rbconfig = {
 
64
      "hdrdir" => $hdrdir,
 
65
      "srcdir" => $srcdir,
 
66
      "topdir" => $topdir,
 
67
    }
 
68
    mkconfig = {
 
69
      "hdrdir" => "$(top_srcdir)/include",
 
70
      "srcdir" => "$(top_srcdir)/ext/#{$mdir}",
 
71
      "topdir" => $topdir,
 
72
    }
 
73
    rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
 
74
    mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
 
75
    RbConfig.module_eval {
 
76
      remove_const(:CONFIG)
 
77
      const_set(:CONFIG, rbconfig)
 
78
      remove_const(:MAKEFILE_CONFIG)
 
79
      const_set(:MAKEFILE_CONFIG, mkconfig)
 
80
    }
 
81
    Object.class_eval {
 
82
      remove_const(:CONFIG)
 
83
      const_set(:CONFIG, mkconfig)
 
84
    }
13
85
    @tmpdir = Dir.mktmpdir
14
86
    @curdir = Dir.pwd
15
87
    @mkmfobj = Object.new
 
88
    @stdout = Capture.new
16
89
    Dir.chdir(@tmpdir)
17
 
    class << (@output = "")
18
 
      def flush; end
19
 
      def reopen(*) end
20
 
      alias write <<
21
 
    end
22
 
    $stdout = @output
 
90
    @quiet, Logging.quiet = Logging.quiet, true
 
91
    init_mkmf
 
92
    $INCFLAGS[0, 0] = "-I. "
23
93
  end
24
94
 
25
95
  def teardown
26
 
    $stdout = STDOUT
 
96
    rbconfig0 = @rbconfig
 
97
    mkconfig0 = @mkconfig
 
98
    RbConfig.module_eval {
 
99
      remove_const(:CONFIG)
 
100
      const_set(:CONFIG, rbconfig0)
 
101
      remove_const(:MAKEFILE_CONFIG)
 
102
      const_set(:MAKEFILE_CONFIG, mkconfig0)
 
103
    }
 
104
    Object.class_eval {
 
105
      remove_const(:CONFIG)
 
106
      const_set(:CONFIG, mkconfig0)
 
107
    }
 
108
    Logging.quiet = @quiet
 
109
    Logging.log_close
27
110
    Dir.chdir(@curdir)
28
111
    FileUtils.rm_rf(@tmpdir)
29
112
  end
30
113
 
31
114
  def mkmf(*args, &block)
 
115
    @stdout.clear
 
116
    stdout, $stdout = $stdout, @stdout
32
117
    @mkmfobj.instance_eval(*args, &block)
 
118
  ensure
 
119
    $stdout = stdout
 
120
  end
 
121
 
 
122
  def config_value(name)
 
123
    create_tmpsrc("---config-value=#{name}")
 
124
    xpopen(cpp_command('')) do |f|
 
125
      f.grep(/^---config-value=(.*)/) {return $1}
 
126
    end
 
127
    nil
33
128
  end
34
129
end