From adfbee85e07494d42e54b1c616e5fa62a207fb8f Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 11 Nov 2022 09:05:51 +0900 Subject: [PATCH] Allow a float error for Regexp.timeout The tests failed on windows https://github.com/ruby/ruby/actions/runs/3440997073/jobs/5740085169#step:18:62 ``` 1) Failure: TestRegexp#test_s_timeout [D:/a/ruby/ruby/src/test/ruby/test_regexp.rb:1586]: <0.30000000000000004> expected but was <0.3>. 2) Failure: TestRegexp#test_timeout_shorter_than_global [D:/a/ruby/ruby/src/test/ruby/test_regexp.rb:1631]: <0.30000000000000004> expected but was <0.3>. ``` --- test/ruby/test_regexp.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 87ce6987e3..3479a9f212 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1583,7 +1583,7 @@ class TestRegexp < Test::Unit::TestCase timeout = #{ EnvUtil.apply_timeout_scale(0.2).inspect } begin; Regexp.timeout = timeout - assert_equal(timeout, Regexp.timeout) + assert_in_delta(timeout, Regexp.timeout, timeout * 2 * Float::EPSILON) t = Time.now assert_raise_with_message(Regexp::TimeoutError, "regexp match timeout") do @@ -1628,7 +1628,11 @@ class TestRegexp < Test::Unit::TestCase Regexp.timeout = global_timeout re = Regexp.new("^(a*)\\1b?a*$", timeout: per_instance_timeout) - assert_equal(per_instance_timeout, re.timeout) + if per_instance_timeout + assert_in_delta(per_instance_timeout, re.timeout, per_instance_timeout * 2 * Float::EPSILON) + else + assert_nil(re.timeout) + end t = Time.now assert_raise_with_message(Regexp::TimeoutError, "regexp match timeout") do