diff options
author | Yusuke Endoh <[email protected]> | 2024-09-13 13:48:51 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2024-09-13 16:52:38 +0900 |
commit | 0f3dc2f958bd1447cc459bc4a4f39071a6a07a9c (patch) | |
tree | 18778bfcd6c52ff80ad05d6e2cf5bd7b5bb6ffd9 /test | |
parent | b6c7226facc140bf8976d48fbd6c06f729534379 (diff) |
Prevent warnings "the block passed to ... may be ignored"
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11611
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_call.rb | 19 | ||||
-rw-r--r-- | test/ruby/test_iterator.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_proc.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 4 |
4 files changed, 38 insertions, 4 deletions
diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index 14847bf629..b7d62ae111 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -3,7 +3,24 @@ require 'test/unit' require '-test-/iter' class TestCall < Test::Unit::TestCase - def aaa(a, b=100, *rest) + # These dummy method definitions prevent warnings "the block passed to 'a'..." + def a(&) = nil + def b(&) = nil + def c(&) = nil + def d(&) = nil + def e(&) = nil + def f(&) = nil + def g(&) = nil + def h(&) = nil + def i(&) = nil + def j(&) = nil + def k(&) = nil + def l(&) = nil + def m(&) = nil + def n(&) = nil + def o(&) = nil + + def aaa(a, b=100, *rest, &) res = [a, b] res += rest if rest return res diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 820d5591c1..1bb655d52e 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -175,10 +175,13 @@ class TestIterator < Test::Unit::TestCase end def test_block_given + verbose_bak, $VERBOSE = $VERBOSE, nil assert(m1{p 'test'}) assert(m2{p 'test'}) assert(!m1()) assert(!m2()) + ensure + $VERBOSE = verbose_bak end def m3(var, &block) @@ -308,7 +311,18 @@ class TestIterator < Test::Unit::TestCase def test_ljump assert_raise(LocalJumpError) {get_block{break}.call} - assert_raise(LocalJumpError) {proc_call2(get_block{break}){}} + begin + verbose_bak, $VERBOSE = $VERBOSE, nil + # See the commit https://github.com/ruby/ruby/commit/7d8a415bc2d08a1b5e9d1ea802493b6eeb99c219 + # This block is not used but this is intentional. + # | + # +-----------------------------------------------------+ + # | + # vv + assert_raise(LocalJumpError) {proc_call2(get_block{break}){}} + ensure + $VERBOSE = verbose_bak + end # cannot use assert_nothing_raised due to passing block. begin diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 2f91da8aa8..192955c60a 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -207,10 +207,13 @@ class TestProc < Test::Unit::TestCase end def test_block_given_method + verbose_bak, $VERBOSE = $VERBOSE, nil m = method(:m_block_given?) assert(!m.call, "without block") assert(m.call {}, "with block") assert(!m.call, "without block second") + ensure + $VERBOSE = verbose_bak end def test_block_given_method_to_proc diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index bd15d7c9f3..fe6fa30e02 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1387,7 +1387,7 @@ eom def test_block_after_cmdarg_in_paren bug11873 = '[ruby-core:72482] [Bug #11873]' - def bug11873.p(*);end; + def bug11873.p(*, &);end; assert_raise(LocalJumpError, bug11873) do bug11873.instance_eval do @@ -2256,7 +2256,7 @@ eom end end - def caller_lineno(*) + def caller_lineno(*, &) caller_locations(1, 1)[0].lineno end end |