[前][次][番号順一覧][スレッド一覧]

ruby-changes:74446

From: Yusuke <ko1@a...>
Date: Fri, 11 Nov 2022 09:07:20 +0900 (JST)
Subject: [ruby-changes:74446] adfbee85e0 (master): Allow a float error for Regexp.timeout

https://git.ruby-lang.org/ruby.git/commit/?id=adfbee85e0

From adfbee85e07494d42e54b1c616e5fa62a207fb8f Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 11 Nov 2022 09:05:51 +0900
Subject: 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1583
       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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1628
       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
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]