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

ruby-changes:71903

From: Hiroshi <ko1@a...>
Date: Fri, 20 May 2022 19:48:44 +0900 (JST)
Subject: [ruby-changes:71903] 4146fd284b (master): Rewrite with assert_ractor for multiple ractor environment

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

From 4146fd284b3c3995cf6638b239625c530c6da875 Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 20 May 2022 19:48:21 +0900
Subject: Rewrite with assert_ractor for multiple ractor environment

---
 test/did_you_mean/test_ractor_compatibility.rb | 157 ++++++++++++++-----------
 1 file changed, 86 insertions(+), 71 deletions(-)

diff --git a/test/did_you_mean/test_ractor_compatibility.rb b/test/did_you_mean/test_ractor_compatibility.rb
index 1a9e63997f..f66a1a9d62 100644
--- a/test/did_you_mean/test_ractor_compatibility.rb
+++ b/test/did_you_mean/test_ractor_compatibility.rb
@@ -3,100 +3,115 @@ require_relative './helper' https://github.com/ruby/ruby/blob/trunk/test/did_you_mean/test_ractor_compatibility.rb#L3
 return if not DidYouMean::TestHelper.ractor_compatible?
 
 class RactorCompatibilityTest < Test::Unit::TestCase
-  include DidYouMean::TestHelper
-
-  class ::Book; end
-  class FirstNameError < NameError; end
-
   def test_class_name_suggestion_works_in_ractor
-    error = Ractor.new {
-              begin
-                Boook
-              rescue NameError => e
-                e.corrections # It is important to call the #corrections method within Ractor.
-                e
-              end
-            }.take
+    assert_ractor(<<~CODE, require_relative: "helper")
+      class ::Book; end
+      include DidYouMean::TestHelper
+      error = Ractor.new {
+                begin
+                  Boook
+                rescue NameError => e
+                  e.corrections # It is important to call the #corrections method within Ractor.
+                  e
+                end
+              }.take
 
-    assert_correction "Book", error.corrections
+      assert_correction "Book", error.corrections
+    CODE
   end
 
   def test_key_name_suggestion_works_in_ractor
-    error = Ractor.new {
-              begin
-                hash = { "foo" => 1, bar: 2 }
+    assert_ractor(<<~CODE, require_relative: "helper")
+      include DidYouMean::TestHelper
+      error = Ractor.new {
+                begin
+                  hash = { "foo" => 1, bar: 2 }
 
-                hash.fetch(:bax)
-              rescue KeyError => e
-                e.corrections # It is important to call the #corrections method within Ractor.
-                e
-              end
-            }.take
+                  hash.fetch(:bax)
+                rescue KeyError => e
+                  e.corrections # It is important to call the #corrections method within Ractor.
+                  e
+                end
+              }.take
 
-    assert_correction ":bar", error.corrections
-    assert_match "Did you mean?  :bar", error.to_s
+      assert_correction ":bar", error.corrections
+      assert_match "Did you mean?  :bar", error.to_s
+    CODE
   end
 
   def test_method_name_suggestion_works_in_ractor
-    error = Ractor.new {
-              begin
-                self.to__s
-              rescue NoMethodError => e
-                e.corrections # It is important to call the #corrections method within Ractor.
-                e
-              end
-            }.take
-
-    assert_correction :to_s, error.corrections
-    assert_match "Did you mean?  to_s",  error.to_s
-  end
-
-  if defined?(::NoMatchingPatternKeyError)
-    def test_pattern_key_name_suggestion_works_in_ractor
+    assert_ractor(<<~CODE, require_relative: "helper")
+      include DidYouMean::TestHelper
       error = Ractor.new {
                 begin
-                  eval(<<~RUBY, binding, __FILE__, __LINE__)
-                          hash = {foo: 1, bar: 2, baz: 3}
-                          hash => {fooo:}
-                          fooo = 1 # suppress "unused variable: fooo" warning
-                  RUBY
-                rescue NoMatchingPatternKeyError => e
+                  self.to__s
+                rescue NoMethodError => e
                   e.corrections # It is important to call the #corrections method within Ractor.
                   e
                 end
               }.take
 
-      assert_correction ":foo", error.corrections
-      assert_match "Did you mean?  :foo", error.to_s
+      assert_correction :to_s, error.corrections
+      assert_match "Did you mean?  to_s",  error.to_s
+    CODE
+  end
+
+  if defined?(::NoMatchingPatternKeyError)
+    def test_pattern_key_name_suggestion_works_in_ractor
+      assert_ractor(<<~CODE, require_relative: "helper")
+        include DidYouMean::TestHelper
+        error = Ractor.new {
+                  begin
+                    eval(<<~RUBY, binding, __FILE__, __LINE__)
+                            hash = {foo: 1, bar: 2, baz: 3}
+                            hash => {fooo:}
+                            fooo = 1 # suppress "unused variable: fooo" warning
+                    RUBY
+                  rescue NoMatchingPatternKeyError => e
+                    e.corrections # It is important to call the #corrections method within Ractor.
+                    e
+                  end
+                }.take
+
+        assert_correction ":foo", error.corrections
+        assert_match "Did you mean?  :foo", error.to_s
+      CODE
     end
   end
 
   def test_can_raise_other_name_error_in_ractor
-    error = Ractor.new {
-      begin
-        raise FirstNameError, "Other name error"
-      rescue FirstNameError => e
-        e.corrections # It is important to call the #corrections method within Ractor.
-        e
-      end
-    }.take
-
-    assert_not_match(/Did you mean\?/, error.message)
+    assert_ractor(<<~CODE, require_relative: "helper")
+      class FirstNameError < NameError; end
+      include DidYouMean::TestHelper
+      error = Ractor.new {
+        begin
+          raise FirstNameError, "Other name error"
+        rescue FirstNameError => e
+          e.corrections # It is important to call the #corrections method within Ractor.
+          e
+        end
+      }.take
+
+      assert_not_match(/Did you mean\?/, error.message)
+    CODE
   end
 
   def test_variable_name_suggestion_works_in_ractor
-    error = Ractor.new {
-      in_ractor = in_ractor = 1
-
-      begin
-        in_reactor
-      rescue NameError => e
-        e.corrections # It is important to call the #corrections method within Ractor.
-        e
-      end
-    }.take
-
-    assert_correction :in_ractor, error.corrections
-    assert_match "Did you mean?  in_ractor", error.to_s
+    assert_ractor(<<~CODE, require_relative: "helper")
+      include DidYouMean::TestHelper
+      error = Ractor.new {
+        in_ractor = in_ractor = 1
+
+        begin
+          in_reactor
+        rescue NameError => e
+          e.corrections # It is important to call the #corrections method within Ractor.
+          e
+        end
+      }.take
+
+      assert_correction :in_ractor, error.corrections
+      assert_match "Did you mean?  in_ractor", error.to_s
+    CODE
   end
 end
-- 
cgit v1.2.1


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

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