summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2024-09-10 15:37:32 +0900
committerNobuyoshi Nakada <[email protected]>2024-09-10 16:50:21 +0900
commit2d12fbc4db7d1501d8f2a6b464af165ec40f7f3c (patch)
tree68ed0a2e3cafb9e15d91379e04b348c794585444
parenta3ba723ef09f0a42bb7ad31167a5457756e53f8d (diff)
Add predicates for platforms
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11583
-rw-r--r--test/ruby/test_process.rb2
-rw-r--r--test/ruby/test_rubyoptions.rb4
-rw-r--r--test/ruby/test_vm_dump.rb2
-rw-r--r--tool/lib/core_assertions.rb59
-rw-r--r--tool/lib/test/unit.rb1
5 files changed, 64 insertions, 4 deletions
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 4257110950..90cb3ef027 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1874,7 +1874,7 @@ class TestProcess < Test::Unit::TestCase
end
def test_daemon_noclose
- pend "macOS 15 beta is not working with this test" if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`
+ pend "macOS 15 beta is not working with this test" if macos?(15)
data = IO.popen("-", "r+") do |f|
break f.read if f
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 4d1a096298..f82861b8ce 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -876,7 +876,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
def assert_segv(args, message=nil, list: SEGVTest::ExpectedStderrList, **opt, &block)
- pend "macOS 15 beta is not working with this assertion" if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`
+ pend "macOS 15 beta is not working with this assertion" if macos?(15)
# We want YJIT to be enabled in the subprocess if it's enabled for us
# so that the Ruby description matches.
@@ -921,7 +921,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
def assert_crash_report(path, cmd = nil, &block)
- pend "macOS 15 beta is not working with this assertion" if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`
+ pend "macOS 15 beta is not working with this assertion" if macos?(15)
Dir.mktmpdir("ruby_crash_report") do |dir|
list = SEGVTest::ExpectedStderrList
diff --git a/test/ruby/test_vm_dump.rb b/test/ruby/test_vm_dump.rb
index 86d89adb96..22afee7a24 100644
--- a/test/ruby/test_vm_dump.rb
+++ b/test/ruby/test_vm_dump.rb
@@ -5,7 +5,7 @@ return unless /darwin/ =~ RUBY_PLATFORM
class TestVMDump < Test::Unit::TestCase
def assert_darwin_vm_dump_works(args, timeout=nil)
- pend "macOS 15 beta is not working with this assertion" if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`
+ pend "macOS 15 beta is not working with this assertion" if macos?(15)
assert_in_out_err(args, "", [], /^\[IMPORTANT\]/, timeout: timeout || 300)
end
diff --git a/tool/lib/core_assertions.rb b/tool/lib/core_assertions.rb
index 361b1a697d..55ef93bed0 100644
--- a/tool/lib/core_assertions.rb
+++ b/tool/lib/core_assertions.rb
@@ -861,6 +861,65 @@ eom
token = "\e[7;1m#{$$.to_s}:#{Time.now.strftime('%s.%L')}:#{rand(0x10000).to_s(16)}:\e[m"
return token.dump, Regexp.quote(token)
end
+
+ # Platform predicates
+
+ def self.mswin?
+ defined?(@mswin) ? @mswin : @mswin = RUBY_PLATFORM.include?('mswin')
+ end
+ private def mswin?
+ CoreAssertions.mswin?
+ end
+
+ def self.mingw?
+ defined?(@mingw) ? @mingw : @mingw = RUBY_PLATFORM.include?('mingw')
+ end
+ private def mingw?
+ CoreAssertions.mingw?
+ end
+
+ module_function def windows?
+ mswin? or mingw?
+ end
+
+ def self.compare_version(a, b)
+ b.empty? ? true && a : a && (a <=> b) >= 0
+ end
+
+ def self.linux?(*ver)
+ unless defined?(@linux)
+ @linux = RUBY_PLATFORM.include?('linux') && `uname -r`.scan(/\d+/).map(&:to_i)
+ end
+ compare_version @linux, ver
+ end
+ private def linux?(*ver)
+ CoreAssertions.linux?(*ver)
+ end
+
+ def self.glibc?(*ver)
+ unless defined?(@glibc)
+ libc = `/usr/bin/ldd /bin/sh`[/^\s*libc.*=> *\K\S*/]
+ if libc and /version (\d+)\.(\d+)\.$/ =~ IO.popen([libc], &:read)[]
+ @glibc = [$1.to_i, $2.to_i]
+ else
+ @glibc = false
+ end
+ end
+ compare_version @glibc, ver
+ end
+ private def glibc?(*ver)
+ CoreAssertions.glibc?(*ver)
+ end
+
+ def self.macos?(*ver)
+ unless defined?(@macos)
+ @macos = RUBY_PLATFORM.include?('darwin') && `sw_vers -productVersion`.scan(/\d+/).map(&:to_i)
+ end
+ compare_version @macos, ver
+ end
+ private def macos?(*ver)
+ CoreAssertions.macos?(*ver)
+ end
end
end
end
diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb
index 30f30df62e..bbb9a26759 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -1893,6 +1893,7 @@ module Test
@backtrace = ex.backtrace
end
+
attr_accessor :message, :backtrace
end
end