summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-09-10 15:37:32 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-12-15 17:38:38 +0900
commit3563a0db80566b7c22ca77e620a9e89bb928dba2 (patch)
tree54169a36aaad2e1e43c412bcc6f4f658dfaeda34
parentc98aa9771ed09ba209aba17b341a893f6c1594d4 (diff)
Add predicates for platforms
-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 2df9b44036..4493b2c525 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1884,7 +1884,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 f2a30edd7a..29a7ed56ce 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -852,7 +852,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
def assert_segv(args, message=nil, list: SEGVTest::ExpectedStderrList, **opt)
- 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.
@@ -893,7 +893,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
def assert_crash_report(path, cmd = 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)
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 6e6f7e2a1f..e0b98d7571 100644
--- a/test/ruby/test_vm_dump.rb
+++ b/test/ruby/test_vm_dump.rb
@@ -4,7 +4,7 @@ require 'test/unit'
class TestVMDump < Test::Unit::TestCase
def assert_darwin_vm_dump_works(args)
omit if RUBY_PLATFORM !~ /darwin/
- 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\]/)
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 1c2d5fd924..a140ea68e0 100644
--- a/tool/lib/test/unit.rb
+++ b/tool/lib/test/unit.rb
@@ -1782,6 +1782,7 @@ module Test
@backtrace = ex.backtrace
end
+
attr_accessor :message, :backtrace
end
end