diff options
Diffstat (limited to 'test/mkmf')
-rw-r--r-- | test/mkmf/base.rb | 233 | ||||
-rw-r--r-- | test/mkmf/test_config.rb | 62 | ||||
-rw-r--r-- | test/mkmf/test_configuration.rb | 39 | ||||
-rw-r--r-- | test/mkmf/test_constant.rb | 60 | ||||
-rw-r--r-- | test/mkmf/test_convertible.rb | 48 | ||||
-rw-r--r-- | test/mkmf/test_egrep_cpp.rb | 14 | ||||
-rw-r--r-- | test/mkmf/test_find_executable.rb | 82 | ||||
-rw-r--r-- | test/mkmf/test_flags.rb | 92 | ||||
-rw-r--r-- | test/mkmf/test_framework.rb | 70 | ||||
-rw-r--r-- | test/mkmf/test_have_func.rb | 18 | ||||
-rw-r--r-- | test/mkmf/test_have_library.rb | 84 | ||||
-rw-r--r-- | test/mkmf/test_have_macro.rb | 46 | ||||
-rw-r--r-- | test/mkmf/test_install.rb | 38 | ||||
-rw-r--r-- | test/mkmf/test_libs.rb | 156 | ||||
-rw-r--r-- | test/mkmf/test_mkmf.rb | 14 | ||||
-rw-r--r-- | test/mkmf/test_pkg_config.rb | 66 | ||||
-rw-r--r-- | test/mkmf/test_signedness.rb | 38 | ||||
-rw-r--r-- | test/mkmf/test_sizeof.rb | 74 |
18 files changed, 680 insertions, 554 deletions
diff --git a/test/mkmf/base.rb b/test/mkmf/base.rb index 4f67478a56..7df07c16a6 100644 --- a/test/mkmf/base.rb +++ b/test/mkmf/base.rb @@ -20,136 +20,137 @@ $INCFLAGS << " -I." $extout_prefix = "$(extout)$(target_prefix)/" class TestMkmf < Test::Unit::TestCase -end - -module TestMkmf::Base - MKMFLOG = proc {File.read("mkmf.log") rescue ""} + module Base + MKMFLOG = proc {File.read("mkmf.log") rescue ""} - class Capture - attr_accessor :origin - def initialize - @buffer = "" - @filter = nil - @out = true - @origin = nil - 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 - @origin.reopen(io) if @origin - when IO + class Capture + attr_accessor :origin + def initialize + @buffer = "" + @filter = nil @out = true - @origin.reopen(io) if @origin - else - @out = false + @origin = nil end - end - def filter(&block) - @filter = block - end - def write(*s) - if @out - @buffer.concat(*s) - elsif @origin - @origin.write(*s) + 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 + @origin.reopen(io) if @origin + when IO + @out = true + @origin.reopen(io) if @origin + else + @out = false + end + end + def filter(&block) + @filter = block + end + def write(*s) + if @out + @buffer.concat(*s) + elsif @origin + @origin.write(*s) + end end end - end - attr_reader :stdout + attr_reader :stdout - def mkmflog(msg) - proc {MKMFLOG[] << msg} - end + def mkmflog(msg) + proc {MKMFLOG[] << msg} + end - def setup - @rbconfig = rbconfig0 = RbConfig::CONFIG - @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG - rbconfig = { - "hdrdir" => $hdrdir, - "srcdir" => $srcdir, - "topdir" => $topdir, - } - mkconfig = { - "hdrdir" => "$(top_srcdir)/include", - "srcdir" => "$(top_srcdir)", - "topdir" => $topdir, - } - rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup} - mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup} - RbConfig.module_eval { - remove_const(:CONFIG) - const_set(:CONFIG, rbconfig) - remove_const(:MAKEFILE_CONFIG) - const_set(:MAKEFILE_CONFIG, mkconfig) - } - MakeMakefile.class_eval { - remove_const(:CONFIG) - const_set(:CONFIG, mkconfig) - } - @tmpdir = Dir.mktmpdir - @curdir = Dir.pwd - @mkmfobj = Object.new - @stdout = Capture.new - Dir.chdir(@tmpdir) - @quiet, Logging.quiet = Logging.quiet, true - init_mkmf - $INCFLAGS[0, 0] = "-I. " - end + def setup + @rbconfig = rbconfig0 = RbConfig::CONFIG + @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG + rbconfig = { + "hdrdir" => $hdrdir, + "srcdir" => $srcdir, + "topdir" => $topdir, + } + mkconfig = { + "hdrdir" => "$(top_srcdir)/include", + "srcdir" => "$(top_srcdir)", + "topdir" => $topdir, + } + rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup} + mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup} + RbConfig.module_eval { + remove_const(:CONFIG) + const_set(:CONFIG, rbconfig) + remove_const(:MAKEFILE_CONFIG) + const_set(:MAKEFILE_CONFIG, mkconfig) + } + MakeMakefile.class_eval { + remove_const(:CONFIG) + const_set(:CONFIG, mkconfig) + } + @tmpdir = Dir.mktmpdir + @curdir = Dir.pwd + @mkmfobj = Object.new + @stdout = Capture.new + Dir.chdir(@tmpdir) + @quiet, Logging.quiet = Logging.quiet, true + init_mkmf + $INCFLAGS[0, 0] = "-I. " + end - def teardown - rbconfig0 = @rbconfig - mkconfig0 = @mkconfig - RbConfig.module_eval { - remove_const(:CONFIG) - const_set(:CONFIG, rbconfig0) - remove_const(:MAKEFILE_CONFIG) - const_set(:MAKEFILE_CONFIG, mkconfig0) - } - MakeMakefile.class_eval { - remove_const(:CONFIG) - const_set(:CONFIG, mkconfig0) - } - Logging.quiet = @quiet - Logging.log_close - FileUtils.rm_f("mkmf.log") - Dir.chdir(@curdir) - FileUtils.rm_rf(@tmpdir) - end + def teardown + return if @omitted + rbconfig0 = @rbconfig + mkconfig0 = @mkconfig + RbConfig.module_eval { + remove_const(:CONFIG) + const_set(:CONFIG, rbconfig0) + remove_const(:MAKEFILE_CONFIG) + const_set(:MAKEFILE_CONFIG, mkconfig0) + } + MakeMakefile.class_eval { + remove_const(:CONFIG) + const_set(:CONFIG, mkconfig0) + } + Logging.quiet = @quiet + Logging.log_close + FileUtils.rm_f("mkmf.log") + Dir.chdir(@curdir) + FileUtils.rm_rf(@tmpdir) + end - def mkmf(*args, &block) - @stdout.clear - stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout - verbose, $VERBOSE = $VERBOSE, false - @mkmfobj.instance_eval(*args, &block) - ensure - $VERBOSE = verbose - $stdout, @stdout.origin = @stdout.origin, stdout - end + def mkmf(*args, &block) + @stdout.clear + stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout + verbose, $VERBOSE = $VERBOSE, false + @mkmfobj.instance_eval(*args, &block) + ensure + $VERBOSE = verbose + $stdout, @stdout.origin = @stdout.origin, stdout + end - def config_value(name) - create_tmpsrc("---config-value=#{name}") - xpopen(cpp_command('')) do |f| - f.grep(/^---config-value=(.*)/) {return $1} + def config_value(name) + create_tmpsrc("---config-value=#{name}") + xpopen(cpp_command('')) do |f| + f.grep(/^---config-value=(.*)/) {return $1} + end + nil end - nil end -end -class TestMkmf - include TestMkmf::Base + include Base - def assert_separately(args, src, *rest, **options) - super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options) + def assert_separately(args, extra_args, src, *rest, **options) + super(args + ["-r#{__FILE__}"] + %w[- --] + extra_args, + "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", + *rest, + **options) end end diff --git a/test/mkmf/test_config.rb b/test/mkmf/test_config.rb index 07ed641415..0d2cb3751c 100644 --- a/test/mkmf/test_config.rb +++ b/test/mkmf/test_config.rb @@ -1,17 +1,57 @@ # frozen_string_literal: false -$extmk = true +require_relative 'base' +require 'tempfile' -require 'test/unit' -require 'mkmf' +class TestMkmfConfig < TestMkmf + def test_dir_config + bug8074 = '[Bug #8074]' + lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"/test/foo") + assert_separately([], %w[--with-foo-dir=/test/foo], <<-"end;") + assert_equal(%w[/test/foo/include #{lib}], dir_config("foo"), #{bug8074.dump}) + end; + end + + def test_with_config_with_arg_and_value + assert_separately([], %w[--with-foo=bar], <<-'end;') + assert_equal("bar", with_config("foo")) + end; + end + + def test_with_config_with_arg_and_no_value + assert_separately([], %w[--with-foo], <<-'end;') + assert_equal(true, with_config("foo")) + end; + end + + def test_with_config_without_arg + assert_separately([], %w[--without-foo], <<-'end;') + assert_equal(false, with_config("foo")) + end; + end + + def test_with_target_rbconfig + Tempfile.create(%w"rbconfig .rb", ".") do |tmp| + tmp.puts <<~'end;' + module RbConfig + CONFIG = {} + MAKEFILE_CONFIG = {} -class TestMkmf < Test::Unit::TestCase - class TestConfig < Test::Unit::TestCase - def test_dir_config - bug8074 = '[Bug #8074]' - lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"") - assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{ - assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump}) - } + def self.fire_update!(key, value); end + def self.expand(val, config = CONFIG); val; end + end; + ::RbConfig::CONFIG.each do |k, v| + tmp.puts " CONFIG[#{k.dump}] = #{v.dump}" + end + ::RbConfig::MAKEFILE_CONFIG.each do |k, v| + tmp.puts " MAKEFILE_CONFIG[#{k.dump}] = #{v.dump}" + end + tmp.puts " CONFIG['testing-only'] = 'ok'" + tmp.puts "end" + tmp.close + assert_separately([], ["--target-rbconfig=#{tmp.path}"], <<-'end;') + assert_equal("ok", MakeMakefile::RbConfig::CONFIG["testing-only"]) + assert_not_equal(::RbConfig, MakeMakefile::RbConfig) + end; end end end diff --git a/test/mkmf/test_configuration.rb b/test/mkmf/test_configuration.rb new file mode 100644 index 0000000000..0261f78a01 --- /dev/null +++ b/test/mkmf/test_configuration.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: false +require_relative 'base' + +class TestMkmfConfiguration < TestMkmf + def test_verbose_with_rbconfig_verbose_disabled + makefile = mkmf do + self.class::CONFIG['MKMF_VERBOSE'] = "0" + init_mkmf(self.class::CONFIG) + configuration '.' + end + verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1] + + assert_equal "0", verbose + end + + def test_verbose_with_rbconfig_verbose_enabled + makefile = mkmf do + self.class::CONFIG['MKMF_VERBOSE'] = "1" + init_mkmf(self.class::CONFIG) + configuration '.' + end + verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1] + + assert_equal "1", verbose + end + + def test_verbose_with_arg + assert_separately([], %w[--with-verbose], <<-'end;') + makefile = mkmf do + self.class::CONFIG['MKMF_VERBOSE'] = "0" + init_mkmf(self.class::CONFIG) + configuration '.' + end + verbose = makefile.grep(/^V =/).first[/^V = (.)$/, 1] + + assert_equal "1", verbose + end; + end +end diff --git a/test/mkmf/test_constant.rb b/test/mkmf/test_constant.rb index f5a87a1caa..f22b82ff95 100644 --- a/test/mkmf/test_constant.rb +++ b/test/mkmf/test_constant.rb @@ -1,38 +1,44 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestTryConstant < TestMkmf - def test_simple - assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG) - assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG) - assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG) +class TestMkmfTryConstant < TestMkmf + def setup + if ENV.key?('APPVEYOR') + @omitted = true + omit 'This test fails too often on AppVeyor' end + super + end - def test_sizeof - assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG) - assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG) - assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG) - assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG) - end + def test_simple + assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG) + assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG) + assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG) + end - def test_long - sizeof_int = config_value("SIZEOF_INT").to_i - sizeof_long = config_value("SIZEOF_LONG").to_i - if sizeof_long > sizeof_int - type = 'long' - else - sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i - return if !sizeof_long_long or sizeof_long_long <= sizeof_int - type = 'LONG_LONG' - end + def test_sizeof + assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG) + assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG) + end - decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))" - assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG) + def test_long + sizeof_int = config_value("SIZEOF_INT").to_i + sizeof_long = config_value("SIZEOF_LONG").to_i + if sizeof_long > sizeof_int + type = 'long' + else + sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i + return if !sizeof_long_long or sizeof_long_long <= sizeof_int + type = 'LONG_LONG' end - def test_large_unsigned - assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG) - end + decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))" + assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG) + end + + def test_large_unsigned + assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG) end end diff --git a/test/mkmf/test_convertible.rb b/test/mkmf/test_convertible.rb index 1baf892842..d65db4265b 100644 --- a/test/mkmf/test_convertible.rb +++ b/test/mkmf/test_convertible.rb @@ -1,35 +1,33 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestConvertible < TestMkmf - def test_typeof_builtin - ["", ["signed ", ""], "unsigned "].each do |signed, prefix| - %w[short int long].each do |type| - assert_equal((prefix || signed)+type, - mkmf {convertible_int(signed+type)}, MKMFLOG) - end +class TestMkmfConvertible < TestMkmf + def test_typeof_builtin + ["", ["signed ", ""], "unsigned "].each do |signed, prefix| + %w[short int long].each do |type| + assert_equal((prefix || signed)+type, + mkmf {convertible_int(signed+type)}, MKMFLOG) end end + end - def test_typeof_typedef - ["", ["signed ", ""], "unsigned "].each do |signed, prefix| - %w[short int long].each do |type| - open("confdefs.h", "w") {|f| - f.puts "typedef #{signed}#{type} test1_t;" - } - $defs.clear - assert_equal((prefix || signed)+type, - mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG) - (u = signed[/^u/]) and u.upcase! - assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote) - assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX") - assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM") - assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}") - end + def test_typeof_typedef + ["", ["signed ", ""], "unsigned "].each do |signed, prefix| + %w[short int long].each do |type| + open("confdefs.h", "w") {|f| + f.puts "typedef #{signed}#{type} test1_t;" + } + $defs.clear + assert_equal((prefix || signed)+type, + mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG) + (u = signed[/^u/]) and u.upcase! + assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote) + assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX") + assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM") + assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}") end - ensure - File.unlink("confdefs.h") end + ensure + File.unlink("confdefs.h") end end diff --git a/test/mkmf/test_egrep_cpp.rb b/test/mkmf/test_egrep_cpp.rb index ce276bef20..7ac0e60010 100644 --- a/test/mkmf/test_egrep_cpp.rb +++ b/test/mkmf/test_egrep_cpp.rb @@ -2,14 +2,12 @@ require_relative 'base' require 'tempfile' -class TestMkmf - class TestEgrepCpp < TestMkmf - def test_egrep_cpp - assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG) - end +class TestMkmfEgrepCpp < TestMkmf + def test_egrep_cpp + assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG) + end - def test_not_have_func - assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG) - end + def test_not_have_func + assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG) end end diff --git a/test/mkmf/test_find_executable.rb b/test/mkmf/test_find_executable.rb index 7ffc28ecc8..88b70c21c0 100644 --- a/test/mkmf/test_find_executable.rb +++ b/test/mkmf/test_find_executable.rb @@ -1,58 +1,56 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestFindExecutable < TestMkmf - def setup - super - @path, ENV["PATH"] = ENV["PATH"], @tmpdir - end +class TestMkmfFindExecutable < TestMkmf + def setup + super + @path, ENV["PATH"] = ENV["PATH"], @tmpdir + end - def each_exts(&block) - name = "foobar#{$$}#{rand(1000)}" - stdout.filter {|s| s.sub(name, "<executable>")} - exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split - exts[0] ||= "" - exts.each do |ext| - yield name+ext, name - end + def each_exts(&block) + name = "foobar#{$$}#{rand(1000)}" + stdout.filter {|s| s.sub(name, "<executable>")} + exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split + exts[0] ||= "" + exts.each do |ext| + yield name+ext, name end + end - def teardown - ENV["PATH"] = @path - super - end + def teardown + ENV["PATH"] = @path + super + end - def test_find_executable - bug2669 = '[ruby-core:27912]' - each_exts do |full, name| - begin - open(full, "w") {|ff| ff.chmod(0755)} - result = mkmf {find_executable(name)} - ensure - File.unlink(full) - end - assert_equal("#{@tmpdir}/#{full}", result, bug2669) + def test_find_executable + bug2669 = '[ruby-core:27912]' + each_exts do |full, name| + begin + open(full, "w") {|ff| ff.chmod(0755)} + result = mkmf {find_executable(name)} + ensure + File.unlink(full) end + assert_equal("#{@tmpdir}/#{full}", result, bug2669) end + end - def test_find_executable_dir - each_exts do |full, name| - begin - Dir.mkdir(full) - result = mkmf {find_executable(name)} - ensure - Dir.rmdir(full) - end - assert_nil(result) + def test_find_executable_dir + each_exts do |full, name| + begin + Dir.mkdir(full) + result = mkmf {find_executable(name)} + ensure + Dir.rmdir(full) end + assert_nil(result) end + end - if /mingw|mswin/ =~ RUBY_PLATFORM - def test_quoted_path_on_windows - ENV["PATH"] = %["#{@tmpdir}"] - test_find_executable - end + if /mingw|mswin/ =~ RUBY_PLATFORM + def test_quoted_path_on_windows + ENV["PATH"] = %["#{@tmpdir}"] + test_find_executable end end end diff --git a/test/mkmf/test_flags.rb b/test/mkmf/test_flags.rb index a3596d8e55..6fde46adec 100644 --- a/test/mkmf/test_flags.rb +++ b/test/mkmf/test_flags.rb @@ -1,57 +1,55 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestFlags < TestMkmf - def test_valid_warnflags - val = $extmk - warnflags = $warnflags - makefile = mkmf do - $extmk = false - self.class::CONFIG['warnflags'] = %w"-Wextra - -Wno-unused-parameter -Wno-parentheses -Wno-long-long - -Wno-missing-field-initializers -Werror=pointer-arith - -Werror=write-strings -Werror=declaration-after-statement - -Werror=shorten-64-to-32 - -Werror-implicit-function-declaration - ".join(' ') - self.class::CONFIG['GCC'] = 'yes' - init_mkmf(self.class::CONFIG) - configuration '.' - end - generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split +class TestMkmfFlags < TestMkmf + def test_valid_warnflags + val = $extmk + warnflags = $warnflags + makefile = mkmf do + $extmk = false + self.class::CONFIG['warnflags'] = %w"-Wextra + -Wno-unused-parameter -Wno-parentheses -Wno-long-long + -Wno-missing-field-initializers -Werror=pointer-arith + -Werror=write-strings -Werror=declaration-after-statement + -Werror=shorten-64-to-32 + -Werror-implicit-function-declaration + ".join(' ') + self.class::CONFIG['GCC'] = 'yes' + init_mkmf(self.class::CONFIG) + configuration '.' + end + generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split - assert_equal %w" - -Wextra -Wno-unused-parameter -Wno-parentheses - -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith - -Wwrite-strings -Wdeclaration-after-statement - -Wshorten-64-to-32 -Wimplicit-function-declaration - ", generated_flags + assert_equal %w" + -Wextra -Wno-unused-parameter -Wno-parentheses + -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith + -Wwrite-strings -Wdeclaration-after-statement + -Wshorten-64-to-32 -Werror-implicit-function-declaration + ", generated_flags - ensure - $warnflags = warnflags - $extmk = val - end + ensure + $warnflags = warnflags + $extmk = val + end - def test_try_ldflag_invalid_opt - assert_separately([], <<-'end;') #do - assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG) - assert(have_devel?, TestMkmf::MKMFLOG) - end; - end + def test_try_ldflag_invalid_opt + assert_separately([], [], <<-'end;') #do + assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; + end - def test_try_cflag_invalid_opt - assert_separately([], <<-'end;', timeout: 30) #do - assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG) - assert(have_devel?, TestMkmf::MKMFLOG) - end; - end + def test_try_cflag_invalid_opt + assert_separately([], [], <<-'end;', timeout: 30) #do + assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; + end - def test_try_cppflag_invalid_opt - assert_separately([], <<-'end;') #do - assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG) - assert(have_devel?, TestMkmf::MKMFLOG) - end; - end + def test_try_cppflag_invalid_opt + assert_separately([], [], <<-'end;') #do + assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG) + assert(have_devel?, TestMkmf::MKMFLOG) + end; end end diff --git a/test/mkmf/test_framework.rb b/test/mkmf/test_framework.rb index ba15299ae0..3245e43c75 100644 --- a/test/mkmf/test_framework.rb +++ b/test/mkmf/test_framework.rb @@ -1,49 +1,47 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestHaveFramework < TestMkmf - def create_framework(fw, hdrname = "#{fw}.h") - Dir.mktmpdir("frameworks") do |dir| - fwdir = "#{dir}/#{fw}.framework" - hdrdir = "#{fwdir}/Headers" - FileUtils.mkdir_p(hdrdir) - File.write("#{hdrdir}/#{hdrname}", "") - src = "#{fwdir}/main.c" - File.write(src, "void #{fw}(void) {}\n") - cmd = LINK_SO.dup - RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src)) - cmd.gsub!("$@", "#{fwdir}/#{fw}") - cmd.gsub!(/ -bundle /, ' -dynamiclib ') - assert(xsystem(cmd), MKMFLOG) - $INCFLAGS << " " << "-F#{dir}".quote - yield fw, hdrname - end +class TestMkmfHaveFramework < TestMkmf + def create_framework(fw, hdrname = "#{fw}.h") + Dir.mktmpdir("frameworks") do |dir| + fwdir = "#{dir}/#{fw}.framework" + hdrdir = "#{fwdir}/Headers" + FileUtils.mkdir_p(hdrdir) + File.write("#{hdrdir}/#{hdrname}", "") + src = "#{fwdir}/main.c" + File.write(src, "void #{fw}(void) {}\n") + cmd = LINK_SO.dup + RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src)) + cmd.gsub!("$@", "#{fwdir}/#{fw}") + cmd.gsub!(/ -bundle /, ' -dynamiclib ') + assert(xsystem(cmd), MKMFLOG) + $INCFLAGS << " " << "-F#{dir}".quote + yield fw, hdrname end + end - def test_single_framework - assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C")) - end + def test_single_framework + assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C")) + end - def test_multi_frameworks - assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C")) - create_framework("MkmfTest") do |fw| - assert(have_framework(fw), MKMFLOG) - end + def test_multi_frameworks + assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C")) + create_framework("MkmfTest") do |fw| + assert(have_framework(fw), MKMFLOG) end + end - def test_empty_framework - create_framework("MkmfTest") do |fw| - assert(have_framework(fw), MKMFLOG) - end + def test_empty_framework + create_framework("MkmfTest") do |fw| + assert(have_framework(fw), MKMFLOG) end + end - def test_different_name_header - _bug8593 = '[ruby-core:55745] [Bug #8593]' - create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname| - assert(!have_framework(fw), MKMFLOG) - assert(have_framework([fw, hdrname]), MKMFLOG) - end + def test_different_name_header + _bug8593 = '[ruby-core:55745] [Bug #8593]' + create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname| + assert(!have_framework(fw), MKMFLOG) + assert(have_framework([fw, hdrname]), MKMFLOG) end end end if /darwin/ =~ RUBY_PLATFORM diff --git a/test/mkmf/test_have_func.rb b/test/mkmf/test_have_func.rb index 6204ab24f0..521a0bb435 100644 --- a/test/mkmf/test_have_func.rb +++ b/test/mkmf/test_have_func.rb @@ -2,16 +2,14 @@ require_relative 'base' require 'tempfile' -class TestMkmf - class TestHaveFunc < TestMkmf - def test_have_func - assert_equal(true, have_func("ruby_init"), MKMFLOG) - assert_include($defs, '-DHAVE_RUBY_INIT') - end +class TestMkmfHaveFunc < TestMkmf + def test_have_func + assert_equal(true, have_func("ruby_init"), MKMFLOG) + assert_include($defs, '-DHAVE_RUBY_INIT') + end - def test_not_have_func - assert_equal(false, have_func("no_ruby_init"), MKMFLOG) - assert_not_include($defs, '-DHAVE_RUBY_INIT') - end + def test_not_have_func + assert_equal(false, have_func("no_ruby_init"), MKMFLOG) + assert_not_include($defs, '-DHAVE_RUBY_INIT') end end diff --git a/test/mkmf/test_have_library.rb b/test/mkmf/test_have_library.rb index bb9ce6972d..e34a9b06da 100644 --- a/test/mkmf/test_have_library.rb +++ b/test/mkmf/test_have_library.rb @@ -2,55 +2,53 @@ require_relative 'base' require 'tempfile' -class TestMkmf - class TestHaveLibrary < TestMkmf - LIBRARY_NAME = 'mkmftest' - HEADER_NAME = "#{LIBRARY_NAME}.h" - FUNC_NAME = 'ruby_mkmftest_foo' - ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]} - - def create_library(libname = LIBRARY_NAME) - lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}" - open(HEADER_NAME, "w") do |hdr| - hdr.puts "void #{FUNC_NAME}(void);" - hdr.puts "void #{FUNC_NAME}_fake(void);" - end - create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}") - assert(xsystem(cc_command), "compile failed: #{cc_command}") - command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}" - assert(xsystem(command), "making library failed: #{command}") - File.unlink("#{CONFTEST}.#{$OBJEXT}") - config_string('RANLIB') do |ranlib| - command = "#{ranlib} #{lib}" - assert(xsystem(command), "ranlib failed: #{command}") - end +class TestMkmfHaveLibrary < TestMkmf + LIBRARY_NAME = 'mkmftest' + HEADER_NAME = "#{LIBRARY_NAME}.h" + FUNC_NAME = 'ruby_mkmftest_foo' + ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]} + + def create_library(libname = LIBRARY_NAME) + lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}" + open(HEADER_NAME, "w") do |hdr| + hdr.puts "void #{FUNC_NAME}(void);" + hdr.puts "void #{FUNC_NAME}_fake(void);" end - - def assert_have_library(*args) - assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG) + create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}") + assert(xsystem(cc_command), "compile failed: #{cc_command}") + command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}" + assert(xsystem(command), "making library failed: #{command}") + File.unlink("#{CONFTEST}.#{$OBJEXT}") + config_string('RANLIB') do |ranlib| + command = "#{ranlib} #{lib}" + assert(xsystem(command), "ranlib failed: #{command}") end + end - def assert_not_have_library(*args) - assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG) - end + def assert_have_library(*args) + assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG) + end - def test_have_library - create_library - assert_have_library - end + def assert_not_have_library(*args) + assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG) + end - def test_have_library_with_name - create_library - assert_have_library(FUNC_NAME, HEADER_NAME) - end + def test_have_library + create_library + assert_have_library + end - def test_not_have_library - assert_not_have_library - end + def test_have_library_with_name + create_library + assert_have_library(FUNC_NAME, HEADER_NAME) + end - def test_not_have_library_with_name - create_library - assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME) - end + def test_not_have_library + assert_not_have_library + end + + def test_not_have_library_with_name + create_library + assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME) end end diff --git a/test/mkmf/test_have_macro.rb b/test/mkmf/test_have_macro.rb index ebc5648097..3178bfea0b 100644 --- a/test/mkmf/test_have_macro.rb +++ b/test/mkmf/test_have_macro.rb @@ -2,35 +2,33 @@ require_relative 'base' require 'tempfile' -class TestMkmf - class TestHaveMacro < TestMkmf - MACRO_NAME = "RUBY_MKMFTEST_FOOBAR" +class TestMkmfHaveMacro < TestMkmf + MACRO_NAME = "RUBY_MKMFTEST_FOOBAR" - def test_have_macro_opt - assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG) - end + def test_have_macro_opt + assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG) + end - def test_have_macro_header - Tempfile.create(%w"test_mkmf .h", ".") do |tmp| - tmp.puts("#undef #{MACRO_NAME}") - tmp.puts("#define #{MACRO_NAME} 1") - tmp.close - base = File.basename(tmp.path) - assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) - end + def test_have_macro_header + Tempfile.create(%w"test_mkmf .h", ".") do |tmp| + tmp.puts("#undef #{MACRO_NAME}") + tmp.puts("#define #{MACRO_NAME} 1") + tmp.close + base = File.basename(tmp.path) + assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) end + end - def test_not_have_macro_opt - assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG) - end + def test_not_have_macro_opt + assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG) + end - def test_not_have_macro_header - Tempfile.create(%w"test_mkmf .h", ".") do |tmp| - tmp.puts("#undef #{MACRO_NAME}") - tmp.close - base = File.basename(tmp.path) - assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) - end + def test_not_have_macro_header + Tempfile.create(%w"test_mkmf .h", ".") do |tmp| + tmp.puts("#undef #{MACRO_NAME}") + tmp.close + base = File.basename(tmp.path) + assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG) end end end diff --git a/test/mkmf/test_install.rb b/test/mkmf/test_install.rb index 7f8c603d42..009d55f72d 100644 --- a/test/mkmf/test_install.rb +++ b/test/mkmf/test_install.rb @@ -1,27 +1,25 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestInstall < TestMkmf - def test_install_dirs - Dir.mktmpdir do |dir| - File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')") - all_assertions do |a| +class TestMkmfInstall < TestMkmf + def test_install_dirs + Dir.mktmpdir do |dir| + File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')") + all_assertions do |a| + a.foreach( + ["site"], + ["vendor", "--vendor"], + ) do |dest, *options| + assert_ruby_status(["-C", dir, "extconf.rb", *options]) + mf = File.read(dir+"/Makefile") a.foreach( - ["site"], - ["vendor", "--vendor"], - ) do |dest, *options| - assert_ruby_status(["-C", dir, "extconf.rb", *options]) - mf = File.read(dir+"/Makefile") - a.foreach( - ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"], - ["RUBYLIBDIR", "$(#{dest}libdir)$(target_prefix)"], - ["RUBYARCHDIR", "$(#{dest}archdir)$(target_prefix)"], - ["HDRDIR", "$(#{dest}hdrdir)$(target_prefix)"], - ["ARCHHDRDIR", "$(#{dest}archhdrdir)$(target_prefix)"], - ) do |(var, path)| - assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1] - end + ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"], + ["RUBYLIBDIR", "$(#{dest}libdir)$(target_prefix)"], + ["RUBYARCHDIR", "$(#{dest}archdir)$(target_prefix)"], + ["HDRDIR", "$(#{dest}hdrdir)$(target_prefix)"], + ["ARCHHDRDIR", "$(#{dest}archhdrdir)$(target_prefix)"], + ) do |(var, path)| + assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1] end end end diff --git a/test/mkmf/test_libs.rb b/test/mkmf/test_libs.rb index 9c5e1d29fb..2f84d024e2 100644 --- a/test/mkmf/test_libs.rb +++ b/test/mkmf/test_libs.rb @@ -1,94 +1,92 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestLibs < TestMkmf - def test_split_libs - assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar")) - end +class TestMkmfLibs < TestMkmf + def test_split_libs + assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar")) + end - def test_split_libs_macos - assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987') - end if /darwin/ =~ RUBY_PLATFORM + def test_split_libs_macos + assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987') + end if /darwin/ =~ RUBY_PLATFORM - def test_split_libs_windows - assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib")) - end if /mswin/ =~ RUBY_PLATFORM + def test_split_libs_windows + assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib")) + end if /mswin/ =~ RUBY_PLATFORM - def assert_in_order(array, x, y, mesg = nil) - mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}" - assert_operator(array.index(x), :<, array.rindex(y), mesg) - end + def assert_in_order(array, x, y, mesg = nil) + mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}" + assert_operator(array.index(x), :<, array.rindex(y), mesg) + end - def test_merge_simple - bug = '[ruby-dev:21765]' - assert_equal([], merge_libs(%w[])) - assert_equal(%w[a b], merge_libs(%w[a], %w[b])) - array = merge_libs(%w[a c], %w[b]) - assert_in_order(array, "a", "c", bug) - end + def test_merge_simple + bug = '[ruby-dev:21765]' + assert_equal([], merge_libs(%w[])) + assert_equal(%w[a b], merge_libs(%w[a], %w[b])) + array = merge_libs(%w[a c], %w[b]) + assert_in_order(array, "a", "c", bug) + end - def test_merge_seq - bug = '[ruby-dev:21765]' - array = merge_libs(%w[a c d], %w[c b e]) - assert_in_order(array, "a", "c", bug) - assert_in_order(array, "c", "d", bug) - assert_in_order(array, "c", "b", bug) - assert_in_order(array, "b", "e", bug) - end + def test_merge_seq + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[c b e]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "c", "b", bug) + assert_in_order(array, "b", "e", bug) + end - def test_merge_seq_pre - bug = '[ruby-dev:21765]' - array = merge_libs(%w[a c d], %w[b c d e]) - assert_in_order(array, "a", "c", bug) - assert_in_order(array, "c", "d", bug) - assert_in_order(array, "b", "c", bug) - assert_in_order(array, "d", "e", bug) - end + def test_merge_seq_pre + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[b c d e]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "d", "e", bug) + end - def test_merge_cyclic - bug = '[ruby-dev:21765]' - array = merge_libs(%w[a c d], %w[b c b]) - assert_in_order(array, "a", "c", bug) - assert_in_order(array, "c", "d", bug) - assert_in_order(array, "b", "c", bug) - assert_in_order(array, "c", "b", bug) - end + def test_merge_cyclic + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c d], %w[b c b]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "c", "b", bug) + end - def test_merge_cyclic_2 - bug = '[ruby-dev:21765]' - array = merge_libs(%w[a c a d], %w[b c b]) - assert_in_order(array, "a", "c", bug) - assert_in_order(array, "c", "a", bug) - assert_in_order(array, "c", "d", bug) - assert_in_order(array, "a", "d", bug) - assert_in_order(array, "b", "c", bug) - assert_in_order(array, "c", "b", bug) - end + def test_merge_cyclic_2 + bug = '[ruby-dev:21765]' + array = merge_libs(%w[a c a d], %w[b c b]) + assert_in_order(array, "a", "c", bug) + assert_in_order(array, "c", "a", bug) + assert_in_order(array, "c", "d", bug) + assert_in_order(array, "a", "d", bug) + assert_in_order(array, "b", "c", bug) + assert_in_order(array, "c", "b", bug) + end - def test_merge_reversal - bug = '[ruby-dev:22440]' - array = merge_libs(%w[a b c], %w[c d a]) - assert_in_order(array, "a", "b" , bug) - assert_in_order(array, "c", "d" , bug) - ## assume that a and c have no dependency - end + def test_merge_reversal + bug = '[ruby-dev:22440]' + array = merge_libs(%w[a b c], %w[c d a]) + assert_in_order(array, "a", "b" , bug) + assert_in_order(array, "c", "d" , bug) + ## assume that a and c have no dependency + end - def test_merge_reversal_followed - bug7467 = '[ruby-core:50314] [Bug #7467]' - array = nil - assert_nothing_raised(bug7467) { - array = merge_libs(%w[a b c d e f g h], %w[d c d e], []) - } - assert_in_order(array, "a", "b", bug7467) - assert_in_order(array, "b", "c", bug7467) - assert_in_order(array, "c", "d", bug7467) - assert_in_order(array, "d", "e", bug7467) - assert_in_order(array, "e", "f", bug7467) - assert_in_order(array, "f", "g", bug7467) - assert_in_order(array, "g", "h", bug7467) - assert_in_order(array, "d", "c", bug7467) - assert_in_order(array, "c", "e", bug7467) - end + def test_merge_reversal_followed + bug7467 = '[ruby-core:50314] [Bug #7467]' + array = nil + assert_nothing_raised(bug7467) { + array = merge_libs(%w[a b c d e f g h], %w[d c d e], []) + } + assert_in_order(array, "a", "b", bug7467) + assert_in_order(array, "b", "c", bug7467) + assert_in_order(array, "c", "d", bug7467) + assert_in_order(array, "d", "e", bug7467) + assert_in_order(array, "e", "f", bug7467) + assert_in_order(array, "f", "g", bug7467) + assert_in_order(array, "g", "h", bug7467) + assert_in_order(array, "d", "c", bug7467) + assert_in_order(array, "c", "e", bug7467) end end if RUBY_ENGINE == "ruby" diff --git a/test/mkmf/test_mkmf.rb b/test/mkmf/test_mkmf.rb index adb86eca8d..55f9aa3b88 100644 --- a/test/mkmf/test_mkmf.rb +++ b/test/mkmf/test_mkmf.rb @@ -2,14 +2,12 @@ require 'test/unit' require 'mkmf' -class TestMkmf < Test::Unit::TestCase - class TestGlobal < TestMkmf - main = TOPLEVEL_BINDING.receiver - MakeMakefile.public_instance_methods(false).each do |m| - define_method(:"test_global_#{m}") do - assert_respond_to(main, [m, true]) - assert_not_respond_to(main, [m, false]) - end +class TestMkmfGlobal < Test::Unit::TestCase + main = TOPLEVEL_BINDING.receiver + MakeMakefile.public_instance_methods(false).each do |m| + define_method(:"test_global_#{m}") do + assert_respond_to(main, [m, true]) + assert_not_respond_to(main, [m, false]) end end end diff --git a/test/mkmf/test_pkg_config.rb b/test/mkmf/test_pkg_config.rb new file mode 100644 index 0000000000..f6a960c7d9 --- /dev/null +++ b/test/mkmf/test_pkg_config.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: false +require_relative 'base' +require 'shellwords' + +class TestMkmfPkgConfig < TestMkmf + PKG_CONFIG = config_string("PKG_CONFIG") {|path| find_executable0(path)} + + def setup + super + + if PKG_CONFIG + @fixtures_dir = File.join(Dir.pwd, "fixtures") + @fixtures_lib_dir = File.join(@fixtures_dir, "lib") + @fixtures_inc_dir = File.join(@fixtures_dir, "include") + + FileUtils.mkdir(@fixtures_dir) + File.write("fixtures/test1.pc", <<~EOF) + libdir=#{@fixtures_lib_dir} + includedir=#{@fixtures_inc_dir} + + Name: test1 + Description: Test for mkmf pkg-config method + Version: 1.2.3 + Libs: -L${libdir} -ltest1-public + Libs.private: -ltest1-private + Cflags: -I${includedir}/cflags-I --cflags-other + EOF + + @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], @fixtures_dir + end + end + + def teardown + if PKG_CONFIG + ENV["PKG_CONFIG_PATH"] = @pkg_config_path + end + + super + end + + def test_pkgconfig_with_option_returns_nil_on_error + pend("skipping because pkg-config is not installed") unless PKG_CONFIG + assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG) + end + + def test_pkgconfig_with_libs_option_returns_output + pend("skipping because pkg-config is not installed") unless PKG_CONFIG + expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort + actual = pkg_config("test1", "libs").shellsplit.sort + assert_equal(expected, actual, MKMFLOG) + end + + def test_pkgconfig_with_cflags_option_returns_output + pend("skipping because pkg-config is not installed") unless PKG_CONFIG + expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort + actual = pkg_config("test1", "cflags").shellsplit.sort + assert_equal(expected, actual, MKMFLOG) + end + + def test_pkgconfig_with_multiple_options + pend("skipping because pkg-config is not installed") unless PKG_CONFIG + expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort + actual = pkg_config("test1", "libs", "static").shellsplit.sort + assert_equal(expected, actual, MKMFLOG) + end +end diff --git a/test/mkmf/test_signedness.rb b/test/mkmf/test_signedness.rb index 589dcb56e8..a59e3548a2 100644 --- a/test/mkmf/test_signedness.rb +++ b/test/mkmf/test_signedness.rb @@ -1,30 +1,28 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestSignedness < TestMkmf - def test_typeof_builtin - bug4144 = '[ruby-dev:42731]' - [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| - %w[short int long].each do |type| - assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144)) - end +class TestMkmfSignedness < TestMkmf + def test_typeof_builtin + bug4144 = '[ruby-dev:42731]' + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144)) end end + end - def test_typeof_typedef - [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| - %w[short int long].each do |type| - open("confdefs.h", "w") {|f| - f.puts "typedef #{signed}#{type} test1_t;" - } - $defs.clear - assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG) - assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}") - end + def test_typeof_typedef + [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect| + %w[short int long].each do |type| + open("confdefs.h", "w") {|f| + f.puts "typedef #{signed}#{type} test1_t;" + } + $defs.clear + assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG) + assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}") end - ensure - File.unlink("confdefs.h") end + ensure + File.unlink("confdefs.h") end end diff --git a/test/mkmf/test_sizeof.rb b/test/mkmf/test_sizeof.rb index 742c3d6454..6fb0a6a8f6 100644 --- a/test/mkmf/test_sizeof.rb +++ b/test/mkmf/test_sizeof.rb @@ -1,48 +1,46 @@ # frozen_string_literal: false require_relative 'base' -class TestMkmf - class TestSizeof < TestMkmf - def setup - super - @sizeof_short = config_value("SIZEOF_SHORT").to_i - @sizeof_int = config_value("SIZEOF_INT").to_i - @sizeof_long = config_value("SIZEOF_LONG").to_i - @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i - @sizeof___int64 = config_value("SIZEOF___INT64").to_i - end +class TestMkmfSizeof < TestMkmf + def setup + super + @sizeof_short = config_value("SIZEOF_SHORT").to_i + @sizeof_int = config_value("SIZEOF_INT").to_i + @sizeof_long = config_value("SIZEOF_LONG").to_i + @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i + @sizeof___int64 = config_value("SIZEOF___INT64").to_i + end - def test_sizeof_builtin - %w[char short int long float double void*].each do |type| - assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG) - end - assert_operator(@sizeof_short, :<=, @sizeof_int) - assert_operator(@sizeof_int, :<=, @sizeof_long) - assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero? - assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero? + def test_sizeof_builtin + %w[char short int long float double void*].each do |type| + assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG) end + assert_operator(@sizeof_short, :<=, @sizeof_int) + assert_operator(@sizeof_int, :<=, @sizeof_long) + assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero? + assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero? + end - def test_sizeof_struct - open("confdefs.h", "w") {|f| - f.puts "typedef struct {char x;} test1_t;" - } - assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + def test_sizeof_struct + open("confdefs.h", "w") {|f| + f.puts "typedef struct {char x;} test1_t;" + } + assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) - open("confdefs.h", "w") {|f| - f.puts "typedef struct {char x, y;} test1_t;" - } - assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + open("confdefs.h", "w") {|f| + f.puts "typedef struct {char x, y;} test1_t;" + } + assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) - open("confdefs.h", "w") {|f| - f.puts "typedef struct {int x;} test1_t;" - } - assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) - open("confdefs.h", "w") {|f| - f.puts "typedef struct {int x, y;} test1_t;" - } - assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) - ensure - File.unlink("confdefs.h") - end + open("confdefs.h", "w") {|f| + f.puts "typedef struct {int x;} test1_t;" + } + assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + open("confdefs.h", "w") {|f| + f.puts "typedef struct {int x, y;} test1_t;" + } + assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG) + ensure + File.unlink("confdefs.h") end end |