test/test_generator.rb in mkrf-0.1.0 vs test/test_generator.rb in mkrf-0.1.1

- old
+ new

@@ -1,74 +1,85 @@ require File.dirname(__FILE__) + '/abstract_unit' +# stubb this out so we don't overwrite our test rakefile +module Mkrf + class Generator + def write_rakefile(file = "Rakefile") + end + end +end + class TestGenerator < Test::Unit::TestCase - SAMPLES_DIR = File.dirname(__FILE__) + '/sample_files' - - SAMPLE_LIBS = { - :libtrivial => '/libtrivial/libtrivial_so.bundle', - :syck => '/syck-0.55/ext/ruby/ext/syck/syck.bundle', - :libxml => '/libxml-ruby-0.3.8/ext/xml/libxml_so.bundle' - } - - # Set to true for full command line output - @@debug = false - def setup - silence_command_line do - system('rake test:samples:clean') - end + FileUtils.rm_f 'mkrf.log' end - def test_that_trivial_lib_compiles - assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libtrivial]) - silence_command_line do - system('rake test:samples:trivial') - end - assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libtrivial]) + def test_default_sources + g = Mkrf::Generator.new('testlib') + assert_equal ["'lib/*.c'"], g.sources, "Default sources incorrect" end - def test_that_syck_compiles - assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:syck]) - silence_command_line do - system('rake test:samples:syck') + def test_additional_code + generator = Mkrf::Generator.new('testlib') do |g| + g.additional_code = spec_code end - assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:syck]) + assert_match spec_code, generator.rakefile_contents end - def test_that_libxml_compiles - assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libxml]) - silence_command_line do - system('rake test:samples:libxml') + def test_logging_levels + generator = Mkrf::Generator.new('testlib') do |g| + g.logger.level = Logger::WARN + g.include_header 'stdio.h' + g.include_header 'fake_header.h' end - assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libxml]) + + logs = File.open('mkrf.log').read + assert_no_match(/INFO/, logs) + assert_match(/WARN/, logs) end - private - - def silence_command_line - yield and return if @@debug - silence_stream(STDERR) do - silence_stream(STDOUT) do - yield - end + def test_logging_defaults_to_info_level + generator = Mkrf::Generator.new('testlib') do |g| + g.include_header 'stdio.h' + g.include_header 'fake_header.h' end + + logs = File.open('mkrf.log').read + assert_match(/INFO/, logs) + assert_match(/WARN/, logs) end - # silence_stream taken from Rails ActiveSupport reporting.rb + protected - # Silences any stream for the duration of the block. - # - # silence_stream(STDOUT) do - # puts 'This will never be seen' - # end - # - # puts 'But this will' - def silence_stream(stream) - old_stream = stream.dup - stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') - stream.sync = true - yield - ensure - stream.reopen(old_stream) + def spec_code + <<-SPEC + # Create compressed packages + spec = Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = PKG_NAME + s.summary = "Generate Rakefiles to Build C Extensions to Ruby" + s.description = %q{This proposed replacement to mkmf generates Rakefiles to build C Extensions.} + s.version = PKG_VERSION + + s.author = "Kevin Clark" + s.email = "kevin.clark@gmail.com" + s.rubyforge_project = RUBY_FORGE_PROJECT + s.homepage = "http://glu.ttono.us" + + s.has_rdoc = true + s.requirements << 'rake' + s.require_path = 'lib' + s.autorequire = 'mkrf' + + s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ] + s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) } + s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) } + end + + Rake::GemPackageTask.new(spec) do |p| + p.gem_spec = spec + p.need_tar = true + p.need_zip = true + end + SPEC end - end \ No newline at end of file