From 72acd2eb62aba51be6a77a7a10927129bf44a62e Mon Sep 17 00:00:00 2001 From: nick evans Date: Sat, 26 Apr 2025 21:40:13 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Update=20Regexp.linear=5Ftime=3F=20?= =?UTF-8?q?tests=20for=20non-CRuby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We'll attempt to load these tests for all ruby engines, but we'll catch failures and mark them as pending. On @eregon's suggestion, this also prints out regexp.inspect when it fails. --- test/net/imap/regexp_collector.rb | 2 ++ test/net/imap/test_regexps.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/test/net/imap/regexp_collector.rb b/test/net/imap/regexp_collector.rb index ff3b00540..9f5f584d0 100644 --- a/test/net/imap/regexp_collector.rb +++ b/test/net/imap/regexp_collector.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class RegexpCollector + Data = Net::IMAP::Data + ConstantRegexp = Data.define(:mod, :const_name, :regexp) do def name = "%s::%s" % [mod, const_name] end diff --git a/test/net/imap/test_regexps.rb b/test/net/imap/test_regexps.rb index 3432f62e3..3852b639a 100644 --- a/test/net/imap/test_regexps.rb +++ b/test/net/imap/test_regexps.rb @@ -3,8 +3,6 @@ require "net/imap" require "test/unit" -return unless Regexp.respond_to?(:linear_time?) - begin require_relative "regexp_collector" rescue LoadError @@ -34,7 +32,13 @@ class IMAPRegexpsTest < Test::Unit::TestCase ) def test_linear_time(data) - assert Regexp.linear_time?(data.regexp) + regexp = data.regexp + assert Regexp.linear_time?(regexp), "%p might backtrack" % [regexp] + rescue NoMethodError + pend "Regexp.linear_time? not implemented by #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}" + rescue Test::Unit::AssertionFailedError + raise if RUBY_ENGINE == "ruby" + pend "%p might backtrack in %s %s" % [regexp, RUBY_ENGINE, RUBY_ENGINE_VERSION] end end