2009-08-06 00:14:50 -04:00
|
|
|
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
|
2009-11-25 21:42:24 -05:00
|
|
|
$INCFLAGS << " -I."
|
2009-08-06 00:14:50 -04:00
|
|
|
$extout_prefix = "$(extout)$(target_prefix)/"
|
|
|
|
|
2009-08-06 00:30:15 -04:00
|
|
|
class TestMkmf < Test::Unit::TestCase
|
2010-12-10 04:11:10 -05:00
|
|
|
MKMFLOG = proc {File.read("mkmf.log") rescue ""}
|
|
|
|
class << MKMFLOG
|
|
|
|
alias to_s call
|
|
|
|
end
|
2010-12-17 05:35:20 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-12-10 04:11:48 -05:00
|
|
|
def mkmflog(msg)
|
|
|
|
log = proc {MKMFLOG[] << msg}
|
|
|
|
class << log
|
|
|
|
alias to_s call
|
|
|
|
end
|
|
|
|
log
|
|
|
|
end
|
2010-12-10 04:11:10 -05:00
|
|
|
|
2009-08-06 00:14:50 -04:00
|
|
|
def setup
|
|
|
|
@tmpdir = Dir.mktmpdir
|
|
|
|
@curdir = Dir.pwd
|
|
|
|
@mkmfobj = Object.new
|
2010-12-17 05:35:20 -05:00
|
|
|
@stdout = Capture.new
|
2009-08-06 00:14:50 -04:00
|
|
|
Dir.chdir(@tmpdir)
|
2010-12-06 09:18:26 -05:00
|
|
|
@quiet, Logging.quiet = Logging.quiet, true
|
2009-08-06 00:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2010-12-06 09:18:26 -05:00
|
|
|
Logging.quiet = @quiet
|
2010-12-10 04:11:10 -05:00
|
|
|
Logging.log_close
|
2009-08-06 00:14:50 -04:00
|
|
|
Dir.chdir(@curdir)
|
|
|
|
FileUtils.rm_rf(@tmpdir)
|
|
|
|
end
|
|
|
|
|
|
|
|
def mkmf(*args, &block)
|
2010-12-17 05:35:20 -05:00
|
|
|
@stdout.clear
|
|
|
|
stdout, $stdout = $stdout, @stdout
|
2009-08-06 00:14:50 -04:00
|
|
|
@mkmfobj.instance_eval(*args, &block)
|
2010-12-17 05:35:20 -05:00
|
|
|
ensure
|
|
|
|
$stdout = stdout
|
2009-08-06 00:14:50 -04:00
|
|
|
end
|
2010-12-10 04:12:33 -05:00
|
|
|
|
|
|
|
def config_value(name)
|
|
|
|
create_tmpsrc("---config-value=#{name}")
|
|
|
|
xpopen(cpp_command('')) do |f|
|
|
|
|
f.grep(/^---config-value=(.*)/) {return $1}
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
2009-08-06 00:14:50 -04:00
|
|
|
end
|