diff options
Diffstat (limited to 'test/mkmf')
-rw-r--r-- | test/mkmf/base.rb | 8 | ||||
-rw-r--r-- | test/mkmf/test_config.rb | 60 | ||||
-rw-r--r-- | test/mkmf/test_configuration.rb | 39 | ||||
-rw-r--r-- | test/mkmf/test_constant.rb | 8 | ||||
-rw-r--r-- | test/mkmf/test_flags.rb | 6 | ||||
-rw-r--r-- | test/mkmf/test_pkg_config.rb | 4 |
6 files changed, 109 insertions, 16 deletions
diff --git a/test/mkmf/base.rb b/test/mkmf/base.rb index e097c396d6..7df07c16a6 100644 --- a/test/mkmf/base.rb +++ b/test/mkmf/base.rb @@ -106,6 +106,7 @@ class TestMkmf < Test::Unit::TestCase end def teardown + return if @omitted rbconfig0 = @rbconfig mkconfig0 = @mkconfig RbConfig.module_eval { @@ -146,7 +147,10 @@ class TestMkmf < Test::Unit::TestCase 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 3878db1964..0d2cb3751c 100644 --- a/test/mkmf/test_config.rb +++ b/test/mkmf/test_config.rb @@ -1,15 +1,57 @@ # frozen_string_literal: false -$extmk = true +require_relative 'base' +require 'tempfile' -require 'test/unit' -require 'mkmf' - -class TestMkmfConfig < Test::Unit::TestCase +class TestMkmfConfig < TestMkmf 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}) - } + 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 = {} + + 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 f6834c7f28..f22b82ff95 100644 --- a/test/mkmf/test_constant.rb +++ b/test/mkmf/test_constant.rb @@ -2,6 +2,14 @@ require_relative 'base' class TestMkmfTryConstant < TestMkmf + def setup + if ENV.key?('APPVEYOR') + @omitted = true + omit 'This test fails too often on AppVeyor' + end + super + end + def test_simple assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG) assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG) diff --git a/test/mkmf/test_flags.rb b/test/mkmf/test_flags.rb index aedf06b610..6fde46adec 100644 --- a/test/mkmf/test_flags.rb +++ b/test/mkmf/test_flags.rb @@ -33,21 +33,21 @@ class TestMkmfFlags < TestMkmf end def test_try_ldflag_invalid_opt - assert_separately([], <<-'end;') #do + 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_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_separately([], [], <<-'end;') #do assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG) assert(have_devel?, TestMkmf::MKMFLOG) end; diff --git a/test/mkmf/test_pkg_config.rb b/test/mkmf/test_pkg_config.rb index 72efb4ba81..f6a960c7d9 100644 --- a/test/mkmf/test_pkg_config.rb +++ b/test/mkmf/test_pkg_config.rb @@ -3,7 +3,7 @@ require_relative 'base' require 'shellwords' class TestMkmfPkgConfig < TestMkmf - PKG_CONFIG = find_executable0("pkg-config") + PKG_CONFIG = config_string("PKG_CONFIG") {|path| find_executable0(path)} def setup super @@ -26,7 +26,7 @@ class TestMkmfPkgConfig < TestMkmf Cflags: -I${includedir}/cflags-I --cflags-other EOF - @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures") + @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], @fixtures_dir end end |