summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_dir_m17n.rb36
-rw-r--r--test/ruby/test_econv.rb7
-rw-r--r--test/ruby/test_exception.rb8
-rw-r--r--test/ruby/test_io.rb12
-rw-r--r--test/ruby/test_io_m17n.rb3
-rw-r--r--test/ruby/test_literal.rb4
-rw-r--r--test/ruby/test_numeric.rb7
-rw-r--r--test/ruby/test_string.rb4
8 files changed, 49 insertions, 32 deletions
diff --git a/test/ruby/test_dir_m17n.rb b/test/ruby/test_dir_m17n.rb
index 7584074c7e..c2c0c4999e 100644
--- a/test/ruby/test_dir_m17n.rb
+++ b/test/ruby/test_dir_m17n.rb
@@ -18,7 +18,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = #{code}.chr('UTF-8').force_encoding("#{encoding}")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename)
EOS
@@ -26,7 +26,7 @@ class TestDir_M17N < Test::Unit::TestCase
assert_separately(%w[-EASCII-8BIT], <<-EOS, :chdir=>dir)
filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?"
expected_filename = expected_filename.force_encoding("ASCII-8BIT")
if /mswin|mingw/ =~ RUBY_PLATFORM
@@ -35,7 +35,7 @@ class TestDir_M17N < Test::Unit::TestCase
when ents.include?(expected_filename)
filename = expected_filename
else
- ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
+ ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
filename = expected_filename
end
end
@@ -52,7 +52,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\u3042"
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename)
EOS
}
@@ -67,7 +67,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
assert_include(ents, filename)
EOS
@@ -75,7 +75,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
assert_include(ents, filename)
EOS
@@ -88,7 +88,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xc2\xa1".force_encoding("utf-8")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename)
EOS
assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
@@ -125,13 +125,13 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\u3042"
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename)
EOS
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename)
EOS
assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
@@ -151,7 +151,7 @@ class TestDir_M17N < Test::Unit::TestCase
File.open(filename1, "w") {}
File.open(filename2, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename1)
assert_include(ents, filename2)
EOS
@@ -159,7 +159,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
assert_include(ents, filename1)
assert_include(ents, filename2)
EOS
@@ -183,7 +183,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
ents.each {|e| e.force_encoding("ASCII-8BIT") }
if /darwin/ =~ RUBY_PLATFORM
filename = filename.encode("utf-8")
@@ -200,7 +200,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
if /darwin/ =~ RUBY_PLATFORM
filename = filename.encode("utf-8").force_encoding("euc-jp")
end
@@ -210,14 +210,14 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
unless ents.include?(filename)
case RUBY_PLATFORM
when /darwin/
filename = filename.encode("utf-8", "euc-jp").b
when /mswin|mingw/
if ents.include?(win_expected_filename.b)
- ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
+ ents = Dir.entries(".", :encoding => Encoding.find("filesystem"))
filename = win_expected_filename
end
end
@@ -246,7 +246,7 @@ class TestDir_M17N < Test::Unit::TestCase
filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
if /darwin/ =~ RUBY_PLATFORM
filename = filename.encode("utf-8", "euc-jp").force_encoding("euc-jp")
end
@@ -255,7 +255,7 @@ class TestDir_M17N < Test::Unit::TestCase
assert_separately(%w[-EEUC-JP:UTF-8], <<-'EOS', :chdir=>d)
filename = "\u3042"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
- ents = Dir.entries(".", opts)
+ ents = Dir.entries(".", **(opts||{}))
if /darwin/ =~ RUBY_PLATFORM
filename = filename.force_encoding("euc-jp")
end
@@ -420,7 +420,7 @@ class TestDir_M17N < Test::Unit::TestCase
else
orig.each {|o| o.force_encoding(enc) }
end
- ents = Dir.entries(".", opts).reject {|n| /\A\./ =~ n}
+ ents = Dir.entries(".", **(opts||{})).reject {|n| /\A\./ =~ n}
ents.sort!
PP.assert_equal(orig, ents, bug7267)
}
diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb
index 6f098db454..115ff73ea8 100644
--- a/test/ruby/test_econv.rb
+++ b/test/ruby/test_econv.rb
@@ -3,7 +3,12 @@ require 'test/unit'
class TestEncodingConverter < Test::Unit::TestCase
def check_ec(edst, esrc, eres, dst, src, ec, off, len, opts=nil)
- res = ec.primitive_convert(src, dst, off, len, opts)
+ case opts
+ when Hash
+ res = ec.primitive_convert(src, dst, off, len, **opts)
+ else
+ res = ec.primitive_convert(src, dst, off, len, opts)
+ end
assert_equal([edst.b, esrc.b, eres],
[dst.b, src.b, res])
end
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 9de1b2d82c..e5c38091ac 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -1223,6 +1223,14 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0])
assert_raise(ArgumentError) {warn("test warning", uplevel: -1)}
assert_in_out_err(["-e", "warn 'ok', uplevel: 1"], '', [], /warning:/)
+ warning = capture_warning_warn {warn("test warning", {uplevel: 0})}
+ assert_equal("#{__FILE__}:#{__LINE__-1}: warning: The last argument is used as the keyword parameter\n", warning[0])
+ assert_match(/warning: for method defined here|warning: test warning/, warning[1])
+ warning = capture_warning_warn {warn("test warning", **{uplevel: 0})}
+ assert_equal("#{__FILE__}:#{__LINE__-1}: warning: test warning\n", warning[0])
+ warning = capture_warning_warn {warn("test warning", {uplevel: 0}, **{})}
+ assert_equal("test warning\n{:uplevel=>0}\n", warning[0])
+ assert_raise(ArgumentError) {warn("test warning", foo: 1)}
end
def test_warning_warn_invalid_argument
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index ed60452b36..a610b608aa 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -423,7 +423,7 @@ class TestIO < Test::Unit::TestCase
path = t.path
t.close!
assert_raise(Errno::ENOENT, "[ruby-dev:33072]") do
- File.read(path, nil, nil, {})
+ File.read(path, nil, nil, **{})
end
end
@@ -2489,15 +2489,15 @@ class TestIO < Test::Unit::TestCase
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = []
- IO.foreach(t.path, {:mode => "r" }) {|x| a << x }
+ IO.foreach(t.path, :mode => "r") {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = []
- IO.foreach(t.path, {:open_args => [] }) {|x| a << x }
+ IO.foreach(t.path, :open_args => []) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = []
- IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x }
+ IO.foreach(t.path, :open_args => ["r"]) {|x| a << x }
assert_equal(["foo\n", "bar\n", "baz\n"], a)
a = []
@@ -3119,7 +3119,9 @@ __END__
assert_equal(1, File.write(path, "f", 0, encoding: "UTF-8"))
assert_equal("ff", File.read(path))
assert_raise(TypeError) {
- File.write(path, "foo", Object.new => Object.new)
+ assert_warn(/The last argument is split into positional and keyword parameters/) do
+ File.write(path, "foo", Object.new => Object.new)
+ end
}
end
end
diff --git a/test/ruby/test_io_m17n.rb b/test/ruby/test_io_m17n.rb
index 8101bfb62f..022ff330b5 100644
--- a/test/ruby/test_io_m17n.rb
+++ b/test/ruby/test_io_m17n.rb
@@ -23,7 +23,8 @@ class TestIO_M17N < Test::Unit::TestCase
def pipe(*args, wp, rp)
re, we = nil, nil
- r, w = IO.pipe(*args)
+ kw = args.last.is_a?(Hash) ? args.pop : {}
+ r, w = IO.pipe(*args, **kw)
rt = Thread.new do
begin
rp.call(r)
diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb
index 3f87f860b1..7f4a329c4a 100644
--- a/test/ruby/test_literal.rb
+++ b/test/ruby/test_literal.rb
@@ -189,7 +189,7 @@ class TestRubyLiteral < Test::Unit::TestCase
def test_debug_frozen_string
src = 'n = 1; _="foo#{n ? "-#{n}" : ""}"'; f = "test.rb"; n = 1
opt = {frozen_string_literal: true, debug_frozen_string_literal: true}
- str = RubyVM::InstructionSequence.compile(src, f, f, n, opt).eval
+ str = RubyVM::InstructionSequence.compile(src, f, f, n, **opt).eval
assert_equal("foo-1", str)
assert_predicate(str, :frozen?)
assert_raise_with_message(FrozenError, /created at #{Regexp.quote(f)}:#{n}/) {
@@ -200,7 +200,7 @@ class TestRubyLiteral < Test::Unit::TestCase
def test_debug_frozen_string_in_array_literal
src = '["foo"]'; f = "test.rb"; n = 1
opt = {frozen_string_literal: true, debug_frozen_string_literal: true}
- ary = RubyVM::InstructionSequence.compile(src, f, f, n, opt).eval
+ ary = RubyVM::InstructionSequence.compile(src, f, f, n, **opt).eval
assert_equal("foo", ary.first)
assert_predicate(ary.first, :frozen?)
assert_raise_with_message(FrozenError, /created at #{Regexp.quote(f)}:#{n}/) {
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 6073ec1ee5..f87abbb4a8 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -230,7 +230,8 @@ class TestNumeric < Test::Unit::TestCase
end
def assert_step(expected, (from, *args), inf: false)
- enum = from.step(*args)
+ kw = args.last.is_a?(Hash) ? args.pop : {}
+ enum = from.step(*args, **kw)
size = enum.size
xsize = expected.size
@@ -239,7 +240,7 @@ class TestNumeric < Test::Unit::TestCase
assert_send [size, :>, 0], "step size: +infinity"
a = []
- from.step(*args) { |x| a << x; break if a.size == xsize }
+ from.step(*args, **kw) { |x| a << x; break if a.size == xsize }
assert_equal expected, a, "step"
a = []
@@ -249,7 +250,7 @@ class TestNumeric < Test::Unit::TestCase
assert_equal expected.size, size, "step size"
a = []
- from.step(*args) { |x| a << x }
+ from.step(*args, **kw) { |x| a << x }
assert_equal expected, a, "step"
a = []
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 36d246f9e0..dd403bf9d9 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -17,8 +17,8 @@ class TestString < Test::Unit::TestCase
super
end
- def S(*args)
- @cls.new(*args)
+ def S(*args, **kw)
+ @cls.new(*args, **kw)
end
def test_s_new