* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / test_rbconfig.rb
blobfcbbbd8500e6b0a2be8e796a213ea8534071f8a4
1 # frozen_string_literal: false
2 require 'test/unit'
3 require 'rbconfig'
4 require 'shellwords'
6 class TestRbConfig < Test::Unit::TestCase
7   @@with_config = {}
9   Shellwords::shellwords(RbConfig::CONFIG["configure_args"]).grep(/\A--with-([^=]*)=(.*)/) do
10     @@with_config[$1.tr('_', '-')] = $2
11   end
13   def test_sitedirs
14     RbConfig::MAKEFILE_CONFIG.each do |key, val|
15       next unless /\Asite(?!arch)/ =~ key
16       next if @@with_config[key]
17       assert_match(/(?:\$\(|\/)site/, val, key)
18     end
19   end
21   def test_vendordirs
22     RbConfig::MAKEFILE_CONFIG.each do |key, val|
23       next unless /\Avendor(?!arch)/ =~ key
24       next if @@with_config[key]
25       assert_match(/(?:\$\(|\/)vendor/, val, key)
26     end
27   end
29   def test_archdirs
30     RbConfig::MAKEFILE_CONFIG.each do |key, val|
31       next unless /\A(?!site|vendor|archdir\z).*arch.*dir\z/ =~ key
32       next if @@with_config[key]
33       assert_match(/\$\(arch|\$\(rubyarchprefix\)/, val, key)
34     end
35   end
37   def test_sitearchdirs
38     bug7823 = '[ruby-dev:46964] [Bug #7823]'
39     RbConfig::MAKEFILE_CONFIG.each do |key, val|
40       next unless /\Asite.*arch.*dir\z/ =~ key
41       next if @@with_config[key]
42       assert_match(/\$\(sitearch|\$\(rubysitearchprefix\)/, val, "#{key} #{bug7823}")
43     end
44   end
46   def test_vendorarchdirs
47     bug7823 = '[ruby-dev:46964] [Bug #7823]'
48     RbConfig::MAKEFILE_CONFIG.each do |key, val|
49       next unless /\Avendor.*arch.*dir\z/ =~ key
50       next if @@with_config[key]
51       assert_match(/\$\(sitearch|\$\(rubysitearchprefix\)/, val, "#{key} #{bug7823}")
52     end
53   end
55   if /darwin/ =~ RUBY_PLATFORM
56     def test_sdkroot
57       assert_separately([{"SDKROOT" => "$(prefix)/SDKRoot"}], "#{<<~"begin;"}\n#{<<~'end;'}")
58       begin;
59         assert_equal RbConfig::CONFIG["prefix"]+"/SDKRoot", RbConfig::CONFIG["SDKROOT"]
60       end;
61     end
62   end
63 end