Skip to content

Commit 72acd2e

Browse files
committed
✅ Update Regexp.linear_time? tests for non-CRuby
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.
1 parent f117dbd commit 72acd2e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

test/net/imap/regexp_collector.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: true
22

33
class RegexpCollector
4+
Data = Net::IMAP::Data
5+
46
ConstantRegexp = Data.define(:mod, :const_name, :regexp) do
57
def name = "%s::%s" % [mod, const_name]
68
end

test/net/imap/test_regexps.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
require "net/imap"
44
require "test/unit"
55

6-
return unless Regexp.respond_to?(:linear_time?)
7-
86
begin
97
require_relative "regexp_collector"
108
rescue LoadError
@@ -34,7 +32,13 @@ class IMAPRegexpsTest < Test::Unit::TestCase
3432
)
3533

3634
def test_linear_time(data)
37-
assert Regexp.linear_time?(data.regexp)
35+
regexp = data.regexp
36+
assert Regexp.linear_time?(regexp), "%p might backtrack" % [regexp]
37+
rescue NoMethodError
38+
pend "Regexp.linear_time? not implemented by #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}"
39+
rescue Test::Unit::AssertionFailedError
40+
raise if RUBY_ENGINE == "ruby"
41+
pend "%p might backtrack in %s %s" % [regexp, RUBY_ENGINE, RUBY_ENGINE_VERSION]
3842
end
3943

4044
end

0 commit comments

Comments
 (0)