1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/mkmf/base.rb
nobu 5cb9711323 * test/mkmf/base.rb (TestMkmf::FakeLog): capture output from mkmf.
* test/mkmf/test_find_executable.rb (test_find_executable):
  suppress meaningless diffrences for chkbuild.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30239 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-12-17 10:35:20 +00:00

91 lines
1.7 KiB
Ruby

require 'test/unit'
require 'mkmf'
require 'tmpdir'
$extout = '$(topdir)/'+RbConfig::CONFIG["EXTOUT"]
RbConfig::CONFIG['topdir'] = CONFIG['topdir'] = File.expand_path(CONFIG['topdir'])
RbConfig::CONFIG["extout"] = CONFIG["extout"] = $extout
$INCFLAGS << " -I."
$extout_prefix = "$(extout)$(target_prefix)/"
class TestMkmf < Test::Unit::TestCase
MKMFLOG = proc {File.read("mkmf.log") rescue ""}
class << MKMFLOG
alias to_s call
end
class Capture
def initialize
@buffer = ""
@filter = nil
@out = true
end
def clear
@buffer.clear
end
def flush
STDOUT.print @filter ? @filter.call(@buffer) : @buffer
clear
end
def reopen(io)
case io
when Capture
initialize_copy(io)
when File
@out = false
when IO
@out = true
else
@out = false
end
end
def filter(&block)
@filter = block
end
def write(s)
@buffer << s if @out
end
end
attr_reader :stdout
def mkmflog(msg)
log = proc {MKMFLOG[] << msg}
class << log
alias to_s call
end
log
end
def setup
@tmpdir = Dir.mktmpdir
@curdir = Dir.pwd
@mkmfobj = Object.new
@stdout = Capture.new
Dir.chdir(@tmpdir)
@quiet, Logging.quiet = Logging.quiet, true
end
def teardown
Logging.quiet = @quiet
Logging.log_close
Dir.chdir(@curdir)
FileUtils.rm_rf(@tmpdir)
end
def mkmf(*args, &block)
@stdout.clear
stdout, $stdout = $stdout, @stdout
@mkmfobj.instance_eval(*args, &block)
ensure
$stdout = stdout
end
def config_value(name)
create_tmpsrc("---config-value=#{name}")
xpopen(cpp_command('')) do |f|
f.grep(/^---config-value=(.*)/) {return $1}
end
nil
end
end