summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/bug_reporter/test_bug_reporter.rb1
-rw-r--r--test/-ext-/postponed_job/test_postponed_job.rb7
-rw-r--r--test/-ext-/string/test_capacity.rb37
-rw-r--r--test/-ext-/string/test_rb_str_dup.rb6
-rw-r--r--test/-ext-/wait/test_wait.rb16
-rw-r--r--test/bigdecimal/test_bigdecimal.rb6
-rw-r--r--test/bigdecimal/test_ractor.rb2
-rw-r--r--test/cgi/test_cgi_cookie.rb5
-rw-r--r--test/coverage/test_coverage.rb146
-rw-r--r--test/csv/interface/test_read.rb32
-rw-r--r--test/csv/interface/test_read_write.rb9
-rw-r--r--test/csv/interface/test_write.rb34
-rw-r--r--test/csv/parse/test_invalid.rb13
-rw-r--r--test/date/test_date_parse.rb71
-rw-r--r--test/date/test_date_strftime.rb2
-rw-r--r--test/did_you_mean/spell_checking/test_pattern_key_name_check.rb20
-rw-r--r--test/did_you_mean/test_spell_checker.rb1
-rw-r--r--test/did_you_mean/test_verbose_formatter.rb23
-rw-r--r--test/drb/drbtest.rb6
-rw-r--r--test/error_highlight/test_error_highlight.rb4
-rw-r--r--test/fiber/scheduler.rb8
-rw-r--r--test/fiber/test_scheduler.rb1
-rw-r--r--test/io/console/test_io_console.rb10
-rw-r--r--test/io/wait/test_io_wait_uncommon.rb2
-rw-r--r--test/io/wait/test_ractor.rb6
-rw-r--r--test/irb/test_cmd.rb24
-rw-r--r--test/irb/test_completion.rb14
-rw-r--r--test/irb/test_context.rb22
-rw-r--r--test/irb/test_init.rb1
-rw-r--r--test/irb/test_ruby_lex.rb41
-rw-r--r--test/irb/yamatanooroti/test_rendering.rb46
-rw-r--r--test/lib/jit_support.rb1
-rw-r--r--test/mkmf/test_have_var.rb17
-rw-r--r--test/net/http/test_http.rb24
-rw-r--r--test/net/http/test_http_request.rb5
-rw-r--r--test/objspace/test_objspace.rb4
-rw-r--r--test/openssl/test_asn1.rb2
-rw-r--r--test/openssl/test_bn.rb4
-rw-r--r--test/openssl/test_config.rb16
-rw-r--r--test/openssl/test_digest.rb2
-rw-r--r--test/openssl/test_pair.rb3
-rw-r--r--test/openssl/test_pkcs12.rb297
-rw-r--r--test/openssl/test_pkey.rb27
-rw-r--r--test/openssl/test_pkey_dh.rb8
-rw-r--r--test/openssl/test_pkey_dsa.rb15
-rw-r--r--test/openssl/test_pkey_ec.rb17
-rw-r--r--test/openssl/test_pkey_rsa.rb33
-rw-r--r--test/openssl/test_ssl.rb207
-rw-r--r--test/openssl/test_ssl_session.rb8
-rw-r--r--test/openssl/test_ts.rb18
-rw-r--r--test/openssl/utils.rb46
-rw-r--r--test/optparse/test_did_you_mean.rb10
-rw-r--r--test/ostruct/test_ostruct.rb12
-rw-r--r--test/rdoc/test_rdoc_any_method.rb48
-rw-r--r--test/rdoc/test_rdoc_class_module.rb4
-rw-r--r--test/rdoc/test_rdoc_cross_reference.rb2
-rw-r--r--test/rdoc/test_rdoc_parser_c.rb66
-rw-r--r--test/readline/test_readline.rb9
-rw-r--r--test/reline/test_key_actor_emacs.rb21
-rw-r--r--test/reline/test_reline.rb69
-rw-r--r--test/reline/test_reline_key.rb53
-rwxr-xr-xtest/reline/yamatanooroti/multiline_repl67
-rw-r--r--test/reline/yamatanooroti/test_rendering.rb190
-rw-r--r--test/ruby/test_autoload.rb27
-rw-r--r--test/ruby/test_class.rb79
-rw-r--r--test/ruby/test_dir.rb8
-rw-r--r--test/ruby/test_enum.rb12
-rw-r--r--test/ruby/test_env.rb2
-rw-r--r--test/ruby/test_eval.rb70
-rw-r--r--test/ruby/test_fiber.rb2
-rw-r--r--test/ruby/test_file_exhaustive.rb50
-rw-r--r--test/ruby/test_gc_compact.rb5
-rw-r--r--test/ruby/test_integer.rb25
-rw-r--r--test/ruby/test_io.rb24
-rw-r--r--test/ruby/test_io_buffer.rb195
-rw-r--r--test/ruby/test_iseq.rb122
-rw-r--r--test/ruby/test_jit.rb26
-rw-r--r--test/ruby/test_literal.rb11
-rw-r--r--test/ruby/test_m17n.rb7
-rw-r--r--test/ruby/test_marshal.rb89
-rw-r--r--test/ruby/test_module.rb51
-rw-r--r--test/ruby/test_objectspace.rb2
-rw-r--r--test/ruby/test_optimization.rb42
-rw-r--r--test/ruby/test_pack.rb34
-rw-r--r--test/ruby/test_parse.rb14
-rw-r--r--test/ruby/test_pattern_matching.rb19
-rw-r--r--test/ruby/test_proc.rb12
-rw-r--r--test/ruby/test_process.rb95
-rw-r--r--test/ruby/test_refinement.rb105
-rw-r--r--test/ruby/test_regexp.rb21
-rw-r--r--test/ruby/test_require.rb84
-rw-r--r--test/ruby/test_rubyoptions.rb28
-rw-r--r--test/ruby/test_rubyvm.rb53
-rw-r--r--test/ruby/test_settracefunc.rb132
-rw-r--r--test/ruby/test_sprintf.rb15
-rw-r--r--test/ruby/test_string.rb2
-rw-r--r--test/ruby/test_struct.rb8
-rw-r--r--test/ruby/test_super.rb37
-rw-r--r--test/ruby/test_syntax.rb57
-rw-r--r--test/ruby/test_thread.rb8
-rw-r--r--test/ruby/test_thread_cv.rb3
-rw-r--r--test/ruby/test_time.rb23
-rw-r--r--test/ruby/test_undef.rb16
-rw-r--r--test/ruby/test_yjit.rb662
-rw-r--r--test/rubygems/encrypted_private_key.pem52
-rw-r--r--test/rubygems/helper.rb78
-rw-r--r--test/rubygems/private_ec_key.pem9
-rw-r--r--test/rubygems/test_gem.rb130
-rw-r--r--test/rubygems/test_gem_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_cert_command.rb83
-rw-r--r--test/rubygems/test_gem_commands_fetch_command.rb36
-rw-r--r--test/rubygems/test_gem_commands_server_command.rb50
-rw-r--r--test/rubygems/test_gem_commands_setup_command.rb69
-rw-r--r--test/rubygems/test_gem_commands_signin_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_uninstall_command.rb2
-rw-r--r--test/rubygems/test_gem_commands_yank_command.rb2
-rw-r--r--test/rubygems/test_gem_ext_ext_conf_builder.rb10
-rw-r--r--test/rubygems/test_gem_install_update_options.rb4
-rw-r--r--test/rubygems/test_gem_installer.rb42
-rw-r--r--test/rubygems/test_gem_package.rb53
-rw-r--r--test/rubygems/test_gem_request.rb26
-rw-r--r--test/rubygems/test_gem_resolver.rb14
-rw-r--r--test/rubygems/test_gem_security.rb38
-rw-r--r--test/rubygems/test_gem_server.rb608
-rw-r--r--test/rubygems/test_gem_source_fetch_problem.rb10
-rw-r--r--test/rubygems/test_gem_specification.rb471
-rw-r--r--test/rubygems/test_gem_uri.rb7
-rw-r--r--test/rubygems/test_require.rb10
-rw-r--r--test/runner.rb2
-rw-r--r--test/socket/test_socket.rb4
-rw-r--r--test/test_getoptlong.rb163
-rw-r--r--test/test_ipaddr.rb59
-rw-r--r--test/test_timeout.rb11
-rw-r--r--test/uri/test_http.rb31
-rw-r--r--test/win32ole/test_win32ole.rb2
-rw-r--r--test/win32ole/test_win32ole_event.rb3
-rw-r--r--test/zlib/test_zlib.rb10
137 files changed, 4484 insertions, 1807 deletions
diff --git a/test/-ext-/bug_reporter/test_bug_reporter.rb b/test/-ext-/bug_reporter/test_bug_reporter.rb
index ac6d92bb67f..6d3640eba59 100644
--- a/test/-ext-/bug_reporter/test_bug_reporter.rb
+++ b/test/-ext-/bug_reporter/test_bug_reporter.rb
@@ -8,6 +8,7 @@ class TestBugReporter < Test::Unit::TestCase
description = RUBY_DESCRIPTION
description = description.sub(/\+JIT /, '') if defined?(RubyVM::JIT) && RubyVM::JIT.enabled?
+ description = description.sub(/\+YJIT /, '') if defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
expected_stderr = [
:*,
/\[BUG\]\sSegmentation\sfault.*\n/,
diff --git a/test/-ext-/postponed_job/test_postponed_job.rb b/test/-ext-/postponed_job/test_postponed_job.rb
index 7dc28776d0c..fee0172d114 100644
--- a/test/-ext-/postponed_job/test_postponed_job.rb
+++ b/test/-ext-/postponed_job/test_postponed_job.rb
@@ -25,4 +25,11 @@ class TestPostponed_job < Test::Unit::TestCase
Bug.postponed_job_register_one(ary = [])
assert_equal [1], ary
end
+
+ if Bug.respond_to?(:postponed_job_register_in_c_thread)
+ def test_register_in_c_thread
+ assert Bug.postponed_job_register_in_c_thread(ary = [])
+ assert_equal [1], ary
+ end
+ end
end
diff --git a/test/-ext-/string/test_capacity.rb b/test/-ext-/string/test_capacity.rb
index df59e767781..583c98fca46 100644
--- a/test/-ext-/string/test_capacity.rb
+++ b/test/-ext-/string/test_capacity.rb
@@ -4,13 +4,10 @@ require '-test-/string'
require 'rbconfig/sizeof'
class Test_StringCapacity < Test::Unit::TestCase
- def capa(str)
- Bug::String.capacity(str)
- end
-
def test_capacity_embedded
- size = RbConfig::SIZEOF['void*'] * 3 - 1
- assert_equal size, capa('foo')
+ assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] - embed_header_size - 1, capa('foo')
+ assert_equal max_embed_len, capa('1' * max_embed_len)
+ assert_equal max_embed_len, capa('1' * (max_embed_len - 1))
end
def test_capacity_shared
@@ -18,7 +15,8 @@ class Test_StringCapacity < Test::Unit::TestCase
end
def test_capacity_normal
- assert_equal 128, capa('1'*128)
+ assert_equal max_embed_len + 1, capa('1' * (max_embed_len + 1))
+ assert_equal max_embed_len + 100, capa('1' * (max_embed_len + 100))
end
def test_s_new_capacity
@@ -39,7 +37,10 @@ class Test_StringCapacity < Test::Unit::TestCase
end
def test_literal_capacity
- s = "I am testing string literal capacity"
+ s = eval(%{
+ # frozen_string_literal: true
+ "#{"a" * (max_embed_len + 1)}"
+ })
assert_equal(s.length, capa(s))
end
@@ -51,9 +52,27 @@ class Test_StringCapacity < Test::Unit::TestCase
end
def test_capacity_fstring
- s = String.new("I am testing", capacity: 1000)
+ s = String.new("a" * max_embed_len, capacity: 1000)
s << "fstring capacity"
s = -s
assert_equal(s.length, capa(s))
end
+
+ private
+
+ def capa(str)
+ Bug::String.capacity(str)
+ end
+
+ def embed_header_size
+ if GC.using_rvargc?
+ 2 * RbConfig::SIZEOF['void*'] + RbConfig::SIZEOF['short']
+ else
+ 2 * RbConfig::SIZEOF['void*']
+ end
+ end
+
+ def max_embed_len
+ GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE] - embed_header_size - 1
+ end
end
diff --git a/test/-ext-/string/test_rb_str_dup.rb b/test/-ext-/string/test_rb_str_dup.rb
index 49b6af9598d..c76a90252f7 100644
--- a/test/-ext-/string/test_rb_str_dup.rb
+++ b/test/-ext-/string/test_rb_str_dup.rb
@@ -3,13 +3,15 @@ require '-test-/string'
class Test_RbStrDup < Test::Unit::TestCase
def test_nested_shared_non_frozen
- str = Bug::String.rb_str_dup(Bug::String.rb_str_dup("a" * 50))
+ orig_str = "a" * GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE]
+ str = Bug::String.rb_str_dup(Bug::String.rb_str_dup(orig_str))
assert_send([Bug::String, :shared_string?, str])
assert_not_send([Bug::String, :sharing_with_shared?, str], '[Bug #15792]')
end
def test_nested_shared_frozen
- str = Bug::String.rb_str_dup(Bug::String.rb_str_dup("a" * 50).freeze)
+ orig_str = "a" * GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE]
+ str = Bug::String.rb_str_dup(Bug::String.rb_str_dup(orig_str).freeze)
assert_send([Bug::String, :shared_string?, str])
assert_not_send([Bug::String, :sharing_with_shared?, str], '[Bug #15792]')
end
diff --git a/test/-ext-/wait/test_wait.rb b/test/-ext-/wait/test_wait.rb
index 79127c041b5..8e53f067cf3 100644
--- a/test/-ext-/wait/test_wait.rb
+++ b/test/-ext-/wait/test_wait.rb
@@ -12,14 +12,18 @@ class TestWait < Test::Unit::TestCase
end
def test_wait_for_invalid_fd
- r, w = IO.pipe
- r.close
+ assert_separately [], <<~'RUBY'
+ require '-test-/wait'
- IO.for_fd(w.fileno).close
+ r, w = IO.pipe
+ r.close
- assert_raise(Errno::EBADF) do
- IO.io_wait(w, IO::WRITABLE, nil)
- end
+ IO.for_fd(w.fileno).close
+
+ assert_raise(Errno::EBADF) do
+ IO.io_wait(w, IO::WRITABLE, nil)
+ end
+ RUBY
end
def test_wait_for_closed_pipe
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb
index 99f92c461c5..49e6b2a70e1 100644
--- a/test/bigdecimal/test_bigdecimal.rb
+++ b/test/bigdecimal/test_bigdecimal.rb
@@ -146,6 +146,7 @@ class TestBigDecimal < Test::Unit::TestCase
def test_BigDecimal_with_float
assert_equal(BigDecimal("0.1235"), BigDecimal(0.1234567, 4))
assert_equal(BigDecimal("-0.1235"), BigDecimal(-0.1234567, 4))
+ assert_equal(BigDecimal("0.01"), BigDecimal(0.01, Float::DIG + 1))
assert_raise_with_message(ArgumentError, "can't omit precision for a Float.") { BigDecimal(4.2) }
assert_raise(ArgumentError) { BigDecimal(0.1, Float::DIG + 2) }
assert_nothing_raised { BigDecimal(0.1, Float::DIG + 1) }
@@ -656,13 +657,10 @@ class TestBigDecimal < Test::Unit::TestCase
end
def test_precs_deprecated
- saved = Warning[:deprecated]
- Warning[:deprecated] = true
assert_warn(/BigDecimal#precs is deprecated and will be removed in the future/) do
+ Warning[:deprecated] = true if defined?(Warning.[])
BigDecimal("1").precs
end
- ensure
- Warning[:deprecated] = saved
end
def test_precs
diff --git a/test/bigdecimal/test_ractor.rb b/test/bigdecimal/test_ractor.rb
index f78663f15e2..798cc494e18 100644
--- a/test/bigdecimal/test_ractor.rb
+++ b/test/bigdecimal/test_ractor.rb
@@ -6,7 +6,7 @@ class TestBigDecimalRactor < Test::Unit::TestCase
def setup
super
- skip unless defined? Ractor
+ omit unless defined? Ractor
end
def test_ractor_shareable
diff --git a/test/cgi/test_cgi_cookie.rb b/test/cgi/test_cgi_cookie.rb
index 115a57e4a10..985cc0d7a1a 100644
--- a/test/cgi/test_cgi_cookie.rb
+++ b/test/cgi/test_cgi_cookie.rb
@@ -101,6 +101,11 @@ class CGICookieTest < Test::Unit::TestCase
end
end
+ def test_cgi_cookie_parse_not_decode_name
+ cookie_str = "%66oo=baz;foo=bar"
+ cookies = CGI::Cookie.parse(cookie_str)
+ assert_equal({"%66oo" => ["baz"], "foo" => ["bar"]}, cookies)
+ end
def test_cgi_cookie_arrayinterface
cookie = CGI::Cookie.new('name1', 'a', 'b', 'c')
diff --git a/test/coverage/test_coverage.rb b/test/coverage/test_coverage.rb
index 22557bd9d8b..882368363a8 100644
--- a/test/coverage/test_coverage.rb
+++ b/test/coverage/test_coverage.rb
@@ -774,4 +774,150 @@ class TestCoverage < Test::Unit::TestCase
end
end;
end
+
+ def test_coverage_suspendable
+ Dir.mktmpdir {|tmp|
+ Dir.chdir(tmp) {
+ File.open("test.rb", "w") do |f|
+ f.puts <<-EOS
+ def foo
+ :ok
+ end
+
+ def bar
+ :ok
+ end
+
+ def baz
+ :ok
+ end
+ EOS
+ end
+
+ cov1 = "[0, 0, nil, nil, 0, 1, nil, nil, 0, 0, nil]"
+ cov2 = "[0, 0, nil, nil, 0, 1, nil, nil, 0, 1, nil]"
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [cov1, cov2], [])
+ Coverage.setup
+ tmp = Dir.pwd
+ require tmp + "/test.rb"
+ foo
+ Coverage.resume
+ bar
+ Coverage.suspend
+ baz
+ p Coverage.peek_result[tmp + "/test.rb"]
+ Coverage.resume
+ baz
+ p Coverage.result[tmp + "/test.rb"]
+ end;
+
+ cov1 = "{:lines=>[0, 0, nil, nil, 0, 1, nil, nil, 0, 0, nil], :branches=>{}, :methods=>{[Object, :baz, 9, 12, 11, 15]=>0, [Object, :bar, 5, 12, 7, 15]=>1, [Object, :foo, 1, 12, 3, 15]=>0}}"
+ cov2 = "{:lines=>[0, 0, nil, nil, 0, 1, nil, nil, 0, 1, nil], :branches=>{}, :methods=>{[Object, :baz, 9, 12, 11, 15]=>1, [Object, :bar, 5, 12, 7, 15]=>1, [Object, :foo, 1, 12, 3, 15]=>0}}"
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [cov1, cov2], [])
+ Coverage.setup(:all)
+ tmp = Dir.pwd
+ require tmp + "/test.rb"
+ foo
+ Coverage.resume
+ bar
+ Coverage.suspend
+ baz
+ p Coverage.peek_result[tmp + "/test.rb"]
+ Coverage.resume
+ baz
+ p Coverage.result[tmp + "/test.rb"]
+ end;
+
+ cov1 = "{:oneshot_lines=>[6]}"
+ cov2 = "{:oneshot_lines=>[6, 10]}"
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [cov1, cov2], [])
+ Coverage.setup(oneshot_lines: true)
+ tmp = Dir.pwd
+ require tmp + "/test.rb"
+ foo
+ Coverage.resume
+ bar
+ Coverage.suspend
+ baz
+ p Coverage.peek_result[tmp + "/test.rb"]
+ Coverage.resume
+ baz
+ p Coverage.result[tmp + "/test.rb"]
+ end;
+ }
+ }
+ end
+
+ def test_coverage_state
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [":idle", ":running", ":running", ":idle"], [])
+ p Coverage.state
+ Coverage.start
+ p Coverage.state
+ Coverage.peek_result
+ p Coverage.state
+ Coverage.result
+ p Coverage.state
+ end;
+
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [":idle", ":suspended", ":running", ":suspended", ":running", ":suspended", ":idle"], [])
+ p Coverage.state
+ Coverage.setup
+ p Coverage.state
+ Coverage.resume
+ p Coverage.state
+ Coverage.suspend
+ p Coverage.state
+ Coverage.resume
+ p Coverage.state
+ Coverage.suspend
+ p Coverage.state
+ Coverage.result
+ p Coverage.state
+ end;
+ end
+
+ def test_result_without_resume
+ assert_in_out_err(%w[-rcoverage], <<-"end;", ["{}"], [])
+ Coverage.setup
+ p Coverage.result
+ end;
+ end
+
+ def test_result_after_suspend
+ assert_in_out_err(%w[-rcoverage], <<-"end;", ["{}"], [])
+ Coverage.start
+ Coverage.suspend
+ p Coverage.result
+ end;
+ end
+
+ def test_resume_without_setup
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [], /coverage measurement is not set up yet/)
+ Coverage.resume
+ p :NG
+ end;
+ end
+
+ def test_suspend_without_setup
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [], /coverage measurement is not running/)
+ Coverage.suspend
+ p :NG
+ end;
+ end
+
+ def test_double_resume
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [], /coverage measurement is already running/)
+ Coverage.start
+ Coverage.resume
+ p :NG
+ end;
+ end
+
+ def test_double_suspend
+ assert_in_out_err(%w[-rcoverage], <<-"end;", [], /coverage measurement is not running/)
+ Coverage.setup
+ Coverage.suspend
+ p :NG
+ end;
+ end
end
diff --git a/test/csv/interface/test_read.rb b/test/csv/interface/test_read.rb
index b86c54fc9f6..d73622d554b 100644
--- a/test/csv/interface/test_read.rb
+++ b/test/csv/interface/test_read.rb
@@ -32,6 +32,24 @@ class TestCSVInterfaceRead < Test::Unit::TestCase
assert_equal(@rows, rows)
end
+ if respond_to?(:ractor)
+ ractor
+ def test_foreach_in_ractor
+ ractor = Ractor.new(@input.path) do |path|
+ rows = []
+ CSV.foreach(path, col_sep: "\t", row_sep: "\r\n").each do |row|
+ rows << row
+ end
+ rows
+ end
+ rows = [
+ ["1", "2", "3"],
+ ["4", "5"],
+ ]
+ assert_equal(rows, ractor.take)
+ end
+ end
+
def test_foreach_mode
rows = []
CSV.foreach(@input.path, "r", col_sep: "\t", row_sep: "\r\n").each do |row|
@@ -240,6 +258,20 @@ class TestCSVInterfaceRead < Test::Unit::TestCase
CSV.read(@input.path, col_sep: "\t", row_sep: "\r\n"))
end
+ if respond_to?(:ractor)
+ ractor
+ def test_read_in_ractor
+ ractor = Ractor.new(@input.path) do |path|
+ CSV.read(path, col_sep: "\t", row_sep: "\r\n")
+ end
+ rows = [
+ ["1", "2", "3"],
+ ["4", "5"],
+ ]
+ assert_equal(rows, ractor.take)
+ end
+ end
+
def test_readlines
assert_equal(@rows,
CSV.readlines(@input.path, col_sep: "\t", row_sep: "\r\n"))
diff --git a/test/csv/interface/test_read_write.rb b/test/csv/interface/test_read_write.rb
index 20c9fe317ec..c371e9c5fcf 100644
--- a/test/csv/interface/test_read_write.rb
+++ b/test/csv/interface/test_read_write.rb
@@ -112,4 +112,13 @@ a;b;c
assert_equal(CSV.instance,
CSV {|csv| csv})
end
+
+ def test_instance_shortcut_with_io
+ io = StringIO.new
+ from_instance = CSV.instance(io, col_sep: ";") { |csv| csv << ["a", "b", "c"] }
+ from_shortcut = CSV(io, col_sep: ";") { |csv| csv << ["e", "f", "g"] }
+
+ assert_equal(from_instance, from_shortcut)
+ assert_equal(from_instance.string, "a;b;c\ne;f;g\n")
+ end
end
diff --git a/test/csv/interface/test_write.rb b/test/csv/interface/test_write.rb
index 8650ecd624a..02c2c5c5cee 100644
--- a/test/csv/interface/test_write.rb
+++ b/test/csv/interface/test_write.rb
@@ -25,6 +25,21 @@ class TestCSVInterfaceWrite < Test::Unit::TestCase
CSV
end
+ if respond_to?(:ractor)
+ ractor
+ def test_generate_default_in_ractor
+ ractor = Ractor.new do
+ CSV.generate do |csv|
+ csv << [1, 2, 3] << [4, nil, 5]
+ end
+ end
+ assert_equal(<<-CSV, ractor.take)
+1,2,3
+4,,5
+ CSV
+ end
+ end
+
def test_generate_append
csv_text = <<-CSV
1,2,3
@@ -101,6 +116,25 @@ a,b,c
CSV
end
+
+ if respond_to?(:ractor)
+ ractor
+ def test_append_row_in_ractor
+ ractor = Ractor.new(@output.path) do |path|
+ CSV.open(path, "wb") do |csv|
+ csv <<
+ CSV::Row.new([], ["1", "2", "3"]) <<
+ CSV::Row.new([], ["a", "b", "c"])
+ end
+ end
+ ractor.take
+ assert_equal(<<-CSV, File.read(@output.path, mode: "rb"))
+1,2,3
+a,b,c
+ CSV
+ end
+ end
+
def test_append_hash
CSV.open(@output.path, "wb", headers: true) do |csv|
csv << [:a, :b, :c]
diff --git a/test/csv/parse/test_invalid.rb b/test/csv/parse/test_invalid.rb
index 9dfd0813801..ddb59e2b9a0 100644
--- a/test/csv/parse/test_invalid.rb
+++ b/test/csv/parse/test_invalid.rb
@@ -36,4 +36,17 @@ ggg,hhh,iii
csv.shift)
assert_equal(true, csv.eof?)
end
+
+ def test_ignore_invalid_line_cr_lf
+ data = <<-CSV
+"1","OK"\r
+"2",""NOT" OK"\r
+"3","OK"\r
+CSV
+ csv = CSV.new(data)
+
+ assert_equal(['1', 'OK'], csv.shift)
+ assert_raise(CSV::MalformedCSVError) { csv.shift }
+ assert_equal(['3', 'OK'], csv.shift)
+ end
end
diff --git a/test/date/test_date_parse.rb b/test/date/test_date_parse.rb
index 9f92635387b..34a672b069c 100644
--- a/test/date/test_date_parse.rb
+++ b/test/date/test_date_parse.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'test/unit'
require 'date'
+require 'timeout'
class TestDateParse < Test::Unit::TestCase
@@ -847,6 +848,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._iso8601('')
assert_equal({}, h)
+
+ h = Date._iso8601(nil)
+ assert_equal({}, h)
+
+ h = Date._iso8601('01-02-03T04:05:06Z'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__rfc3339
@@ -862,6 +870,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc3339('')
assert_equal({}, h)
+
+ h = Date._rfc3339(nil)
+ assert_equal({}, h)
+
+ h = Date._rfc3339('2001-02-03T04:05:06Z'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__xmlschema
@@ -944,6 +959,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._xmlschema('')
assert_equal({}, h)
+
+ h = Date._xmlschema(nil)
+ assert_equal({}, h)
+
+ h = Date._xmlschema('2001-02-03'.to_sym)
+ assert_equal([2001, 2, 3, nil, nil, nil, nil],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__rfc2822
@@ -976,6 +998,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._rfc2822('')
assert_equal({}, h)
+
+ h = Date._rfc2822(nil)
+ assert_equal({}, h)
+
+ h = Date._rfc2822('Sat, 3 Feb 2001 04:05:06 UT'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__httpdate
@@ -996,6 +1025,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._httpdate('')
assert_equal({}, h)
+
+ h = Date._httpdate(nil)
+ assert_equal({}, h)
+
+ h = Date._httpdate('Sat, 03 Feb 2001 04:05:06 GMT'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 0],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test__jisx0301
@@ -1072,6 +1108,13 @@ class TestDateParse < Test::Unit::TestCase
h = Date._jisx0301('')
assert_equal({}, h)
+
+ h = Date._jisx0301(nil)
+ assert_equal({}, h)
+
+ h = Date._jisx0301('H13.02.03T04:05:06.07+0100'.to_sym)
+ assert_equal([2001, 2, 3, 4, 5, 6, 3600],
+ h.values_at(:year, :mon, :mday, :hour, :min, :sec, :offset))
end
def test_iso8601
@@ -1228,4 +1271,32 @@ class TestDateParse < Test::Unit::TestCase
assert_equal(s0, s)
end
+ def test_length_limit
+ assert_raise(ArgumentError) { Date._parse("1" * 1000) }
+ assert_raise(ArgumentError) { Date._iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { Date._xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { Date._rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { Date._jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { Date.parse("1" * 1000) }
+ assert_raise(ArgumentError) { Date.iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { Date.xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { Date.rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { Date.jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { DateTime.parse("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.iso8601("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc3339("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.xmlschema("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc2822("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.rfc822("1" * 1000) }
+ assert_raise(ArgumentError) { DateTime.jisx0301("1" * 1000) }
+
+ assert_raise(ArgumentError) { Date._parse("Jan " + "9" * 1000000) }
+ assert_raise(Timeout::Error) { Timeout.timeout(1) { Date._parse("Jan " + "9" * 1000000, limit: nil) } }
+ end
end
diff --git a/test/date/test_date_strftime.rb b/test/date/test_date_strftime.rb
index f82874d26d0..be9354504a5 100644
--- a/test/date/test_date_strftime.rb
+++ b/test/date/test_date_strftime.rb
@@ -48,7 +48,7 @@ class TestDateStrftime < Test::Unit::TestCase
'%t'=>["\t",{}],
'%u'=>['6',{:cwday=>6}],
'%V'=>['05',{:cweek=>5}],
- '%v'=>[' 3-Feb-2001',{:mday=>3,:mon=>2,:year=>2001}],
+ '%v'=>[' 3-FEB-2001',{:mday=>3,:mon=>2,:year=>2001}],
'%z'=>['+0000',{:zone=>'+0000',:offset=>0}],
'%+'=>['Sat Feb 3 00:00:00 +00:00 2001',
{:wday=>6,:mon=>2,:mday=>3,
diff --git a/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
new file mode 100644
index 00000000000..2b0752a56a9
--- /dev/null
+++ b/test/did_you_mean/spell_checking/test_pattern_key_name_check.rb
@@ -0,0 +1,20 @@
+require_relative '../helper'
+
+return if !defined?(::NoMatchingPatternKeyError)
+
+class PatternKeyNameCheckTest < Test::Unit::TestCase
+ include DidYouMean::TestHelper
+
+ def test_corrects_hash_key_name_with_single_pattern_match
+ error = assert_raise(NoMatchingPatternKeyError) do
+ eval(<<~RUBY, binding, __FILE__, __LINE__)
+ hash = {foo: 1, bar: 2, baz: 3}
+ hash => {fooo:}
+ fooo = 1 # suppress "unused variable: fooo" warning
+ RUBY
+ end
+
+ assert_correction ":foo", error.corrections
+ assert_match "Did you mean? :foo", error.to_s
+ end
+end
diff --git a/test/did_you_mean/test_spell_checker.rb b/test/did_you_mean/test_spell_checker.rb
index 98460b4d94f..8445380de33 100644
--- a/test/did_you_mean/test_spell_checker.rb
+++ b/test/did_you_mean/test_spell_checker.rb
@@ -10,6 +10,7 @@ class SpellCheckerTest < Test::Unit::TestCase
assert_spell 'eval', input: 'veal', dictionary: ['email', 'fail', 'eval']
assert_spell 'sub!', input: 'suv!', dictionary: ['sub', 'gsub', 'sub!']
assert_spell 'sub', input: 'suv', dictionary: ['sub', 'gsub', 'sub!']
+ assert_spell 'Foo', input: 'FOo', dictionary: ['Foo', 'FOo']
assert_spell %w(gsub! gsub), input: 'gsuv!', dictionary: %w(sub gsub gsub!)
assert_spell %w(sub! sub gsub!), input: 'ssub!', dictionary: %w(sub sub! gsub gsub!)
diff --git a/test/did_you_mean/test_verbose_formatter.rb b/test/did_you_mean/test_verbose_formatter.rb
deleted file mode 100644
index d8f2f462736..00000000000
--- a/test/did_you_mean/test_verbose_formatter.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require_relative './helper'
-
-class VerboseFormatterTest < Test::Unit::TestCase
- def setup
- require_relative File.join(DidYouMean::TestHelper.root, 'verbose')
-
- DidYouMean.formatter = DidYouMean::VerboseFormatter.new
- end
-
- def teardown
- DidYouMean.formatter = DidYouMean::PlainFormatter.new
- end
-
- def test_message
- @error = assert_raise(NoMethodError){ 1.zeor? }
-
- assert_match <<~MESSAGE.strip, @error.message
- undefined method `zeor?' for 1:Integer
-
- Did you mean? zero?
- MESSAGE
- end
-end
diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb
index acef380ad6b..f3d20201bc9 100644
--- a/test/drb/drbtest.rb
+++ b/test/drb/drbtest.rb
@@ -214,9 +214,9 @@ module DRbCore
end
def test_06_timeout
- skip if RUBY_PLATFORM.include?("armv7l-linux")
- skip if RUBY_PLATFORM.include?("sparc-solaris2.10")
- skip if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # expecting a certain delay is difficult for --jit-wait CI
+ omit if RUBY_PLATFORM.include?("armv7l-linux")
+ omit if RUBY_PLATFORM.include?("sparc-solaris2.10")
+ omit if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # expecting a certain delay is difficult for --jit-wait CI
Timeout.timeout(60) do
ten = Onecky.new(10)
assert_raise(Timeout::Error) do
diff --git a/test/error_highlight/test_error_highlight.rb b/test/error_highlight/test_error_highlight.rb
index 9fc14202b5f..08036bca542 100644
--- a/test/error_highlight/test_error_highlight.rb
+++ b/test/error_highlight/test_error_highlight.rb
@@ -5,7 +5,7 @@ require "tempfile"
class ErrorHighlightTest < Test::Unit::TestCase
class DummyFormatter
- def message_for(corrections)
+ def self.message_for(corrections)
""
end
end
@@ -13,7 +13,7 @@ class ErrorHighlightTest < Test::Unit::TestCase
def setup
if defined?(DidYouMean)
@did_you_mean_old_formatter = DidYouMean.formatter
- DidYouMean.formatter = DummyFormatter.new
+ DidYouMean.formatter = DummyFormatter
end
end
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb
index 8c2fdcb0e06..a6e1325259f 100644
--- a/test/fiber/scheduler.rb
+++ b/test/fiber/scheduler.rb
@@ -14,6 +14,14 @@ rescue LoadError
end
class Scheduler
+ experimental = Warning[:experimental]
+ begin
+ Warning[:experimental] = false
+ IO::Buffer.new(0)
+ ensure
+ Warning[:experimental] = experimental
+ end
+
def initialize
@readable = {}
@writable = {}
diff --git a/test/fiber/test_scheduler.rb b/test/fiber/test_scheduler.rb
index f0f5b79f36f..1870ab1c33e 100644
--- a/test/fiber/test_scheduler.rb
+++ b/test/fiber/test_scheduler.rb
@@ -55,6 +55,7 @@ class TestFiberScheduler < Test::Unit::TestCase
def test_close_at_exit
assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['Running Fiber'], [], success: true
require 'scheduler'
+ Warning[:experimental] = false
scheduler = Scheduler.new
Fiber.set_scheduler scheduler
diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index 3d12b1f463c..33b98990a14 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -7,7 +7,13 @@ rescue LoadError
end
class TestIO_Console < Test::Unit::TestCase
- PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
+ begin
+ PATHS = $LOADED_FEATURES.grep(%r"/io/console(?:\.#{RbConfig::CONFIG['DLEXT']}|\.rb|/\w+\.rb)\z") {$`}
+ rescue Encoding::CompatibilityError
+ $stderr.puts "test_io_console.rb debug"
+ $LOADED_FEATURES.each{|path| $stderr.puts [path, path.encoding].inspect}
+ raise
+ end
PATHS.uniq!
# FreeBSD seems to hang on TTOU when running parallel tests
@@ -375,7 +381,7 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do
if cc = ctrl["intr"]
assert_ctrl("#{cc.ord}", cc, r, w)
assert_ctrl("#{cc.ord}", cc, r, w)
- assert_ctrl("Interrupt", cc, r, w) unless /linux/ =~ RUBY_PLATFORM
+ assert_ctrl("Interrupt", cc, r, w) unless /linux|solaris/ =~ RUBY_PLATFORM
end
if cc = ctrl["dsusp"]
assert_ctrl("#{cc.ord}", cc, r, w)
diff --git a/test/io/wait/test_io_wait_uncommon.rb b/test/io/wait/test_io_wait_uncommon.rb
index b6f1c29bcd9..75cd335802b 100644
--- a/test/io/wait/test_io_wait_uncommon.rb
+++ b/test/io/wait/test_io_wait_uncommon.rb
@@ -45,7 +45,7 @@ class TestIOWaitUncommon < Test::Unit::TestCase
rescue Errno::ENOENT
return # Ignore silently
rescue SystemCallError => e
- skip "#{dev} could not be opened #{e.message} (#{e.class})"
+ omit "#{dev} could not be opened #{e.message} (#{e.class})"
end
if block
yield fp
diff --git a/test/io/wait/test_ractor.rb b/test/io/wait/test_ractor.rb
index 3d286af77f9..3742680cf75 100644
--- a/test/io/wait/test_ractor.rb
+++ b/test/io/wait/test_ractor.rb
@@ -4,10 +4,6 @@ require 'rbconfig'
require 'io/wait'
class TestIOWaitInRactor < Test::Unit::TestCase
- def setup
- omit unless defined? Ractor
- end
-
def test_ractor
ext = "/io/wait.#{RbConfig::CONFIG['DLEXT']}"
path = $".find {|path| path.end_with?(ext)}
@@ -19,4 +15,4 @@ class TestIOWaitInRactor < Test::Unit::TestCase
puts r.take
end;
end
-end
+end if defined? Ractor
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index e6bb587b5cb..8eee36badc6 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -509,6 +509,30 @@ module TestIRB
assert_match(%r[/irb\.rb], out)
end
+ def test_show_source_end_finder
+ pend if RUBY_ENGINE == 'truffleruby'
+ eval(code = <<-EOS, binding, __FILE__, __LINE__ + 1)
+ def show_source_test_method
+ unless true
+ end
+ end
+ EOS
+ input = TestInputMethod.new([
+ "show_source 'TestIRB::ExtendCommand#show_source_test_method'\n",
+ ])
+ IRB.init_config(nil)
+ workspace = IRB::WorkSpace.new(self)
+ IRB.conf[:VERBOSE] = false
+ irb = IRB::Irb.new(workspace, input)
+ IRB.conf[:MAIN_CONTEXT] = irb.context
+ irb.context.return_format = "=> %s\n"
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_include(out, code)
+ end
+
def test_whereami
input = TestInputMethod.new([
"whereami\n",
diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb
index f00eda00586..3aa99d74d34 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -27,6 +27,10 @@ module TestIRB
end
def test_complete_symbol
+ %w"UTF-16LE UTF-7".each do |enc|
+ "K".force_encoding(enc).to_sym
+ rescue
+ end
_ = :aiueo
assert_include(IRB::InputCompletor.retrieve_completion_data(":a", bind: binding), ":aiueo")
assert_empty(IRB::InputCompletor.retrieve_completion_data(":irb_unknown_symbol_abcdefg", bind: binding))
@@ -37,6 +41,13 @@ module TestIRB
assert_empty(IRB::InputCompletor.retrieve_completion_data(":::", bind: binding))
end
+ def test_complete_absolute_constants_with_special_characters
+ assert_empty(IRB::InputCompletor.retrieve_completion_data("::A:", bind: binding))
+ assert_empty(IRB::InputCompletor.retrieve_completion_data("::A.", bind: binding))
+ assert_empty(IRB::InputCompletor.retrieve_completion_data("::A(", bind: binding))
+ assert_empty(IRB::InputCompletor.retrieve_completion_data("::A)", bind: binding))
+ end
+
def test_complete_symbol_failure
assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding))
end
@@ -74,8 +85,9 @@ module TestIRB
end
def test_complete_require_library_name_first
+ pend 'Need to use virtual library paths'
candidates = IRB::InputCompletor::CompletionProc.("'csv", "require ", "")
- assert_equal candidates.first, "'csv"
+ assert_equal "'csv", candidates.first
end
def test_complete_require_relative
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb
index ba3b94ce49c..d908195e6a5 100644
--- a/test/irb/test_context.rb
+++ b/test/irb/test_context.rb
@@ -448,6 +448,28 @@ module TestIRB
out)
end
+ def test_default_return_format
+ IRB.conf[:PROMPT][:MY_PROMPT] = {
+ :PROMPT_I => "%03n> ",
+ :PROMPT_N => "%03n> ",
+ :PROMPT_S => "%03n> ",
+ :PROMPT_C => "%03n> "
+ # without :RETURN
+ # :RETURN => "%s\n"
+ }
+ IRB.conf[:PROMPT_MODE] = :MY_PROMPT
+ input = TestInputMethod.new([
+ "3"
+ ])
+ irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
+ out, err = capture_output do
+ irb.eval_input
+ end
+ assert_empty err
+ assert_equal("3\n",
+ out)
+ end
+
def test_eval_input_with_exception
pend if RUBY_ENGINE == 'truffleruby'
verbose, $VERBOSE = $VERBOSE, nil
diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb
index e5417b18c3f..d8c7c79263b 100644
--- a/test/irb/test_init.rb
+++ b/test/irb/test_init.rb
@@ -62,6 +62,7 @@ module TestIRB
end
def test_recovery_sigint
+ pend "This test gets stuck on Solaris for unknown reason; contribution is welcome" if RUBY_PLATFORM =~ /solaris/
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
status = assert_in_out_err(bundle_exec + %w[-W0 -rirb -e binding.irb;loop{Process.kill("SIGINT",$$)} -- -f --], "exit\n", //, //)
Process.kill("SIGKILL", status.pid) if !status.exited? && !status.stopped? && !status.signaled?
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index e255720e253..47435d675ea 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -109,8 +109,8 @@ module TestIRB
Row.new(%q( ]), 4, 4),
Row.new(%q( ]), 2, 2),
Row.new(%q(]), 0, 0),
- Row.new(%q([<<FOO]), nil, 0),
- Row.new(%q(hello), nil, 0),
+ Row.new(%q([<<FOO]), 0, 0),
+ Row.new(%q(hello), 0, 0),
Row.new(%q(FOO), nil, 0),
]
@@ -399,6 +399,23 @@ module TestIRB
end
end
+ def test_corresponding_syntax_to_keyword_in
+ input_with_correct_indents = [
+ Row.new(%q(module E), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(class A), nil, 2, 1),
+ Row.new(%q( in), nil, 4, 1)
+ ]
+
+ lines = []
+ input_with_correct_indents.each do |row|
+ lines << row.content
+ assert_indenting(lines, row.current_line_spaces, false)
+ assert_indenting(lines, row.new_line_spaces, true)
+ assert_nesting_level(lines, row.nesting_level)
+ end
+ end
+
def test_bracket_corresponding_to_times
input_with_correct_indents = [
Row.new(%q(3.times { |i|), nil, 2, 1),
@@ -465,10 +482,10 @@ module TestIRB
def test_heredoc_with_indent
input_with_correct_indents = [
- Row.new(%q(<<~Q), nil, 0, 0),
- Row.new(%q({), nil, 0, 0),
- Row.new(%q( #), nil, 0, 0),
- Row.new(%q(}), nil, 0, 0),
+ Row.new(%q(<<~Q), 0, 0, 0),
+ Row.new(%q({), 0, 0, 0),
+ Row.new(%q( #), 2, 0, 0),
+ Row.new(%q(}), 0, 0, 0)
]
lines = []
@@ -503,8 +520,8 @@ module TestIRB
end
input_with_correct_indents = [
Row.new(%q(def foo), nil, 2, 1),
- Row.new(%q( <<~Q), nil, 2, 1),
- Row.new(%q( Qend), nil, 2, 1),
+ Row.new(%q( <<~Q), 2, 2, 1),
+ Row.new(%q( Qend), 2, 2, 1),
]
lines = []
@@ -581,8 +598,8 @@ module TestIRB
tokens = RubyLex.ripper_lex_without_warning('%wwww')
pos_to_index = {}
tokens.each_with_index { |t, i|
- assert_nil(pos_to_index[t[0]], "There is already another token in the position of #{t.inspect}.")
- pos_to_index[t[0]] = i
+ assert_nil(pos_to_index[t.pos], "There is already another token in the position of #{t.inspect}.")
+ pos_to_index[t.pos] = i
}
end
@@ -598,8 +615,8 @@ module TestIRB
EOC
pos_to_index = {}
tokens.each_with_index { |t, i|
- assert_nil(pos_to_index[t[0]], "There is already another token in the position of #{t.inspect}.")
- pos_to_index[t[0]] = i
+ assert_nil(pos_to_index[t.pos], "There is already another token in the position of #{t.inspect}.")
+ pos_to_index[t.pos] = i
}
end
end
diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb
index ac6df30c625..7ed98b11c1a 100644
--- a/test/irb/yamatanooroti/test_rendering.rb
+++ b/test/irb/yamatanooroti/test_rendering.rb
@@ -170,6 +170,52 @@ begin
EOC
end
+ def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_right
+ pend "Needs a dummy document to show doc"
+ write_irbrc <<~'LINES'
+ IRB.conf[:PROMPT][:MY_PROMPT] = {
+ :PROMPT_I => "%03n> ",
+ :PROMPT_N => "%03n> ",
+ :PROMPT_S => "%03n> ",
+ :PROMPT_C => "%03n> "
+ }
+ IRB.conf[:PROMPT_MODE] = :MY_PROMPT
+ puts 'start IRB'
+ LINES
+ start_terminal(4, 19, %W{ruby -I/home/aycabta/ruby/reline/lib -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
+ write("Str\C-i")
+ close
+ assert_screen(<<~EOC)
+ 001> String
+ StringPress A
+ StructString
+ of byte
+ EOC
+ end
+
+ def test_autocomplete_with_showdoc_in_gaps_on_narrow_screen_left
+ pend "Needs a dummy document to show doc"
+ write_irbrc <<~'LINES'
+ IRB.conf[:PROMPT][:MY_PROMPT] = {
+ :PROMPT_I => "%03n> ",
+ :PROMPT_N => "%03n> ",
+ :PROMPT_S => "%03n> ",
+ :PROMPT_C => "%03n> "
+ }
+ IRB.conf[:PROMPT_MODE] = :MY_PROMPT
+ puts 'start IRB'
+ LINES
+ start_terminal(4, 12, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
+ write("Str\C-i")
+ close
+ assert_screen(<<~EOC)
+ 001> String
+ PressString
+ StrinStruct
+ of by
+ EOC
+ end
+
private def write_irbrc(content)
File.open(@irbrc_file, 'w') do |f|
f.write content
diff --git a/test/lib/jit_support.rb b/test/lib/jit_support.rb
index 3bca63a549a..779aa8567e2 100644
--- a/test/lib/jit_support.rb
+++ b/test/lib/jit_support.rb
@@ -39,6 +39,7 @@ module JITSupport
'--disable-gems', "--jit-verbose=#{verbose}",
"--jit-min-calls=#{min_calls}", "--jit-max-cache=#{max_cache}",
]
+ args << '--disable-yjit'
args << '--jit-wait' if wait
args << '--jit-save-temps' if save_temps
args << '--jit-debug' if defined?(@jit_debug) && @jit_debug
diff --git a/test/mkmf/test_have_var.rb b/test/mkmf/test_have_var.rb
deleted file mode 100644
index 5367ec22484..00000000000
--- a/test/mkmf/test_have_var.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: false
-require_relative 'base'
-require 'tempfile'
-
-class TestMkmf
- class TestHaveVar < TestMkmf
- def test_have_var
- assert_equal(true, have_var("ruby_version"), MKMFLOG)
- assert_include($defs, '-DHAVE_RUBY_VERSION')
- end
-
- def test_not_have_var
- assert_equal(false, have_var("rb_vm_something_flag"), MKMFLOG)
- assert_not_include($defs, '-DHAVE_RB_VM_SOMETHING_FLAG')
- end
- end
-end
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index c8590219560..b5156078a44 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -1168,6 +1168,30 @@ class TestNetHTTPKeepAlive < Test::Unit::TestCase
}
end
+ def test_keep_alive_reset_on_new_connection
+ # Using WEBrick's debug log output on accepting connection:
+ #
+ # "[2021-04-29 20:36:46] DEBUG accept: 127.0.0.1:50674\n"
+ @log_tester = nil
+ @server.logger.level = WEBrick::BasicLog::DEBUG
+
+ start {|http|
+ res = http.get('/')
+ http.keep_alive_timeout = 1
+ assert_kind_of Net::HTTPResponse, res
+ assert_kind_of String, res.body
+ http.finish
+ assert_equal 1, @log.grep(/accept/i).size
+
+ sleep 1.5
+ http.start
+ res = http.get('/')
+ assert_kind_of Net::HTTPResponse, res
+ assert_kind_of String, res.body
+ assert_equal 2, @log.grep(/accept/i).size
+ }
+ end
+
class MockSocket
attr_reader :count
def initialize(success_after: nil)
diff --git a/test/net/http/test_http_request.rb b/test/net/http/test_http_request.rb
index 239b2d10095..7fd82b03539 100644
--- a/test/net/http/test_http_request.rb
+++ b/test/net/http/test_http_request.rb
@@ -46,8 +46,9 @@ class HTTPRequestTest < Test::Unit::TestCase
assert_not_predicate req, :response_body_permitted?
expected = {
- 'accept' => %w[*/*],
- 'user-agent' => %w[Ruby],
+ 'accept' => %w[*/*],
+ "accept-encoding" => %w[gzip;q=1.0,deflate;q=0.6,identity;q=0.3],
+ 'user-agent' => %w[Ruby],
}
assert_equal expected, req.to_hash
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
index 8ed04f59c9b..a1954d56a97 100644
--- a/test/objspace/test_objspace.rb
+++ b/test/objspace/test_objspace.rb
@@ -29,12 +29,12 @@ class TestObjSpace < Test::Unit::TestCase
end
def test_memsize_of_root_shared_string
- a = "hello" * 5
+ a = "a" * GC::INTERNAL_CONSTANTS[:RVARGC_MAX_ALLOCATE_SIZE]
b = a.dup
c = nil
ObjectSpace.each_object(String) {|x| break c = x if x == a and x.frozen?}
rv_size = GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
- assert_equal([rv_size, rv_size, 26 + rv_size], [a, b, c].map {|x| ObjectSpace.memsize_of(x)})
+ assert_equal([rv_size, rv_size, a.length + 1 + rv_size], [a, b, c].map {|x| ObjectSpace.memsize_of(x)})
end
def test_argf_memsize
diff --git a/test/openssl/test_asn1.rb b/test/openssl/test_asn1.rb
index 6bd847806bd..0fd79715857 100644
--- a/test/openssl/test_asn1.rb
+++ b/test/openssl/test_asn1.rb
@@ -170,7 +170,7 @@ class OpenSSL::TestASN1 < OpenSSL::TestCase
str = +"\000"; str[0] = 0b00000110.chr
assert_equal(str, extv.value)
- ext = extensions.value[0].value[2] # subjetKeyIdentifier
+ ext = extensions.value[0].value[2] # subjectKeyIdentifier
assert_equal(OpenSSL::ASN1::Sequence, ext.class)
assert_equal(2, ext.value.size)
assert_equal(OpenSSL::ASN1::ObjectId, ext.value[0].class)
diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb
index c36d6b89d8b..3f0622f94fd 100644
--- a/test/openssl/test_bn.rb
+++ b/test/openssl/test_bn.rb
@@ -248,6 +248,10 @@ class OpenSSL::TestBN < OpenSSL::TestCase
r5 = OpenSSL::BN.rand_range(256)
assert_include(0..255, r5)
}
+
+ # Aliases
+ assert_include(128..255, OpenSSL::BN.pseudo_rand(8))
+ assert_include(0..255, OpenSSL::BN.pseudo_rand_range(256))
end
begin
diff --git a/test/openssl/test_config.rb b/test/openssl/test_config.rb
index 769e65ceb5a..24a215a4867 100644
--- a/test/openssl/test_config.rb
+++ b/test/openssl/test_config.rb
@@ -61,14 +61,14 @@ foo\\bar::foo\\bar = baz
[default1 default2]\t\t # space is allowed in section name
fo =b ar # space allowed in value
[emptysection]
- [doller ]
+ [dollar ]
foo=bar
bar = $(foo)
baz = 123$(default::bar)456${foo}798
qux = ${baz}
quxx = $qux.$qux
__EOC__
- assert_equal(['default', 'default1 default2', 'doller', 'emptysection', 'foo', 'foo\\bar'], c.sections.sort)
+ assert_equal(['default', 'default1 default2', 'dollar', 'emptysection', 'foo', 'foo\\bar'], c.sections.sort)
assert_equal(['', 'a', 'bar', 'baz', 'd', 'dq', 'dq2', 'esc', 'foo\\bar', 'sq'], c['default'].keys.sort)
assert_equal('c', c['default'][''])
assert_equal('', c['default']['a'])
@@ -84,12 +84,12 @@ __EOC__
assert_equal('baz', c['foo\\bar']['foo\\bar'])
assert_equal('b ar', c['default1 default2']['fo'])
- # dolloer
- assert_equal('bar', c['doller']['foo'])
- assert_equal('bar', c['doller']['bar'])
- assert_equal('123baz456bar798', c['doller']['baz'])
- assert_equal('123baz456bar798', c['doller']['qux'])
- assert_equal('123baz456bar798.123baz456bar798', c['doller']['quxx'])
+ # dollar
+ assert_equal('bar', c['dollar']['foo'])
+ assert_equal('bar', c['dollar']['bar'])
+ assert_equal('123baz456bar798', c['dollar']['baz'])
+ assert_equal('123baz456bar798', c['dollar']['qux'])
+ assert_equal('123baz456bar798.123baz456bar798', c['dollar']['quxx'])
excn = assert_raise(OpenSSL::ConfigError) do
OpenSSL::Config.parse("foo = $bar")
diff --git a/test/openssl/test_digest.rb b/test/openssl/test_digest.rb
index 8d7046e8311..84c128c12ff 100644
--- a/test/openssl/test_digest.rb
+++ b/test/openssl/test_digest.rb
@@ -54,7 +54,7 @@ class OpenSSL::TestDigest < OpenSSL::TestCase
end
def test_digest_constants
- %w{MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512}.each do |name|
+ %w{MD5 SHA1 SHA224 SHA256 SHA384 SHA512}.each do |name|
assert_not_nil(OpenSSL::Digest.new(name))
klass = OpenSSL::Digest.const_get(name.tr('-', '_'))
assert_not_nil(klass.new)
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb
index 8316ec2a9cb..4249b4afb70 100644
--- a/test/openssl/test_pair.rb
+++ b/test/openssl/test_pair.rb
@@ -23,7 +23,6 @@ module OpenSSL::SSLPairM
sctx = OpenSSL::SSL::SSLContext.new
sctx.cert = @svr_cert
sctx.key = @svr_key
- sctx.tmp_dh_callback = proc { OpenSSL::TestUtils::Fixtures.pkey("dh-1") }
sctx.options |= OpenSSL::SSL::OP_NO_COMPRESSION
ssls = OpenSSL::SSL::SSLServer.new(tcps, sctx)
ns = ssls.accept
@@ -383,7 +382,6 @@ module OpenSSL::TestPairM
ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.cert = @svr_cert
ctx2.key = @svr_key
- ctx2.tmp_dh_callback = proc { OpenSSL::TestUtils::Fixtures.pkey("dh-1") }
sock1, sock2 = tcp_pair
@@ -431,7 +429,6 @@ module OpenSSL::TestPairM
ctx = OpenSSL::SSL::SSLContext.new
ctx.cert = @svr_cert
ctx.key = @svr_key
- ctx.tmp_dh_callback = proc { OpenSSL::TestUtils::Fixtures.pkey("dh-1") }
sock1, sock2 = tcp_pair
diff --git a/test/openssl/test_pkcs12.rb b/test/openssl/test_pkcs12.rb
index fdbe753b17e..ec676743bcb 100644
--- a/test/openssl/test_pkcs12.rb
+++ b/test/openssl/test_pkcs12.rb
@@ -5,6 +5,9 @@ if defined?(OpenSSL)
module OpenSSL
class TestPKCS12 < OpenSSL::TestCase
+ DEFAULT_PBE_PKEYS = "PBE-SHA1-3DES"
+ DEFAULT_PBE_CERTS = "PBE-SHA1-3DES"
+
def setup
super
ca = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=CA")
@@ -14,47 +17,41 @@ module OpenSSL
["subjectKeyIdentifier","hash",false],
["authorityKeyIdentifier","keyid:always",false],
]
- @cacert = issue_cert(ca, Fixtures.pkey("rsa2048"), 1, ca_exts, nil, nil)
+ ca_key = Fixtures.pkey("rsa-1")
+ @cacert = issue_cert(ca, ca_key, 1, ca_exts, nil, nil)
inter_ca = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=Intermediate CA")
- inter_ca_key = OpenSSL::PKey.read <<-_EOS_
------BEGIN RSA PRIVATE KEY-----
-MIICXAIBAAKBgQDp7hIG0SFMG/VWv1dBUWziAPrNmkMXJgTCAoB7jffzRtyyN04K
-oq/89HAszTMStZoMigQURfokzKsjpUp8OYCAEsBtt9d5zPndWMz/gHN73GrXk3LT
-ZsxEn7Xv5Da+Y9F/Hx2QZUHarV5cdZixq2NbzWGwrToogOQMh2pxN3Z/0wIDAQAB
-AoGBAJysUyx3olpsGzv3OMRJeahASbmsSKTXVLZvoIefxOINosBFpCIhZccAG6UV
-5c/xCvS89xBw8aD15uUfziw3AuT8QPEtHCgfSjeT7aWzBfYswEgOW4XPuWr7EeI9
-iNHGD6z+hCN/IQr7FiEBgTp6A+i/hffcSdR83fHWKyb4M7TRAkEA+y4BNd668HmC
-G5MPRx25n6LixuBxrNp1umfjEI6UZgEFVpYOg4agNuimN6NqM253kcTR94QNTUs5
-Kj3EhG1YWwJBAO5rUjiOyCNVX2WUQrOMYK/c1lU7fvrkdygXkvIGkhsPoNRzLPeA
-HGJszKtrKD8bNihWpWNIyqKRHfKVD7yXT+kCQGCAhVCIGTRoypcDghwljHqLnysf
-ci0h5ZdPcIqc7ODfxYhFsJ/Rql5ONgYsT5Ig/+lOQAkjf+TRYM4c2xKx2/8CQBvG
-jv6dy70qDgIUgqzONtlmHeYyFzn9cdBO5sShdVYHvRHjFSMEXsosqK9zvW2UqvuK
-FJx7d3f29gkzynCLJDkCQGQZlEZJC4vWmWJGRKJ24P6MyQn3VsPfErSKOg4lvyM3
-Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
------END RSA PRIVATE KEY-----
- _EOS_
- @inter_cacert = issue_cert(inter_ca, inter_ca_key, 2, ca_exts, @cacert, Fixtures.pkey("rsa2048"))
+ inter_ca_key = Fixtures.pkey("rsa-2")
+ @inter_cacert = issue_cert(inter_ca, inter_ca_key, 2, ca_exts, @cacert, ca_key)
exts = [
["keyUsage","digitalSignature",true],
["subjectKeyIdentifier","hash",false],
]
ee = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=Ruby PKCS12 Test Certificate")
- @mykey = Fixtures.pkey("rsa1024")
+ @mykey = Fixtures.pkey("rsa-3")
@mycert = issue_cert(ee, @mykey, 3, exts, @inter_cacert, inter_ca_key)
end
- def test_create
+ def test_create_single_key_single_cert
pkcs12 = OpenSSL::PKCS12.create(
"omg",
"hello",
@mykey,
- @mycert
+ @mycert,
+ nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
)
- assert_equal @mycert.to_der, pkcs12.certificate.to_der
+ assert_equal @mycert, pkcs12.certificate
assert_equal @mykey.to_der, pkcs12.key.to_der
assert_nil pkcs12.ca_certs
+
+ der = pkcs12.to_der
+ decoded = OpenSSL::PKCS12.new(der, "omg")
+ assert_equal @mykey.to_der, decoded.key.to_der
+ assert_equal @mycert, decoded.certificate
+ assert_equal [], Array(decoded.ca_certs)
end
def test_create_no_pass
@@ -62,14 +59,17 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
nil,
"hello",
@mykey,
- @mycert
+ @mycert,
+ nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
)
- assert_equal @mycert.to_der, pkcs12.certificate.to_der
+ assert_equal @mycert, pkcs12.certificate
assert_equal @mykey.to_der, pkcs12.key.to_der
assert_nil pkcs12.ca_certs
decoded = OpenSSL::PKCS12.new(pkcs12.to_der)
- assert_cert @mycert, decoded.certificate
+ assert_equal @mycert, decoded.certificate
end
def test_create_with_chain
@@ -80,7 +80,9 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
"hello",
@mykey,
@mycert,
- chain
+ chain,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
)
assert_equal chain, pkcs12.ca_certs
end
@@ -95,14 +97,16 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
"hello",
@mykey,
@mycert,
- chain
+ chain,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
)
decoded = OpenSSL::PKCS12.new(pkcs12.to_der, passwd)
assert_equal chain.size, decoded.ca_certs.size
- assert_include_cert @cacert, decoded.ca_certs
- assert_include_cert @inter_cacert, decoded.ca_certs
- assert_cert @mycert, decoded.certificate
+ assert_include decoded.ca_certs, @cacert
+ assert_include decoded.ca_certs, @inter_cacert
+ assert_equal @mycert, decoded.certificate
assert_equal @mykey.to_der, decoded.key.to_der
end
@@ -126,8 +130,8 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
@mykey,
@mycert,
[],
- nil,
- nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
2048
)
@@ -138,8 +142,8 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
@mykey,
@mycert,
[],
- nil,
- nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
"omg"
)
end
@@ -152,7 +156,8 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
@mykey,
@mycert,
[],
- nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
nil,
nil,
2048
@@ -165,148 +170,144 @@ Li8JsX5yIiuVYaBg/6ha3tOg4TCa5K/3r3tVliRZ2Es=
@mykey,
@mycert,
[],
- nil,
- nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
nil,
"omg"
)
end
end
- def test_new_with_one_key_and_one_cert
- # generated with:
- # openssl version #=> OpenSSL 1.0.2h 3 May 2016
- # openssl pkcs12 -in <@mycert> -inkey <RSA1024> -export -out <out>
- str = <<~EOF.unpack("m").first
-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
-vyl2WuMdEwQIMWFFphPkIUICAggA
- EOF
- p12 = OpenSSL::PKCS12.new(str, "abc123")
-
- assert_equal @mykey.to_der, p12.key.to_der
- assert_equal @mycert.subject.to_der, p12.certificate.subject.to_der
- assert_equal [], Array(p12.ca_certs)
- end
-
def test_new_with_no_keys
# generated with:
- # openssl pkcs12 -in <@mycert> -nokeys -export -out <out>
+ # openssl pkcs12 -certpbe PBE-SHA1-3DES -in <@mycert> -nokeys -export
str = <<~EOF.unpack("m").first
-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
+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
+AA==
EOF
p12 = OpenSSL::PKCS12.new(str, "abc123")
assert_equal nil, p12.key
assert_equal nil, p12.certificate
assert_equal 1, p12.ca_certs.size
- assert_equal @mycert.subject.to_der, p12.ca_certs[0].subject.to_der
+ assert_equal @mycert.subject, p12.ca_certs[0].subject
end
def test_new_with_no_certs
# generated with:
- # openssl pkcs12 -inkey <RSA1024> -nocerts -export -out <out>
+ # openssl pkcs12 -inkey fixtures/openssl/pkey/rsa-1.pem -nocerts -export
str = <<~EOF.unpack("m").first
-MIIDJwIBAzCCAu0GCSqGSIb3DQEHAaCCAt4EggLaMIIC1jCCAtIGCSqGSIb3DQEH
-AaCCAsMEggK/MIICuzCCArcGCyqGSIb3DQEMCgECoIICpjCCAqIwHAYKKoZIhvcN
-AQwBAzAOBAg6AaYnJs84SwICCAAEggKAQzZH+fWSpcQYD1J7PsGSune85A++fLCQ
-V7tacp2iv95GJkxwYmfTP176pJdgs00mceB9UJ/u9EX5nD0djdjjQjwo6sgKjY0q
-cpVhZw8CMxw7kBD2dhtui0zT8z5hy03LePxsjEKsGiSbeVeeGbSfw/I6AAYbv+Uh
-O/YPBGumeHj/D2WKnfsHJLQ9GAV3H6dv5VKYNxjciK7f/JEyZCuUQGIN64QFHDhJ
-7fzLqd/ul3FZzJZO6a+dwvcgux09SKVXDRSeFmRCEX4b486iWhJJVspCo9P2KNne
-ORrpybr3ZSwxyoICmjyo8gj0OSnEfdx9790Ej1takPqSA1wIdSdBLekbZqB0RBQg
-DEuPOsXNo3QFi8ji1vu0WBRJZZSNC2hr5NL6lNR+DKxG8yzDll2j4W4BBIp22mAE
-7QRX7kVxu17QJXQhOUac4Dd1qXmzebP8t6xkAxD9L7BWEN5OdiXWwSWGjVjMBneX
-nYObi/3UT/aVc5WHMHK2BhCI1bwH51E6yZh06d5m0TQpYGUTWDJdWGBSrp3A+8jN
-N2PMQkWBFrXP3smHoTEN4oZC4FWiPsIEyAkQsfKRhcV9lGKl2Xgq54ROTFLnwKoj
-Z3zJScnq9qmNzvVZSMmDLkjLyDq0pxRxGKBvgouKkWY7VFFIwwBIJM39iDJ5NbBY
-i1AQFTRsRSsZrNVPasCXrIq7bhMoJZb/YZOGBLNyJVqKUoYXhtwsajzSq54VlWft
-JxsPayEd4Vi6O9EU1ahnj6qFEZiKFzsicgK2J1Rb8cYagrp0XWjHW0SBn5GVUWCg
-GUokSFG/0JTdeYTo/sQuG4qNgJkOolRjpeI48Fciq5VUWLvVdKioXzAxMCEwCQYF
-Kw4DAhoFAAQUYAuwVtGD1TdgbFK4Yal2XBgwUR4ECEawsN3rNaa6AgIIAA==
+MIIJ7wIBAzCCCbUGCSqGSIb3DQEHAaCCCaYEggmiMIIJnjCCCZoGCSqGSIb3
+DQEHAaCCCYsEggmHMIIJgzCCCX8GCyqGSIb3DQEMCgECoIIJbjCCCWowHAYK
+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
+BC8fv38mue8LZVcbHQQIUNrWKEnskCoCAggA
EOF
p12 = OpenSSL::PKCS12.new(str, "abc123")
- assert_equal @mykey.to_der, p12.key.to_der
+ assert_equal Fixtures.pkey("rsa-1").to_der, p12.key.to_der
assert_equal nil, p12.certificate
assert_equal [], Array(p12.ca_certs)
end
def test_dup
- p12 = OpenSSL::PKCS12.create("pass", "name", @mykey, @mycert)
+ p12 = OpenSSL::PKCS12.create(
+ "pass",
+ "name",
+ @mykey,
+ @mycert,
+ nil,
+ DEFAULT_PBE_PKEYS,
+ DEFAULT_PBE_CERTS,
+ )
assert_equal p12.to_der, p12.dup.to_der
end
-
- private
- def assert_cert expected, actual
- [
- :subject,
- :issuer,
- :serial,
- :not_before,
- :not_after,
- ].each do |attribute|
- assert_equal expected.send(attribute), actual.send(attribute)
- end
- assert_equal expected.to_der, actual.to_der
- end
-
- def assert_include_cert cert, ary
- der = cert.to_der
- ary.each do |candidate|
- if candidate.to_der == der
- return true
- end
- end
- false
- end
end
end
diff --git a/test/openssl/test_pkey.rb b/test/openssl/test_pkey.rb
index 4a539d8c469..544340e3788 100644
--- a/test/openssl/test_pkey.rb
+++ b/test/openssl/test_pkey.rb
@@ -27,20 +27,16 @@ class OpenSSL::TestPKey < OpenSSL::PKeyTestCase
end
def test_s_generate_parameters
- # 512 is non-default; 1024 is used if 'dsa_paramgen_bits' is not specified
- # with OpenSSL 1.1.0.
- pkey = OpenSSL::PKey.generate_parameters("DSA", {
- "dsa_paramgen_bits" => 512,
- "dsa_paramgen_q_bits" => 256,
+ pkey = OpenSSL::PKey.generate_parameters("EC", {
+ "ec_paramgen_curve" => "secp384r1",
})
- assert_instance_of OpenSSL::PKey::DSA, pkey
- assert_equal 512, pkey.p.num_bits
- assert_equal 256, pkey.q.num_bits
- assert_equal nil, pkey.priv_key
+ assert_instance_of OpenSSL::PKey::EC, pkey
+ assert_equal "secp384r1", pkey.group.curve_name
+ assert_equal nil, pkey.private_key
# Invalid options are checked
assert_raise(OpenSSL::PKey::PKeyError) {
- OpenSSL::PKey.generate_parameters("DSA", "invalid" => "option")
+ OpenSSL::PKey.generate_parameters("EC", "invalid" => "option")
}
# Parameter generation callback is called
@@ -59,14 +55,13 @@ class OpenSSL::TestPKey < OpenSSL::PKeyTestCase
# DSA key pair cannot be generated without parameters
OpenSSL::PKey.generate_key("DSA")
}
- pkey_params = OpenSSL::PKey.generate_parameters("DSA", {
- "dsa_paramgen_bits" => 512,
- "dsa_paramgen_q_bits" => 256,
+ pkey_params = OpenSSL::PKey.generate_parameters("EC", {
+ "ec_paramgen_curve" => "secp384r1",
})
pkey = OpenSSL::PKey.generate_key(pkey_params)
- assert_instance_of OpenSSL::PKey::DSA, pkey
- assert_equal 512, pkey.p.num_bits
- assert_not_equal nil, pkey.priv_key
+ assert_instance_of OpenSSL::PKey::EC, pkey
+ assert_equal "secp384r1", pkey.group.curve_name
+ assert_not_equal nil, pkey.private_key
end
def test_hmac_sign_verify
diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb
index f80af8f8415..757704caf67 100644
--- a/test/openssl/test_pkey_dh.rb
+++ b/test/openssl/test_pkey_dh.rb
@@ -40,12 +40,14 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase
def test_DHparams
dh1024 = Fixtures.pkey("dh1024")
+ dh1024params = dh1024.public_key
+
asn1 = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Integer(dh1024.p),
OpenSSL::ASN1::Integer(dh1024.g)
])
key = OpenSSL::PKey::DH.new(asn1.to_der)
- assert_same_dh dup_public(dh1024), key
+ assert_same_dh dh1024params, key
pem = <<~EOF
-----BEGIN DH PARAMETERS-----
@@ -55,9 +57,9 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase
-----END DH PARAMETERS-----
EOF
key = OpenSSL::PKey::DH.new(pem)
- assert_same_dh dup_public(dh1024), key
+ assert_same_dh dh1024params, key
key = OpenSSL::PKey.read(pem)
- assert_same_dh dup_public(dh1024), key
+ assert_same_dh dh1024params, key
assert_equal asn1.to_der, dh1024.to_der
assert_equal pem, dh1024.export
diff --git a/test/openssl/test_pkey_dsa.rb b/test/openssl/test_pkey_dsa.rb
index 147e50176b2..0994607f21a 100644
--- a/test/openssl/test_pkey_dsa.rb
+++ b/test/openssl/test_pkey_dsa.rb
@@ -138,6 +138,8 @@ class OpenSSL::TestPKeyDSA < OpenSSL::PKeyTestCase
def test_PUBKEY
dsa512 = Fixtures.pkey("dsa512")
+ dsa512pub = OpenSSL::PKey::DSA.new(dsa512.public_to_der)
+
asn1 = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::ObjectId("DSA"),
@@ -153,7 +155,7 @@ class OpenSSL::TestPKeyDSA < OpenSSL::PKeyTestCase
])
key = OpenSSL::PKey::DSA.new(asn1.to_der)
assert_not_predicate key, :private?
- assert_same_dsa dup_public(dsa512), key
+ assert_same_dsa dsa512pub, key
pem = <<~EOF
-----BEGIN PUBLIC KEY-----
@@ -166,10 +168,15 @@ class OpenSSL::TestPKeyDSA < OpenSSL::PKeyTestCase
-----END PUBLIC KEY-----
EOF
key = OpenSSL::PKey::DSA.new(pem)
- assert_same_dsa dup_public(dsa512), key
+ assert_same_dsa dsa512pub, key
+
+ assert_equal asn1.to_der, key.to_der
+ assert_equal pem, key.export
- assert_equal asn1.to_der, dup_public(dsa512).to_der
- assert_equal pem, dup_public(dsa512).export
+ assert_equal asn1.to_der, dsa512.public_to_der
+ assert_equal asn1.to_der, key.public_to_der
+ assert_equal pem, dsa512.public_to_pem
+ assert_equal pem, key.public_to_pem
end
def test_read_DSAPublicKey_pem
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index 0a460bd5361..3f5958af50b 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative 'utils'
-if defined?(OpenSSL) && defined?(OpenSSL::PKey::EC)
+if defined?(OpenSSL)
class OpenSSL::TestEC < OpenSSL::PKeyTestCase
def test_ec_key
@@ -210,6 +210,8 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase
def test_PUBKEY
p256 = Fixtures.pkey("p256")
+ p256pub = OpenSSL::PKey::EC.new(p256.public_to_der)
+
asn1 = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::ObjectId("id-ecPublicKey"),
@@ -221,7 +223,7 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase
])
key = OpenSSL::PKey::EC.new(asn1.to_der)
assert_not_predicate key, :private?
- assert_same_ec dup_public(p256), key
+ assert_same_ec p256pub, key
pem = <<~EOF
-----BEGIN PUBLIC KEY-----
@@ -230,10 +232,15 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase
-----END PUBLIC KEY-----
EOF
key = OpenSSL::PKey::EC.new(pem)
- assert_same_ec dup_public(p256), key
+ assert_same_ec p256pub, key
+
+ assert_equal asn1.to_der, key.to_der
+ assert_equal pem, key.export
- assert_equal asn1.to_der, dup_public(p256).to_der
- assert_equal pem, dup_public(p256).export
+ assert_equal asn1.to_der, p256.public_to_der
+ assert_equal asn1.to_der, key.public_to_der
+ assert_equal pem, p256.public_to_pem
+ assert_equal pem, key.public_to_pem
end
def test_ec_group
diff --git a/test/openssl/test_pkey_rsa.rb b/test/openssl/test_pkey_rsa.rb
index 5e127f54075..dbe87ba4c1b 100644
--- a/test/openssl/test_pkey_rsa.rb
+++ b/test/openssl/test_pkey_rsa.rb
@@ -11,7 +11,7 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
key.set_factors(rsa.p, rsa.q)
assert_raise(OpenSSL::PKey::RSAError){ key.private_encrypt("foo") }
assert_raise(OpenSSL::PKey::RSAError){ key.private_decrypt("foo") }
- end
+ end if !openssl?(3, 0, 0) # Impossible state in OpenSSL 3.0
def test_private
# Generated by key size and public exponent
@@ -201,7 +201,7 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
def test_encrypt_decrypt
rsapriv = Fixtures.pkey("rsa-1")
- rsapub = dup_public(rsapriv)
+ rsapub = OpenSSL::PKey.read(rsapriv.public_to_der)
# Defaults to PKCS #1 v1.5
raw = "data"
@@ -216,7 +216,7 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
def test_encrypt_decrypt_legacy
rsapriv = Fixtures.pkey("rsa-1")
- rsapub = dup_public(rsapriv)
+ rsapub = OpenSSL::PKey.read(rsapriv.public_to_der)
# Defaults to PKCS #1 v1.5
raw = "data"
@@ -346,13 +346,15 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
def test_RSAPublicKey
rsa1024 = Fixtures.pkey("rsa1024")
+ rsa1024pub = OpenSSL::PKey::RSA.new(rsa1024.public_to_der)
+
asn1 = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Integer(rsa1024.n),
OpenSSL::ASN1::Integer(rsa1024.e)
])
key = OpenSSL::PKey::RSA.new(asn1.to_der)
assert_not_predicate key, :private?
- assert_same_rsa dup_public(rsa1024), key
+ assert_same_rsa rsa1024pub, key
pem = <<~EOF
-----BEGIN RSA PUBLIC KEY-----
@@ -362,11 +364,13 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
-----END RSA PUBLIC KEY-----
EOF
key = OpenSSL::PKey::RSA.new(pem)
- assert_same_rsa dup_public(rsa1024), key
+ assert_same_rsa rsa1024pub, key
end
def test_PUBKEY
rsa1024 = Fixtures.pkey("rsa1024")
+ rsa1024pub = OpenSSL::PKey::RSA.new(rsa1024.public_to_der)
+
asn1 = OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::Sequence([
OpenSSL::ASN1::ObjectId("rsaEncryption"),
@@ -381,7 +385,7 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
])
key = OpenSSL::PKey::RSA.new(asn1.to_der)
assert_not_predicate key, :private?
- assert_same_rsa dup_public(rsa1024), key
+ assert_same_rsa rsa1024pub, key
pem = <<~EOF
-----BEGIN PUBLIC KEY-----
@@ -392,10 +396,15 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
-----END PUBLIC KEY-----
EOF
key = OpenSSL::PKey::RSA.new(pem)
- assert_same_rsa dup_public(rsa1024), key
+ assert_same_rsa rsa1024pub, key
+
+ assert_equal asn1.to_der, key.to_der
+ assert_equal pem, key.export
- assert_equal asn1.to_der, dup_public(rsa1024).to_der
- assert_equal pem, dup_public(rsa1024).export
+ assert_equal asn1.to_der, rsa1024.public_to_der
+ assert_equal asn1.to_der, key.public_to_der
+ assert_equal pem, rsa1024.public_to_pem
+ assert_equal pem, key.public_to_pem
end
def test_pem_passwd
@@ -482,12 +491,6 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase
assert_same_rsa rsa1024, OpenSSL::PKey.read(pem, "abcdef")
end
- def test_public_encoding
- rsa1024 = Fixtures.pkey("rsa1024")
- assert_equal dup_public(rsa1024).to_der, rsa1024.public_to_der
- assert_equal dup_public(rsa1024).to_pem, rsa1024.public_to_pem
- end
-
def test_dup
key = Fixtures.pkey("rsa1024")
key2 = key.dup
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index 5dccac5facc..ef9958aee5d 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -4,6 +4,17 @@ require_relative "utils"
if defined?(OpenSSL)
class OpenSSL::TestSSL < OpenSSL::SSLTestCase
+ def test_bad_socket
+ bad_socket = Struct.new(:sync).new
+ assert_raise TypeError do
+ socket = OpenSSL::SSL::SSLSocket.new bad_socket
+ # if the socket is not a T_FILE, `connect` will segv because it tries
+ # to get the underlying file descriptor but the API it calls assumes
+ # the object type is T_FILE
+ socket.connect
+ end
+ end
+
def test_ctx_options
ctx = OpenSSL::SSL::SSLContext.new
@@ -124,9 +135,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_add_certificate_multiple_certs
- pend "EC is not supported" unless defined?(OpenSSL::PKey::EC)
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ca2_key = Fixtures.pkey("rsa-3")
ca2_exts = [
["basicConstraints", "CA:TRUE", true],
@@ -365,59 +373,20 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
}
end
- def test_read_nonblock_without_session
- EnvUtil.suppress_warning do
- start_server(start_immediately: false) { |port|
- sock = TCPSocket.new("127.0.0.1", port)
- ssl = OpenSSL::SSL::SSLSocket.new(sock)
- ssl.sync_close = true
-
- assert_equal :wait_readable, ssl.read_nonblock(100, exception: false)
- ssl.write("abc\n")
- IO.select [ssl]
- assert_equal('a', ssl.read_nonblock(1))
- assert_equal("bc\n", ssl.read_nonblock(100))
- assert_equal :wait_readable, ssl.read_nonblock(100, exception: false)
- ssl.close
- }
- end
- end
-
- def test_starttls
- server_proc = -> (ctx, ssl) {
- while line = ssl.gets
- if line =~ /^STARTTLS$/
- ssl.write("x")
- ssl.flush
- ssl.accept
- break
- end
- ssl.write(line)
- end
- readwrite_loop(ctx, ssl)
- }
-
- EnvUtil.suppress_warning do # read/write on not started session
- start_server(start_immediately: false,
- server_proc: server_proc) { |port|
- begin
- sock = TCPSocket.new("127.0.0.1", port)
- ssl = OpenSSL::SSL::SSLSocket.new(sock)
-
- ssl.puts "plaintext"
- assert_equal "plaintext\n", ssl.gets
+ def test_unstarted_session
+ start_server do |port|
+ sock = TCPSocket.new("127.0.0.1", port)
+ ssl = OpenSSL::SSL::SSLSocket.new(sock)
- ssl.puts("STARTTLS")
- ssl.read(1)
- ssl.connect
+ assert_raise(OpenSSL::SSL::SSLError) { ssl.syswrite("data") }
+ assert_raise(OpenSSL::SSL::SSLError) { ssl.sysread(1) }
- ssl.puts "over-tls"
- assert_equal "over-tls\n", ssl.gets
- ensure
- ssl&.close
- sock&.close
- end
- }
+ ssl.connect
+ ssl.puts "abc"
+ assert_equal "abc\n", ssl.gets
+ ensure
+ ssl&.close
+ sock&.close
end
end
@@ -526,6 +495,7 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
}) { |port|
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ ctx.max_version = :TLS1_2 if libressl?(3, 2, 0) && !libressl?(3, 3, 0)
server_connect(port, ctx) { |ssl|
ssl.puts "abc"; ssl.gets
@@ -553,11 +523,10 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_post_connect_check_with_anon_ciphers
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ctx_proc = -> ctx {
ctx.ssl_version = :TLSv1_2
ctx.ciphers = "aNULL"
+ ctx.tmp_dh = Fixtures.pkey("dh-1")
ctx.security_level = 0
}
@@ -596,8 +565,7 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
exts = [
["keyUsage","keyEncipherment,digitalSignature",true],
- ["subjectAltName","DNS:localhost.localdomain",false],
- ["subjectAltName","IP:127.0.0.1",false],
+ ["subjectAltName","DNS:localhost.localdomain,IP:127.0.0.1",false],
]
@svr_cert = issue_cert(@svr, @svr_key, 4, exts, @ca_cert, @ca_key)
start_server { |port|
@@ -832,7 +800,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
def test_tlsext_hostname
fooctx = OpenSSL::SSL::SSLContext.new
- fooctx.tmp_dh_callback = proc { Fixtures.pkey("dh-1") }
fooctx.cert = @cli_cert
fooctx.key = @cli_key
@@ -884,7 +851,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
ctx2 = OpenSSL::SSL::SSLContext.new
ctx2.cert = @svr_cert
ctx2.key = @svr_key
- ctx2.tmp_dh_callback = proc { Fixtures.pkey("dh-1") }
ctx2.servername_cb = lambda { |args| Object.new }
sock1, sock2 = socketpair
@@ -1028,14 +994,17 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
start_server(ignore_listener_error: true) { |port|
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params
- assert_raise_with_message(OpenSSL::SSL::SSLError, /self signed/) {
+ # OpenSSL <= 1.1.0: "self signed certificate in certificate chain"
+ # OpenSSL >= 3.0.0: "self-signed certificate in certificate chain"
+ assert_raise_with_message(OpenSSL::SSL::SSLError, /self.signed/) {
server_connect(port, ctx)
}
}
ctx_proc = proc { |ctx|
+ now = Time.now
ctx.cert = issue_cert(@svr, @svr_key, 30, [], @ca_cert, @ca_key,
- not_before: Time.now-100, not_after: Time.now-10)
+ not_before: now - 7200, not_after: now - 3600)
}
start_server(ignore_listener_error: true, ctx_proc: ctx_proc) { |port|
store = OpenSSL::X509::Store.new
@@ -1331,7 +1300,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
ctx1 = OpenSSL::SSL::SSLContext.new
ctx1.cert = @svr_cert
ctx1.key = @svr_key
- ctx1.tmp_dh_callback = proc { Fixtures.pkey("dh-1") }
ctx1.alpn_select_cb = -> (protocols) { nil }
ssl1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1)
@@ -1354,7 +1322,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_npn_protocol_selection_ary
- pend "TLS 1.2 is not supported" unless tls12_supported?
pend "NPN is not supported" unless \
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
@@ -1375,7 +1342,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_npn_protocol_selection_enum
- pend "TLS 1.2 is not supported" unless tls12_supported?
pend "NPN is not supported" unless \
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
@@ -1400,7 +1366,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_npn_protocol_selection_cancel
- pend "TLS 1.2 is not supported" unless tls12_supported?
pend "NPN is not supported" unless \
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
@@ -1414,7 +1379,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_npn_advertised_protocol_too_long
- pend "TLS 1.2 is not supported" unless tls12_supported?
pend "NPN is not supported" unless \
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
@@ -1428,7 +1392,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_npn_selected_protocol_too_long
- pend "TLS 1.2 is not supported" unless tls12_supported?
pend "NPN is not supported" unless \
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
pend "LibreSSL 2.6 has broken NPN functions" if libressl?(2, 6, 1)
@@ -1469,56 +1432,51 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_get_ephemeral_key
- if tls12_supported?
- # kRSA
- ctx_proc1 = proc { |ctx|
- ctx.ssl_version = :TLSv1_2
- ctx.ciphers = "kRSA"
- }
- start_server(ctx_proc: ctx_proc1, ignore_listener_error: true) do |port|
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.ssl_version = :TLSv1_2
- ctx.ciphers = "kRSA"
- begin
- server_connect(port, ctx) { |ssl| assert_nil ssl.tmp_key }
- rescue OpenSSL::SSL::SSLError
- # kRSA seems disabled
- raise unless $!.message =~ /no cipher/
- end
+ # kRSA
+ ctx_proc1 = proc { |ctx|
+ ctx.ssl_version = :TLSv1_2
+ ctx.ciphers = "kRSA"
+ }
+ start_server(ctx_proc: ctx_proc1, ignore_listener_error: true) do |port|
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.ssl_version = :TLSv1_2
+ ctx.ciphers = "kRSA"
+ begin
+ server_connect(port, ctx) { |ssl| assert_nil ssl.tmp_key }
+ rescue OpenSSL::SSL::SSLError
+ # kRSA seems disabled
+ raise unless $!.message =~ /no cipher/
end
end
- if defined?(OpenSSL::PKey::DH) && tls12_supported?
- # DHE
- # TODO: How to test this with TLS 1.3?
- ctx_proc2 = proc { |ctx|
- ctx.ssl_version = :TLSv1_2
- ctx.ciphers = "EDH"
+ # DHE
+ # TODO: How to test this with TLS 1.3?
+ ctx_proc2 = proc { |ctx|
+ ctx.ssl_version = :TLSv1_2
+ ctx.ciphers = "EDH"
+ ctx.tmp_dh = Fixtures.pkey("dh-1")
+ }
+ start_server(ctx_proc: ctx_proc2) do |port|
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.ssl_version = :TLSv1_2
+ ctx.ciphers = "EDH"
+ server_connect(port, ctx) { |ssl|
+ assert_instance_of OpenSSL::PKey::DH, ssl.tmp_key
}
- start_server(ctx_proc: ctx_proc2) do |port|
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.ssl_version = :TLSv1_2
- ctx.ciphers = "EDH"
- server_connect(port, ctx) { |ssl|
- assert_instance_of OpenSSL::PKey::DH, ssl.tmp_key
- }
- end
end
- if defined?(OpenSSL::PKey::EC)
- # ECDHE
- ctx_proc3 = proc { |ctx|
- ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
- ctx.ecdh_curves = "P-256"
+ # ECDHE
+ ctx_proc3 = proc { |ctx|
+ ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
+ ctx.ecdh_curves = "P-256"
+ }
+ start_server(ctx_proc: ctx_proc3) do |port|
+ ctx = OpenSSL::SSL::SSLContext.new
+ ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
+ server_connect(port, ctx) { |ssl|
+ assert_instance_of OpenSSL::PKey::EC, ssl.tmp_key
+ ssl.puts "abc"; assert_equal "abc\n", ssl.gets
}
- start_server(ctx_proc: ctx_proc3) do |port|
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
- server_connect(port, ctx) { |ssl|
- assert_instance_of OpenSSL::PKey::EC, ssl.tmp_key
- ssl.puts "abc"; assert_equal "abc\n", ssl.gets
- }
- end
end
end
@@ -1583,13 +1541,11 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
end
- def test_dh_callback
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
+ def test_tmp_dh_callback
dh = Fixtures.pkey("dh-1")
called = false
ctx_proc = -> ctx {
- ctx.ssl_version = :TLSv1_2
+ ctx.max_version = :TLS1_2
ctx.ciphers = "DH:!NULL"
ctx.tmp_dh_callback = ->(*args) {
called = true
@@ -1605,10 +1561,8 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_connect_works_when_setting_dh_callback_to_nil
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ctx_proc = -> ctx {
- ctx.ssl_version = :TLSv1_2
+ ctx.max_version = :TLS1_2
ctx.ciphers = "DH:!NULL" # use DH
ctx.tmp_dh_callback = nil
}
@@ -1621,9 +1575,21 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
end
- def test_ecdh_curves_tls12
- pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
+ def test_tmp_dh
+ dh = Fixtures.pkey("dh-1")
+ ctx_proc = -> ctx {
+ ctx.max_version = :TLS1_2
+ ctx.ciphers = "DH:!NULL" # use DH
+ ctx.tmp_dh = dh
+ }
+ start_server(ctx_proc: ctx_proc) do |port|
+ server_connect(port) { |ssl|
+ assert_equal dh.to_der, ssl.tmp_key.to_der
+ }
+ end
+ end
+ def test_ecdh_curves_tls12
ctx_proc = -> ctx {
# Enable both ECDHE (~ TLS 1.2) cipher suites and TLS 1.3
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
@@ -1659,7 +1625,6 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
end
def test_ecdh_curves_tls13
- pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
pend "TLS 1.3 not supported" unless tls13_supported?
ctx_proc = -> ctx {
diff --git a/test/openssl/test_ssl_session.rb b/test/openssl/test_ssl_session.rb
index a98efdae2a5..b72b10d3b5f 100644
--- a/test/openssl/test_ssl_session.rb
+++ b/test/openssl/test_ssl_session.rb
@@ -5,8 +5,6 @@ if defined?(OpenSSL)
class OpenSSL::TestSSLSession < OpenSSL::SSLTestCase
def test_session
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ctx_proc = proc { |ctx| ctx.ssl_version = :TLSv1_2 }
start_server(ctx_proc: ctx_proc) do |port|
server_connect_with_session(port, nil, nil) { |ssl|
@@ -144,8 +142,6 @@ __EOS__
end
def test_server_session_cache
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ctx_proc = Proc.new do |ctx|
ctx.ssl_version = :TLSv1_2
ctx.options |= OpenSSL::SSL::OP_NO_TICKET
@@ -224,8 +220,6 @@ __EOS__
TEST_SESSION_REMOVE_CB = ENV["OSSL_TEST_ALL"] == "1"
def test_ctx_client_session_cb
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
ctx_proc = proc { |ctx| ctx.ssl_version = :TLSv1_2 }
start_server(ctx_proc: ctx_proc) do |port|
called = {}
@@ -257,8 +251,6 @@ __EOS__
end
def test_ctx_server_session_cb
- pend "TLS 1.2 is not supported" unless tls12_supported?
-
connections = nil
called = {}
cctx = OpenSSL::SSL::SSLContext.new
diff --git a/test/openssl/test_ts.rb b/test/openssl/test_ts.rb
index 8e31a7d28d2..7cb1a1fe8eb 100644
--- a/test/openssl/test_ts.rb
+++ b/test/openssl/test_ts.rb
@@ -181,6 +181,12 @@ _end_of_pem_
assert_equal(42, qer2.nonce)
end
+ def test_request_invalid_asn1
+ assert_raise(OpenSSL::Timestamp::TimestampError) do
+ OpenSSL::Timestamp::Request.new("*" * 44)
+ end
+ end
+
def test_response_constants
assert_equal(0, OpenSSL::Timestamp::Response::GRANTED)
assert_equal(1, OpenSSL::Timestamp::Response::GRANTED_WITH_MODS)
@@ -338,6 +344,12 @@ _end_of_pem_
end
end
+ def test_response_invalid_asn1
+ assert_raise(OpenSSL::Timestamp::TimestampError) do
+ OpenSSL::Timestamp::Response.new("*" * 44)
+ end
+ end
+
def test_no_cert_requested
req = OpenSSL::Timestamp::Request.new
req.algorithm = "SHA1"
@@ -590,6 +602,12 @@ _end_of_pem_
assert_equal(123, info.nonce)
end
+ def test_token_info_invalid_asn1
+ assert_raise(OpenSSL::Timestamp::TimestampError) do
+ OpenSSL::Timestamp::TokenInfo.new("*" * 44)
+ end
+ end
+
private
def assert_cert expected, actual
diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb
index ab5fab4ba37..4ebcb9837bc 100644
--- a/test/openssl/utils.rb
+++ b/test/openssl/utils.rb
@@ -189,13 +189,6 @@ class OpenSSL::SSLTestCase < OpenSSL::TestCase
@server = nil
end
- def tls12_supported?
- ctx = OpenSSL::SSL::SSLContext.new
- ctx.min_version = ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
- true
- rescue
- end
-
def tls13_supported?
return false unless defined?(OpenSSL::SSL::TLS1_3_VERSION)
ctx = OpenSSL::SSL::SSLContext.new
@@ -222,7 +215,6 @@ class OpenSSL::SSLTestCase < OpenSSL::TestCase
ctx.cert_store = store
ctx.cert = @svr_cert
ctx.key = @svr_key
- ctx.tmp_dh_callback = proc { Fixtures.pkey("dh-1") }
ctx.verify_mode = verify_mode
ctx_proc.call(ctx) if ctx_proc
@@ -236,9 +228,7 @@ class OpenSSL::SSLTestCase < OpenSSL::TestCase
threads = []
begin
server_thread = Thread.new do
- if Thread.method_defined?(:report_on_exception=) # Ruby >= 2.4
- Thread.current.report_on_exception = false
- end
+ Thread.current.report_on_exception = false
begin
loop do
@@ -254,9 +244,7 @@ class OpenSSL::SSLTestCase < OpenSSL::TestCase
end
th = Thread.new do
- if Thread.method_defined?(:report_on_exception=)
- Thread.current.report_on_exception = false
- end
+ Thread.current.report_on_exception = false
begin
server_proc.call(ctx, ssl)
@@ -273,9 +261,7 @@ class OpenSSL::SSLTestCase < OpenSSL::TestCase
end
client_thread = Thread.new do
- if Thread.method_defined?(:report_on_exception=)
- Thread.current.report_on_exception = false
- end
+ Thread.current.report_on_exception = false
begin
block.call(port)
@@ -312,32 +298,6 @@ class OpenSSL::PKeyTestCase < OpenSSL::TestCase
assert_equal base.send(comp), test.send(comp)
}
end
-
- def dup_public(key)
- case key
- when OpenSSL::PKey::RSA
- rsa = OpenSSL::PKey::RSA.new
- rsa.set_key(key.n, key.e, nil)
- rsa
- when OpenSSL::PKey::DSA
- dsa = OpenSSL::PKey::DSA.new
- dsa.set_pqg(key.p, key.q, key.g)
- dsa.set_key(key.pub_key, nil)
- dsa
- when OpenSSL::PKey::DH
- dh = OpenSSL::PKey::DH.new
- dh.set_pqg(key.p, nil, key.g)
- dh
- else
- if defined?(OpenSSL::PKey::EC) && OpenSSL::PKey::EC === key
- ec = OpenSSL::PKey::EC.new(key.group)
- ec.public_key = key.public_key
- ec
- else
- raise "unknown key type"
- end
- end
- end
end
module OpenSSL::Certs
diff --git a/test/optparse/test_did_you_mean.rb b/test/optparse/test_did_you_mean.rb
index 763062586cc..aa866f40721 100644
--- a/test/optparse/test_did_you_mean.rb
+++ b/test/optparse/test_did_you_mean.rb
@@ -36,15 +36,7 @@ class TestOptionParser::DidYouMean < TestOptionParser
end
end
- def test_verbose
- require 'did_you_mean/formatters/verbose_formatter'
- ::DidYouMean.formatter = ::DidYouMean::VerboseFormatter.new
- assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\n\s+Did you mean\?\s+bar\s+baz\s*\Z/) do
- @opt.permute!(%w"--baa")
- end
- end
-
- def test_ambiguos
+ def test_ambiguous
assert_raise_with_message(OptionParser::AmbiguousOption, /ambiguous option: --ba\nDid you mean\?\s+bar\s+baz\Z/) do
@opt.permute!(%w"--ba")
end
diff --git a/test/ostruct/test_ostruct.rb b/test/ostruct/test_ostruct.rb
index 1fd7d878114..4ec4d43084e 100644
--- a/test/ostruct/test_ostruct.rb
+++ b/test/ostruct/test_ostruct.rb
@@ -368,6 +368,18 @@ class TC_OpenStruct < Test::Unit::TestCase
RUBY
end if defined?(Ractor)
+ def test_access_methods_from_different_ractor
+ assert_ractor(<<~RUBY, require: 'ostruct')
+ os = OpenStruct.new
+ os.value = 100
+ r = Ractor.new(os) do |x|
+ v = x.value
+ Ractor.yield v
+ end
+ assert 100 == r.take
+ RUBY
+ end if defined?(Ractor)
+
def test_legacy_yaml
s = "--- !ruby/object:OpenStruct\ntable:\n :foo: 42\n"
o = YAML.safe_load(s, permitted_classes: [Symbol, OpenStruct])
diff --git a/test/rdoc/test_rdoc_any_method.rb b/test/rdoc/test_rdoc_any_method.rb
index 615789dfb35..caff86b0595 100644
--- a/test/rdoc/test_rdoc_any_method.rb
+++ b/test/rdoc/test_rdoc_any_method.rb
@@ -72,6 +72,54 @@ method(a, b) { |c, d| ... }
assert_nil m1.is_alias_for, 'missing alias'
end
+ def test_call_seq_handles_aliases
+ # see 0ead786
+ @store.path = Dir.tmpdir
+ top_level = @store.add_file 'file.rb'
+ cm = top_level.add_class RDoc::ClassModule, 'Klass'
+
+ method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
+ method_with_call_seq.call_seq = <<~SEQ
+ method_with_call_seq(a)
+ method_with_call_seq(a, b)
+ alias_to_method(a)
+ alias_to_method(a, b)
+ SEQ
+ cm.add_method(method_with_call_seq)
+
+ alias_to_method = method_with_call_seq.add_alias(
+ RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
+ cm
+ )
+
+ assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
+ method_with_call_seq.call_seq)
+ assert_equal("alias_to_method(a)\nalias_to_method(a, b)",
+ alias_to_method.call_seq)
+ end
+
+ def test_call_seq_returns_nil_if_alias_is_missing_from_call_seq
+ @store.path = Dir.tmpdir
+ top_level = @store.add_file 'file.rb'
+ cm = top_level.add_class RDoc::ClassModule, 'Klass'
+
+ method_with_call_seq = RDoc::AnyMethod.new(nil, "method_with_call_seq")
+ method_with_call_seq.call_seq = <<~SEQ
+ method_with_call_seq(a)
+ method_with_call_seq(a, b)
+ SEQ
+ cm.add_method(method_with_call_seq)
+
+ alias_to_method = method_with_call_seq.add_alias(
+ RDoc::Alias.new(nil, "method_with_call_seq", "alias_to_method", "comment"),
+ cm
+ )
+
+ assert_equal("method_with_call_seq(a)\nmethod_with_call_seq(a, b)",
+ method_with_call_seq.call_seq)
+ assert_nil(alias_to_method.call_seq)
+ end
+
def test_markup_code
tokens = [
{ :line_no => 0, :char_no => 0, :kind => :on_const, :text => 'CONSTANT' },
diff --git a/test/rdoc/test_rdoc_class_module.rb b/test/rdoc/test_rdoc_class_module.rb
index 4dcc5d15ab1..ad185671cfd 100644
--- a/test/rdoc/test_rdoc_class_module.rb
+++ b/test/rdoc/test_rdoc_class_module.rb
@@ -89,7 +89,7 @@ class TestRDocClassModule < XrefTestCase
assert_equal 'comment', cm.comment.text
end
- def test_docuent_self_or_methods
+ def test_document_self_or_methods
assert @c1.document_self_or_methods
@c1.document_self = false
@@ -238,7 +238,7 @@ class TestRDocClassModule < XrefTestCase
assert_equal tl, loaded.method_list.first.file
end
- def test_marshal_dump_visibilty
+ def test_marshal_dump_visibility
@store.path = Dir.tmpdir
tl = @store.add_file 'file.rb'
diff --git a/test/rdoc/test_rdoc_cross_reference.rb b/test/rdoc/test_rdoc_cross_reference.rb
index 183de0930d3..94ddc1e1e47 100644
--- a/test/rdoc/test_rdoc_cross_reference.rb
+++ b/test/rdoc/test_rdoc_cross_reference.rb
@@ -20,7 +20,7 @@ class TestRDocCrossReference < XrefTestCase
def test_METHOD_REGEXP_STR
re = /#{RDoc::CrossReference::METHOD_REGEXP_STR}/
- %w'=== [] []= << >>'.each do |x|
+ %w'== === [] []= << >>'.each do |x|
re =~ x
assert_equal x, $&
end
diff --git a/test/rdoc/test_rdoc_parser_c.rb b/test/rdoc/test_rdoc_parser_c.rb
index 6601d28f606..8f51f32f261 100644
--- a/test/rdoc/test_rdoc_parser_c.rb
+++ b/test/rdoc/test_rdoc_parser_c.rb
@@ -1600,6 +1600,39 @@ Init_IO(void) {
assert_equal "Method Comment! ", read_method.comment.text
assert_equal "rb_io_s_read", read_method.c_function
assert read_method.singleton
+ assert_nil read_method.section.title
+ end
+
+ def test_define_method_with_category
+ content = <<-EOF
+/* :category: Awesome Methods
+ Method Comment!
+ */
+static VALUE
+rb_io_s_read(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
+{
+}
+
+void
+Init_IO(void) {
+ /*
+ * a comment for class Foo on rb_define_class
+ */
+ VALUE rb_cIO = rb_define_class("IO", rb_cObject);
+ rb_define_singleton_method(rb_cIO, "read", rb_io_s_read, -1);
+}
+ EOF
+
+ klass = util_get_class content, 'rb_cIO'
+ read_method = klass.method_list.first
+ assert_equal "read", read_method.name
+ assert_equal "Method Comment!", read_method.comment.text.strip
+ assert_equal "rb_io_s_read", read_method.c_function
+ assert read_method.singleton
+ assert_equal "Awesome Methods", read_method.section.title
end
def test_define_method_dynamically
@@ -1930,6 +1963,39 @@ void d(void) {
@store.all_classes_and_modules.map { |m| m.full_name }.sort
end
+ def test_markup_format_default
+ content = <<-EOF
+void Init_Blah(void) {
+ cBlah = rb_define_class("Blah", rb_cObject);
+
+ /*
+ * This should be interpreted in the default format.
+ */
+ rb_attr(cBlah, rb_intern("default_format"), 1, 1, Qfalse);
+}
+ EOF
+
+ klass = util_get_class content, 'cBlah'
+ assert_equal("rdoc", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
+ end
+
+ def test_markup_format_override
+ content = <<-EOF
+void Init_Blah(void) {
+ cBlah = rb_define_class("Blah", rb_cObject);
+
+ /*
+ * This should be interpreted in the default format.
+ */
+ rb_attr(cBlah, rb_intern("default_format"), 1, 1, Qfalse);
+}
+ EOF
+
+ @options.markup = "markdown"
+ klass = util_get_class content, 'cBlah'
+ assert_equal("markdown", klass.attributes.find {|a| a.name == "default_format"}.comment.format)
+ end
+
def util_get_class content, name = nil
@parser = util_parser content
@parser.scan
diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb
index a0438aa1fdf..f59e9ee9002 100644
--- a/test/readline/test_readline.rb
+++ b/test/readline/test_readline.rb
@@ -7,6 +7,7 @@ require "open3"
module BasetestReadline
INPUTRC = "INPUTRC"
+ TERM = "TERM"
SAVED_ENV = %w[COLUMNS LINES]
TIMEOUT = 8
@@ -14,10 +15,12 @@ module BasetestReadline
def setup
@saved_env = ENV.values_at(*SAVED_ENV)
@inputrc, ENV[INPUTRC] = ENV[INPUTRC], IO::NULL
+ @term, ENV[TERM] = ENV[TERM], "vt100"
end
def teardown
ENV[INPUTRC] = @inputrc
+ ENV[TERM] = @term
Readline.instance_variable_set("@completion_proc", nil)
begin
Readline.delete_text
@@ -485,6 +488,12 @@ module BasetestReadline
omit "Skip Readline 7.0" if Readline::VERSION == "7.0"
omit unless respond_to?(:assert_ruby_status)
omit if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ # On 32-bit machine, readline library (or libtinfo) seems to cause SEGV internally even with Readline 8.0
+ # GDB Backtrace: https://gist.github.com/mame/d12b9de3bbc3f16d440c1927398d176a
+ # Maybe the same issue: https://github.com/facebookresearch/nle/issues/120
+ omit if /i[3-6]86-linux/ =~ RUBY_PLATFORM
+
code = <<-"end;"
$stdout.sync = true
require 'readline'
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index 6a6cbdc59fd..8053225d244 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -2285,6 +2285,27 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_line(' 12345')
end
+ def test_ignore_NUL_by_ed_quoted_insert
+ input_keys(%Q{"\C-v\C-@"}, false)
+ assert_byte_pointer_size('""')
+ assert_cursor(2)
+ assert_cursor_max(2)
+ end
+
+ def test_ed_argument_digit_by_meta_num
+ input_keys('abcdef')
+ assert_byte_pointer_size('abcdef')
+ assert_cursor(6)
+ assert_cursor_max(6)
+ assert_line('abcdef')
+ input_keys("\M-2", false)
+ input_keys("\C-h", false)
+ assert_byte_pointer_size('abcd')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('abcd')
+ end
+
def test_input_unknown_char
input_keys('͸') # U+0378 (unassigned)
assert_line('͸')
diff --git a/test/reline/test_reline.rb b/test/reline/test_reline.rb
index 161b329740f..dd049ac1270 100644
--- a/test/reline/test_reline.rb
+++ b/test/reline/test_reline.rb
@@ -1,5 +1,6 @@
require_relative 'helper'
-require "reline"
+require 'reline'
+require 'stringio'
class Reline::Test < Reline::TestCase
class DummyCallbackObject
@@ -246,29 +247,57 @@ class Reline::Test < Reline::TestCase
end
def test_insert_text
- # TODO
- end
-
- def test_line_buffer
- # TODO
- end
-
- def test_point
- # TODO
- end
-
- def test_input=
- # TODO
+ assert_equal('', Reline.line_buffer)
+ assert_equal(0, Reline.point)
+ Reline.insert_text('abc')
+ assert_equal('abc', Reline.line_buffer)
+ assert_equal(3, Reline.point)
+ end
+
+ def test_delete_text
+ assert_equal('', Reline.line_buffer)
+ assert_equal(0, Reline.point)
+ Reline.insert_text('abc')
+ assert_equal('abc', Reline.line_buffer)
+ assert_equal(3, Reline.point)
+ Reline.delete_text()
+ assert_equal('', Reline.line_buffer)
+ assert_equal(0, Reline.point)
+ Reline.insert_text('abc')
+ Reline.delete_text(1)
+ assert_equal('a', Reline.line_buffer)
+ assert_equal(1, Reline.point)
+ Reline.insert_text('defghi')
+ Reline.delete_text(2, 2)
+ assert_equal('adghi', Reline.line_buffer)
+ assert_equal(5, Reline.point)
+ end
+
+ def test_set_input_and_output
assert_raise(TypeError) do
Reline.input = "This is not a file."
end
- end
-
- def test_output=
- # TODO
assert_raise(TypeError) do
Reline.output = "This is not a file."
end
+
+ input, to_write = IO.pipe
+ to_read, output = IO.pipe
+ unless Reline.__send__(:input=, input)
+ omit "Setting to input is not effective on #{Reline::IOGate}"
+ end
+ Reline.output = output
+
+ to_write.write "a\n"
+ result = Reline.readline
+ to_write.close
+ read_text = to_read.read_nonblock(100)
+ assert_equal('a', result)
+ refute(read_text.empty?)
+ ensure
+ input&.close
+ output&.close
+ to_read&.close
end
def test_vi_editing_mode
@@ -281,10 +310,6 @@ class Reline::Test < Reline::TestCase
assert_equal(Reline::KeyActor::Emacs, Reline.send(:core).config.editing_mode.class)
end
- def test_editing_mode
- # TODO
- end
-
def test_readmultiline
# readmultiline is module function
assert_include(Reline.methods, :readmultiline)
diff --git a/test/reline/test_reline_key.rb b/test/reline/test_reline_key.rb
new file mode 100644
index 00000000000..fb700a6f2eb
--- /dev/null
+++ b/test/reline/test_reline_key.rb
@@ -0,0 +1,53 @@
+require_relative 'helper'
+require "reline"
+
+class Reline::TestKey < Reline::TestCase
+ def setup
+ end
+
+ def teardown
+ Reline.test_reset
+ end
+
+ def test_match_key
+ assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 2, false)))
+ assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(nil, 2, false)))
+ assert(Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 2, nil)))
+
+ assert(Reline::Key.new(nil, 2, false).match?(Reline::Key.new(nil, 2, false)))
+ assert(Reline::Key.new(1, nil, false).match?(Reline::Key.new(1, nil, false)))
+ assert(Reline::Key.new(1, 2, nil).match?(Reline::Key.new(1, 2, nil)))
+
+ assert(Reline::Key.new(nil, 2, false).match?(Reline::Key.new(nil, 2, false)))
+ assert(Reline::Key.new(1, nil, false).match?(Reline::Key.new(1, nil, false)))
+ assert(Reline::Key.new(1, 2, nil).match?(Reline::Key.new(1, 2, nil)))
+
+ assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(3, 1, false)))
+ assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 3, false)))
+ assert(!Reline::Key.new(1, 2, false).match?(Reline::Key.new(1, 3, true)))
+ end
+
+ def test_match_integer
+ assert(Reline::Key.new(1, 2, false).match?(2))
+ assert(Reline::Key.new(nil, 2, false).match?(2))
+ assert(Reline::Key.new(1, nil, false).match?(1))
+
+ assert(!Reline::Key.new(1, 2, false).match?(1))
+ assert(!Reline::Key.new(1, nil, false).match?(2))
+ assert(!Reline::Key.new(nil, nil, false).match?(1))
+ end
+
+ def test_match_symbol
+ assert(Reline::Key.new(:key1, :key2, false).match?(:key2))
+ assert(Reline::Key.new(:key1, nil, false).match?(:key1))
+
+ assert(!Reline::Key.new(:key1, :key2, false).match?(:key1))
+ assert(!Reline::Key.new(:key1, nil, false).match?(:key2))
+ assert(!Reline::Key.new(nil, nil, false).match?(:key1))
+ end
+
+ def test_match_other
+ assert(!Reline::Key.new(:key1, 2, false).match?("key1"))
+ assert(!Reline::Key.new(nil, nil, false).match?(nil))
+ end
+end
diff --git a/test/reline/yamatanooroti/multiline_repl b/test/reline/yamatanooroti/multiline_repl
index 473d9d0f009..1f2a0237243 100755
--- a/test/reline/yamatanooroti/multiline_repl
+++ b/test/reline/yamatanooroti/multiline_repl
@@ -55,6 +55,15 @@ opt.on('--dialog VAL') { |v|
natural to read
and easy to write.
RUBY
+ elsif v.include?('fullwidth')
+ contents = <<~RUBY.split("\n")
+ Rubyとは...
+
+ オープンソースの動的なプログラミン
+ グ言語で、シンプルさと高い生産性を
+ 備えています。エレガントな文法を持
+ ち、自然に読み書きができます。
+ RUBY
end
if v.include?('scrollkey')
dialog.trap_key = nil
@@ -74,8 +83,14 @@ opt.on('--dialog VAL') { |v|
if v.include?('scrollbar')
scrollbar = true
end
+ if v.include?('alt-scrollbar')
+ scrollbar = true
+ end
Reline::DialogRenderInfo.new(pos: cursor_pos, contents: contents, height: height, scrollbar: scrollbar)
})
+ if v.include?('alt-scrollbar')
+ ENV['RELINE_ALT_SCROLLBAR'] = '1'
+ end
}
opt.on('--complete') {
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
@@ -91,7 +106,57 @@ opt.on('--autocomplete') {
opt.on('--autocomplete-long') {
Reline.autocompletion = true
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
- %w{String Struct Symbol StopIteration SystemCallError SystemExit SystemStackError ScriptError SyntaxError Signal SizedQueue Set SecureRandom Socket StringIO StringScanner Shellwords Syslog Singleton SDBM}.select{ |c| c.start_with?(target) }
+ %w{
+ String
+ Struct
+ Symbol
+ StopIteration
+ SystemCallError
+ SystemExit
+ SystemStackError
+ ScriptError
+ SyntaxError
+ Signal
+ SizedQueue
+ Set
+ SecureRandom
+ Socket
+ StringIO
+ StringScanner
+ Shellwords
+ Syslog
+ Singleton
+ SDBM
+ }.select{ |c| c.start_with?(target) }
+ }
+}
+opt.on('--autocomplete-super-long') {
+ Reline.autocompletion = true
+ Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
+ c = 'A'
+ 2000.times.map{ s = "Str_#{c}"; c.succ!; s }.select{ |c| c.start_with?(target) }
+ }
+}
+
+opt.on('--autocomplete-width-long') {
+ Reline.autocompletion = true
+ Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
+ %w{
+ remove_instance_variable
+ respond_to?
+ ruby2_keywords
+ rand
+ readline
+ readlines
+ require
+ require_relative
+ raise
+ respond_to_missing?
+ redo
+ rescue
+ retry
+ return
+ }.select{ |c| c.start_with?(target) }
}
}
opt.parse!(ARGV)
diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb
index 58d23a40fdc..f68b614327b 100644
--- a/test/reline/yamatanooroti/test_rendering.rb
+++ b/test/reline/yamatanooroti/test_rendering.rb
@@ -424,10 +424,10 @@ begin
def test_binding_for_vi_movement_mode
write_inputrc <<~LINES
set editing-mode vi
- "\\C-j": vi-movement-mode
+ "\\C-a": vi-movement-mode
LINES
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
- write(":1234\C-jhhhi0")
+ write(":1234\C-ahhhi0")
close
assert_screen(<<~EOC)
Multiline REPL.
@@ -730,7 +730,7 @@ begin
end
def test_meta_key
- start_terminal(50, 200, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
+ start_terminal(30, 20, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def ge\M-bho")
close
assert_screen(<<~EOC)
@@ -740,7 +740,7 @@ begin
end
def test_force_enter
- start_terminal(50, 200, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
+ start_terminal(30, 120, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\nend\C-p\C-e")
write("\M-\x0D")
close
@@ -752,32 +752,10 @@ begin
EOC
end
- def test_cyrillic_chars
- omit unless Reline::IOGate.win?
- start_terminal(50, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
- write("`chcp 850`\n")
- write("`chcp`\n")
- write("def гопота; 3; end\n")
- write("гопота\n")
- close
- assert_screen(<<~'EOC')
- Multiline REPL.
- prompt> `chcp 850`
- => "Active code page: 850\n"
- prompt> `chcp`
- => "Active code page: 850\n"
- prompt> def гопота; 3; end
- => :гопота
- prompt> гопота
- => 3
- prompt>
- EOC
- end
-
def test_with_newline
omit if Reline::IOGate.win?
cmd = %Q{ruby -e 'print(%Q{abc def \\e\\r})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
- start_terminal(50, 50, ['bash', '-c', cmd])
+ start_terminal(40, 50, ['bash', '-c', cmd])
close
assert_screen(<<~'EOC')
> abc def
@@ -851,12 +829,12 @@ begin
assert_screen(<<~'EOC')
Multiline REPL.
prompt> ab
- Ruby is...
- A dynamic, open source programming
- language with a focus on simplicity
- and productivity. It has an elegant
- syntax that is natural to read and
- easy to write.
+ Ruby is...
+ A dynamic, open source programming
+ language with a focus on simplicity
+ and productivity. It has an elegant
+ syntax that is natural to read and
+ easy to write.
EOC
end
@@ -906,8 +884,8 @@ begin
assert_screen(<<~'EOC')
Multiline REPL.
prompt> St
- r String
- Struct
+ r String
+ Struct
EOC
end
@@ -957,6 +935,40 @@ begin
EOC
end
+ def test_dialog_with_fullwidth_chars
+ ENV['RELINE_TEST_PROMPT'] = '> '
+ start_terminal(30, 5, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog fullwidth,scrollkey,scrollbar}, startup_message: 'Multiline REPL.')
+ 6.times{ write('j') }
+ close
+ assert_screen(<<~'EOC')
+ Multi
+ line
+ REPL.
+ >
+ オー
+ グ言▄
+ 備え█
+ ち、█
+ EOC
+ end
+
+ def test_dialog_with_fullwidth_chars_split
+ ENV['RELINE_TEST_PROMPT'] = '> '
+ start_terminal(30, 6, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog fullwidth,scrollkey,scrollbar}, startup_message: 'Multiline REPL.')
+ 6.times{ write('j') }
+ close
+ assert_screen(<<~'EOC')
+ Multil
+ ine RE
+ PL.
+ >
+ オー
+ グ言 ▄
+ 備え █
+ ち、 █
+ EOC
+ end
+
def test_autocomplete_empty
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete}, startup_message: 'Multiline REPL.')
write('Street')
@@ -1057,6 +1069,33 @@ begin
EOC
end
+ def test_autocomplete_super_long_and_backspace
+ start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-super-long}, startup_message: 'Multiline REPL.')
+ shift_tab = [27, 91, 90]
+ write('S' + shift_tab.map(&:chr).join)
+ write("\C-h")
+ close
+ assert_screen(<<~'EOC')
+ Multiline REPL.
+ prompt> Str_BX
+ Str_BX
+ Str_BXA
+ Str_BXB
+ Str_BXC
+ Str_BXD
+ Str_BXE
+ Str_BXF
+ Str_BXG
+ Str_BXH
+ Str_BXI
+ Str_BXJ
+ Str_BXK
+ Str_BXL
+ Str_BXM
+ Str_BXN
+ EOC
+ end
+
def test_dialog_callback_returns_nil
start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog nil}, startup_message: 'Multiline REPL.')
write('a')
@@ -1067,6 +1106,87 @@ begin
EOC
end
+ def test_dialog_narrower_than_screen
+ start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
+ close
+ assert_screen(<<~'EOC')
+ Multiline R
+ EPL.
+ prompt>
+ Ruby is...
+ A dynamic,
+ language wi
+ and product
+ syntax that
+ easy to wri
+ EOC
+ end
+
+ def test_dialog_narrower_than_screen_with_scrollbar
+ start_terminal(20, 11, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-long}, startup_message: 'Multiline REPL.')
+ write('S' + "\C-i" * 3)
+ close
+ assert_screen(<<~'EOC')
+ Multiline R
+ EPL.
+ prompt> Sym
+ String
+ Struct █
+ Symbol █
+ StopIterat█
+ SystemCall█
+ SystemExit█
+ SystemStac█
+ ScriptErro█
+ SyntaxErro█
+ Signal █
+ SizedQueue█
+ Set
+ SecureRand
+ Socket
+ StringIO
+ EOC
+ end
+
+ def test_dialog_with_fullwidth_scrollbar
+ start_terminal(20, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple,scrollkey,alt-scrollbar}, startup_message: 'Multiline REPL.')
+ close
+ assert_screen(<<~'EOC')
+ Multiline REPL.
+ prompt>
+ Ruby is... ::
+ A dynamic, open source programming ::
+ language with a focus on simplicity''
+ and productivity. It has an elegant
+ EOC
+ end
+
+ def test_rerender_argument_prompt_after_pasting
+ start_terminal(20, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
+ write('abcdef')
+ write("\M-3\C-h")
+ close
+ assert_screen(<<~'EOC')
+ Multiline REPL.
+ prompt> abc
+ EOC
+ end
+
+ def test_autocomplete_old_dialog_width_greater_than_dialog_width
+ start_terminal(40, 40, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --autocomplete-width-long}, startup_message: 'Multiline REPL.')
+ write("0+ \n12345678901234")
+ write("\C-p")
+ write("r")
+ write("a")
+ close
+ assert_screen(<<~'EOC')
+ Multiline REPL.
+ prompt> 0+ ra
+ prompt> 123rand 901234
+ raise
+ EOC
+ end
+
def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content
diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb
index 98d513da87e..7709760d199 100644
--- a/test/ruby/test_autoload.rb
+++ b/test/ruby/test_autoload.rb
@@ -456,6 +456,31 @@ p Foo::Bar
end;
end
+ def test_autoload_after_failed_and_removed_from_loaded_features
+ Dir.mktmpdir('autoload') do |tmpdir|
+ autoload_path = File.join(tmpdir, "test-bug-15790.rb")
+ File.write(autoload_path, '')
+
+ assert_separately(%W[-I #{tmpdir}], <<-RUBY)
+ path = #{File.realpath(autoload_path).inspect}
+ autoload :X, path
+ assert_equal(path, Object.autoload?(:X))
+
+ assert_raise(NameError){X}
+ assert_nil(Object.autoload?(:X))
+ assert_equal(false, Object.const_defined?(:X))
+
+ $LOADED_FEATURES.delete(path)
+ assert_equal(false, Object.const_defined?(:X))
+ assert_nil(Object.autoload?(:X))
+
+ assert_raise(NameError){X}
+ assert_equal(false, Object.const_defined?(:X))
+ assert_nil(Object.autoload?(:X))
+ RUBY
+ end
+ end
+
def add_autoload(path)
(@autoload_paths ||= []) << path
::Object.class_eval {autoload(:AutoloadTest, path)}
@@ -463,7 +488,7 @@ p Foo::Bar
def remove_autoload_constant
$".replace($" - @autoload_paths)
- ::Object.class_eval {remove_const(:AutoloadTest)}
+ ::Object.class_eval {remove_const(:AutoloadTest)} if defined? Object::AutoloadTest
TestAutoload.class_eval {remove_const(:AutoloadTest)} if defined? TestAutoload::AutoloadTest
end
end
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 368c046261e..28285705bf3 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -737,4 +737,83 @@ class TestClass < Test::Unit::TestCase
c = Class.new.freeze
assert_same(c, Module.new.const_set(:Foo, c))
end
+
+ def test_descendants
+ c = Class.new
+ sc = Class.new(c)
+ ssc = Class.new(sc)
+ [c, sc, ssc].each do |k|
+ k.include Module.new
+ k.new.define_singleton_method(:force_singleton_class){}
+ end
+ assert_equal([sc, ssc], c.descendants)
+ assert_equal([ssc], sc.descendants)
+ assert_equal([], ssc.descendants)
+
+ object_descendants = Object.descendants
+ assert_include(object_descendants, c)
+ assert_include(object_descendants, sc)
+ assert_include(object_descendants, ssc)
+ end
+
+ def test_descendants_gc
+ c = Class.new
+ 100000.times { Class.new(c) }
+ assert(c.descendants.size <= 100000)
+ end
+
+ def test_descendants_gc_stress
+ 10000.times do
+ c = Class.new
+ 100.times { Class.new(c) }
+ assert(c.descendants.size <= 100)
+ end
+ end
+
+ def test_subclasses
+ c = Class.new
+ sc = Class.new(c)
+ ssc = Class.new(sc)
+ [c, sc, ssc].each do |k|
+ k.include Module.new
+ k.new.define_singleton_method(:force_singleton_class){}
+ end
+ assert_equal([sc], c.subclasses)
+ assert_equal([ssc], sc.subclasses)
+ assert_equal([], ssc.subclasses)
+
+ object_subclasses = Object.subclasses
+ assert_include(object_subclasses, c)
+ assert_not_include(object_subclasses, sc)
+ assert_not_include(object_subclasses, ssc)
+ object_subclasses.each do |subclass|
+ assert_equal Object, subclass.superclass, "Expected #{subclass}.superclass to be Object"
+ end
+ end
+
+ def test_subclass_gc
+ c = Class.new
+ 10_000.times do
+ cc = Class.new(c)
+ 100.times { Class.new(cc) }
+ end
+ assert(c.subclasses.size <= 10_000)
+ end
+
+ def test_subclass_gc_stress
+ 10000.times do
+ c = Class.new
+ 100.times { Class.new(c) }
+ assert(c.subclasses.size <= 100)
+ end
+ end
+
+ def test_classext_memory_leak
+ assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true)
+code = proc { Class.new }
+1_000.times(&code)
+PREP
+3_000_000.times(&code)
+CODE
+ end
end
diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb
index 71bff5f5c37..9474c6e927f 100644
--- a/test/ruby/test_dir.rb
+++ b/test/ruby/test_dir.rb
@@ -171,9 +171,17 @@ class TestDir < Test::Unit::TestCase
Dir.glob([@root, File.join(@root, "*")]))
assert_equal([@root] + ("a".."z").map {|f| File.join(@root, f) },
Dir.glob([@root, File.join(@root, "*")], sort: false).sort)
+ assert_equal([@root] + ("a".."z").map {|f| File.join(@root, f) },
+ Dir.glob([@root, File.join(@root, "*")], sort: true))
assert_raise_with_message(ArgumentError, /nul-separated/) do
Dir.glob(@root + "\0\0\0" + File.join(@root, "*"))
end
+ assert_raise_with_message(ArgumentError, /expected true or false/) do
+ Dir.glob(@root, sort: 1)
+ end
+ assert_raise_with_message(ArgumentError, /expected true or false/) do
+ Dir.glob(@root, sort: nil)
+ end
assert_equal(("a".."z").step(2).map {|f| File.join(File.join(@root, f), "") },
Dir.glob(File.join(@root, "*/")))
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb
index 4674f984ffb..f6375a4ffc2 100644
--- a/test/ruby/test_enum.rb
+++ b/test/ruby/test_enum.rb
@@ -134,6 +134,12 @@ class TestEnumerable < Test::Unit::TestCase
assert_equal([1, 2, 3, 1, 2], @obj.to_a)
end
+ def test_to_a_keywords
+ @obj.singleton_class.remove_method(:each)
+ def @obj.each(foo:) yield foo end
+ assert_equal([1], @obj.to_a(foo: 1))
+ end
+
def test_to_a_size_symbol
sym = Object.new
class << sym
@@ -731,6 +737,9 @@ class TestEnumerable < Test::Unit::TestCase
ary.clear
(1..10).each_slice(11) {|a| ary << a}
assert_equal([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], ary)
+
+ assert_equal(1..10, (1..10).each_slice(3) { })
+ assert_equal([], [].each_slice(3) { })
end
def test_each_cons
@@ -750,6 +759,9 @@ class TestEnumerable < Test::Unit::TestCase
ary.clear
(1..5).each_cons(6) {|a| ary << a}
assert_empty(ary)
+
+ assert_equal(1..5, (1..5).each_cons(3) { })
+ assert_equal([], [].each_cons(3) { })
end
def test_zip
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb
index ea0f367334f..5bc974d6b25 100644
--- a/test/ruby/test_env.rb
+++ b/test/ruby/test_env.rb
@@ -503,7 +503,7 @@ class TestEnv < Test::Unit::TestCase
end
def test_huge_value
- if /mswin/ =~ RUBY_PLATFORM || /ucrt/ =~ RbConfig::CONFIG['sitearch']
+ if /mswin|ucrt/ =~ RUBY_PLATFORM
# On Windows >= Vista each environment variable can be max 32768 characters
huge_value = "bar" * 10900
else
diff --git a/test/ruby/test_eval.rb b/test/ruby/test_eval.rb
index bf551c68456..d55977c986f 100644
--- a/test/ruby/test_eval.rb
+++ b/test/ruby/test_eval.rb
@@ -219,6 +219,12 @@ class TestEval < Test::Unit::TestCase
end
end
+ def test_instance_exec_cvar
+ [Object.new, [], 7, :sym, true, false, nil].each do |obj|
+ assert_equal(13, obj.instance_exec{@@cvar})
+ end
+ end
+
def test_instance_eval_method
bug2788 = '[ruby-core:28324]'
[Object.new, [], nil, true, false].each do |o|
@@ -253,6 +259,70 @@ class TestEval < Test::Unit::TestCase
assert_equal(2, bar)
end
+ def test_instance_exec_block_basic
+ forall_TYPE do |o|
+ assert_equal nil, o.instance_exec { nil }
+ assert_equal true, o.instance_exec { true }
+ assert_equal false, o.instance_exec { false }
+ assert_equal o, o.instance_exec { self }
+ assert_equal 1, o.instance_exec { 1 }
+ assert_equal :sym, o.instance_exec { :sym }
+
+ assert_equal 11, o.instance_exec { 11 }
+ assert_equal 12, o.instance_exec { @ivar } unless o.frozen?
+ assert_equal 13, o.instance_exec { @@cvar }
+ assert_equal 14, o.instance_exec { $gvar__eval }
+ assert_equal 15, o.instance_exec { Const }
+ assert_equal 16, o.instance_exec { 7 + 9 }
+ assert_equal 17, o.instance_exec { 17.to_i }
+ assert_equal "18", o.instance_exec { "18" }
+ assert_equal "19", o.instance_exec { "1#{9}" }
+
+ 1.times {
+ assert_equal 12, o.instance_exec { @ivar } unless o.frozen?
+ assert_equal 13, o.instance_exec { @@cvar }
+ assert_equal 14, o.instance_exec { $gvar__eval }
+ assert_equal 15, o.instance_exec { Const }
+ }
+ end
+ end
+
+ def test_instance_exec_method_definition
+ klass = Class.new
+ o = klass.new
+
+ o.instance_exec do
+ def foo
+ :foo_result
+ end
+ end
+
+ assert_respond_to o, :foo
+ refute_respond_to klass, :foo
+ refute_respond_to klass.new, :foo
+
+ assert_equal :foo_result, o.foo
+ end
+
+ def test_instance_exec_eval_method_definition
+ klass = Class.new
+ o = klass.new
+
+ o.instance_exec do
+ eval %{
+ def foo
+ :foo_result
+ end
+ }
+ end
+
+ assert_respond_to o, :foo
+ refute_respond_to klass, :foo
+ refute_respond_to klass.new, :foo
+
+ assert_equal :foo_result, o.foo
+ end
+
#
# From ruby/test/ruby/test_eval.rb
#
diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb
index 67fef33b85f..a0fd4a7491c 100644
--- a/test/ruby/test_fiber.rb
+++ b/test/ruby/test_fiber.rb
@@ -50,7 +50,7 @@ class TestFiber < Test::Unit::TestCase
end
def test_many_fibers_with_threads
- assert_normal_exit <<-SRC, timeout: (/solaris/i =~ RUBY_PLATFORM ? 300 : 60)
+ assert_normal_exit <<-SRC, timeout: (/solaris/i =~ RUBY_PLATFORM ? 1000 : 60)
max = 1000
@cnt = 0
(1..100).map{|ti|
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 70966d83a4a..03675eaebcd 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -78,6 +78,19 @@ class TestFileExhaustive < Test::Unit::TestCase
@notownedfile
end
+ def grpownedfile
+ return nil unless POSIX
+ return @grpownedfile if defined? @grpownedfile
+ if group = (Process.groups - [Process.egid]).last
+ grpownedfile = make_tmp_filename("grpownedfile")
+ make_file("grpowned", grpownedfile)
+ File.chown(nil, group, grpownedfile)
+ return @grpownedfile = grpownedfile
+ end
+ rescue
+ @grpownedfile = nil
+ end
+
def suidfile
return @suidfile if defined? @suidfile
if POSIX
@@ -493,6 +506,9 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_grpowned_p ## xxx
assert_file.grpowned?(regular_file)
assert_file.grpowned?(utf8_file)
+ if file = grpownedfile
+ assert_file.grpowned?(file)
+ end
end if POSIX
def io_open(file_name)
@@ -1392,21 +1408,24 @@ class TestFileExhaustive < Test::Unit::TestCase
end
def test_flock_exclusive
+ timeout = EnvUtil.apply_timeout_scale(0.1).to_s
File.open(regular_file, "r+") do |f|
f.flock(File::LOCK_EX)
- assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
- begin
+ assert_separately(["-rtimeout", "-", regular_file, timeout], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ timeout = ARGV[1].to_f
open(ARGV[0], "r") do |f|
- Timeout.timeout(0.1) do
+ Timeout.timeout(timeout) do
assert(!f.flock(File::LOCK_SH|File::LOCK_NB))
end
end
end;
- assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
- begin
+ assert_separately(["-rtimeout", "-", regular_file, timeout], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ timeout = ARGV[1].to_f
open(ARGV[0], "r") do |f|
assert_raise(Timeout::Error) do
- Timeout.timeout(0.1) do
+ Timeout.timeout(timeout) do
f.flock(File::LOCK_SH)
end
end
@@ -1418,21 +1437,24 @@ class TestFileExhaustive < Test::Unit::TestCase
end
def test_flock_shared
+ timeout = EnvUtil.apply_timeout_scale(0.1).to_s
File.open(regular_file, "r+") do |f|
f.flock(File::LOCK_SH)
- assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
- begin
+ assert_separately(["-rtimeout", "-", regular_file, timeout], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ timeout = ARGV[1].to_f
open(ARGV[0], "r") do |f|
- Timeout.timeout(0.1) do
+ Timeout.timeout(timeout) do
assert(f.flock(File::LOCK_SH))
end
end
end;
- assert_separately(["-rtimeout", "-", regular_file], "#{<<~begin}#{<<~"end;"}")
- begin
+ assert_separately(["-rtimeout", "-", regular_file, timeout], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ timeout = ARGV[1].to_f
open(ARGV[0], "r+") do |f|
assert_raise(Timeout::Error) do
- Timeout.timeout(0.1) do
+ Timeout.timeout(timeout) do
f.flock(File::LOCK_EX)
end
end
@@ -1454,6 +1476,7 @@ class TestFileExhaustive < Test::Unit::TestCase
fn1,
zerofile,
notownedfile,
+ grpownedfile,
suidfile,
sgidfile,
stickyfile,
@@ -1689,6 +1712,9 @@ class TestFileExhaustive < Test::Unit::TestCase
def test_stat_grpowned_p ## xxx
assert_predicate(File::Stat.new(regular_file), :grpowned?)
+ if file = grpownedfile
+ assert_predicate(File::Stat.new(file), :grpowned?)
+ end
end if POSIX
def test_stat_suid
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb
index 46683d0ed57..c591b1d74e6 100644
--- a/test/ruby/test_gc_compact.rb
+++ b/test/ruby/test_gc_compact.rb
@@ -3,6 +3,11 @@ require 'test/unit'
require 'fiddle'
require 'etc'
+if RUBY_PLATFORM =~ /s390x/
+ puts "Currently, it is known that the compaction does not work well on s390x; contribution is welcome https://github.com/ruby/ruby/pull/5077"
+ return
+end
+
class TestGCCompact < Test::Unit::TestCase
module SupportsCompact
def setup
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index 9354514df07..a2b181c6422 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -299,6 +299,31 @@ class TestInteger < Test::Unit::TestCase
end
end
+ def test_times_bignum_redefine_plus_lt
+ assert_separately([], "#{<<-"begin;"}\n#{<<~"end;"}")
+ begin;
+ called = false
+ Integer.class_eval do
+ alias old_plus +
+ undef +
+ define_method(:+){|x| called = true; 1}
+ alias old_lt <
+ undef <
+ define_method(:<){|x| called = true}
+ end
+ big = 2**65
+ big.times{break 0}
+ Integer.class_eval do
+ undef +
+ alias + old_plus
+ undef <
+ alias < old_lt
+ end
+ bug18377 = "[ruby-core:106361]"
+ assert_equal(false, called, bug18377)
+ end;
+ end
+
def assert_int_equal(expected, result, mesg = nil)
assert_kind_of(Integer, result, mesg)
assert_equal(expected, result, mesg)
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index a90140fd0b3..96e572b98d7 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -3847,30 +3847,6 @@ __END__
end
end;
end
-
- def test_write_no_garbage
- skip "multiple threads already active" if Thread.list.size > 1
- res = {}
- ObjectSpace.count_objects(res) # creates strings on first call
- [ 'foo'.b, '*' * 24 ].each do |buf|
- with_pipe do |r, w|
- GC.disable
- begin
- before = ObjectSpace.count_objects(res)[:T_STRING]
- n = w.write(buf)
- s = w.syswrite(buf)
- after = ObjectSpace.count_objects(res)[:T_STRING]
- ensure
- GC.enable
- end
- assert_equal before, after,
- "no strings left over after write [ruby-core:78898] [Bug #13085]: #{ before } strings before write -> #{ after } strings after write"
- assert_not_predicate buf, :frozen?, 'no inadvertent freeze'
- assert_equal buf.bytesize, n, 'IO#write wrote expected size'
- assert_equal s, n, 'IO#syswrite wrote expected size'
- end
- end
- end
end
def test_pread
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
new file mode 100644
index 00000000000..f7c175b589c
--- /dev/null
+++ b/test/ruby/test_io_buffer.rb
@@ -0,0 +1,195 @@
+# frozen_string_literal: false
+
+class TestIOBuffer < Test::Unit::TestCase
+ experimental = Warning[:experimental]
+ begin
+ Warning[:experimental] = false
+ IO::Buffer.new(0)
+ ensure
+ Warning[:experimental] = experimental
+ end
+
+ def assert_negative(value)
+ assert(value < 0, "Expected #{value} to be negative!")
+ end
+
+ def assert_positive(value)
+ assert(value > 0, "Expected #{value} to be positive!")
+ end
+
+ def test_flags
+ assert_equal 0, IO::Buffer::EXTERNAL
+ assert_equal 1, IO::Buffer::INTERNAL
+ assert_equal 2, IO::Buffer::MAPPED
+
+ assert_equal 16, IO::Buffer::LOCKED
+ assert_equal 32, IO::Buffer::PRIVATE
+
+ assert_equal 64, IO::Buffer::IMMUTABLE
+ end
+
+ def test_endian
+ assert_equal 4, IO::Buffer::LITTLE_ENDIAN
+ assert_equal 8, IO::Buffer::BIG_ENDIAN
+ assert_equal 8, IO::Buffer::NETWORK_ENDIAN
+
+ assert_include [IO::Buffer::LITTLE_ENDIAN, IO::Buffer::BIG_ENDIAN], IO::Buffer::HOST_ENDIAN
+ end
+
+ def test_new_internal
+ buffer = IO::Buffer.new(1024, IO::Buffer::INTERNAL)
+ assert_equal 1024, buffer.size
+ refute buffer.external?
+ assert buffer.internal?
+ refute buffer.mapped?
+ end
+
+ def test_new_mapped
+ buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED)
+ assert_equal 1024, buffer.size
+ refute buffer.external?
+ refute buffer.internal?
+ assert buffer.mapped?
+ end
+
+ def test_new_immutable
+ buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::IMMUTABLE)
+ assert buffer.immutable?
+
+ assert_raise RuntimeError do
+ buffer.copy("", 0)
+ end
+
+ assert_raise RuntimeError do
+ buffer.copy("!", 1)
+ end
+ end
+
+ def test_file_mapped
+ buffer = File.open(__FILE__) {|file| IO::Buffer.map(file)}
+ assert_include buffer.to_str, "Hello World"
+ end
+
+ def test_string_mapped
+ string = "Hello World"
+ buffer = IO::Buffer.for(string)
+
+ # Cannot modify string as it's locked by the buffer:
+ assert_raise RuntimeError do
+ string[0] = "h"
+ end
+
+ buffer.set(:U8, 0, "h".ord)
+
+ # Buffer releases it's ownership of the string:
+ buffer.free
+
+ assert_equal "hello World", string
+ string[0] = "H"
+ assert_equal "Hello World", string
+ end
+
+ def test_non_string
+ not_string = Object.new
+
+ assert_raise TypeError do
+ IO::Buffer.for(not_string)
+ end
+ end
+
+ def test_resize
+ buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED)
+ buffer.resize(2048, 0)
+ assert_equal 2048, buffer.size
+ end
+
+ def test_resize_preserve
+ message = "Hello World"
+ buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED)
+ buffer.copy(message, 0)
+ buffer.resize(2048, 1024)
+ assert_equal message, buffer.to_str(0, message.bytesize)
+ end
+
+ def test_compare_same_size
+ buffer1 = IO::Buffer.new(1)
+ assert_equal buffer1, buffer1
+
+ buffer2 = IO::Buffer.new(1)
+ buffer1.set(:U8, 0, 0x10)
+ buffer2.set(:U8, 0, 0x20)
+
+ assert_negative buffer1 <=> buffer2
+ assert_positive buffer2 <=> buffer1
+ end
+
+ def test_compare_different_size
+ buffer1 = IO::Buffer.new(3)
+ buffer2 = IO::Buffer.new(5)
+
+ assert_negative buffer1 <=> buffer2
+ assert_positive buffer2 <=> buffer1
+ end
+
+ def test_slice
+ buffer = IO::Buffer.new(128)
+ slice = buffer.slice(8, 32)
+ slice.copy("Hello World", 0)
+ assert_equal("Hello World", buffer.to_str(8, 11))
+ end
+
+ def test_slice_bounds
+ buffer = IO::Buffer.new(128)
+
+ # What is best exception class?
+ assert_raise RuntimeError do
+ buffer.slice(128, 10)
+ end
+
+ # assert_raise RuntimeError do
+ # pp buffer.slice(-10, 10)
+ # end
+ end
+
+ def test_locked
+ buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
+
+ assert_raise RuntimeError do
+ buffer.resize(256, 0)
+ end
+
+ assert_equal 128, buffer.size
+
+ assert_raise RuntimeError do
+ buffer.free
+ end
+
+ assert_equal 128, buffer.size
+ end
+
+ def test_invalidation
+ input, output = IO.pipe
+
+ # (1) rb_write_internal creates IO::Buffer object,
+ buffer = IO::Buffer.new(128)
+
+ # (2) it is passed to (malicious) scheduler
+ # (3) scheduler starts a thread which call system call with the buffer object
+ thread = Thread.new{buffer.locked{input.read}}
+
+ Thread.pass until thread.stop?
+
+ # (4) scheduler returns
+ # (5) rb_write_internal invalidate the buffer object
+ assert_raise RuntimeError do
+ buffer.free
+ end
+
+ # (6) the system call access the memory area after invalidation
+ output.write("Hello World")
+ output.close
+ thread.join
+
+ input.close
+ end
+end
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 0cde1fbb7a5..ac191531dec 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -10,13 +10,16 @@ class TestISeq < Test::Unit::TestCase
end
def compile(src, line = nil, opt = nil)
+ unless line
+ line = caller_locations(1).first.lineno
+ end
EnvUtil.suppress_warning do
ISeq.new(src, __FILE__, __FILE__, line, opt)
end
end
- def lines src
- body = compile(src).to_a[13]
+ def lines src, lines = nil
+ body = compile(src, lines).to_a[13]
body.find_all{|e| e.kind_of? Integer}
end
@@ -25,24 +28,22 @@ class TestISeq < Test::Unit::TestCase
end
def test_to_a_lines
- src = <<-EOS
+ assert_equal [__LINE__+1, __LINE__+2, __LINE__+4], lines(<<-EOS, __LINE__+1)
p __LINE__ # 1
p __LINE__ # 2
# 3
p __LINE__ # 4
EOS
- assert_equal [1, 2, 4], lines(src)
- src = <<-EOS
+ assert_equal [__LINE__+2, __LINE__+4], lines(<<-EOS, __LINE__+1)
# 1
p __LINE__ # 2
# 3
p __LINE__ # 4
# 5
EOS
- assert_equal [2, 4], lines(src)
- src = <<-EOS
+ assert_equal [__LINE__+3, __LINE__+4, __LINE__+7, __LINE__+9], lines(<<~EOS, __LINE__+1)
1 # should be optimized out
2 # should be optimized out
p __LINE__ # 3
@@ -53,10 +54,9 @@ class TestISeq < Test::Unit::TestCase
8 # should be optimized out
9
EOS
- assert_equal [3, 4, 7, 9], lines(src)
end
- def test_unsupport_type
+ def test_unsupported_type
ary = compile("p").to_a
ary[9] = :foobar
assert_raise_with_message(TypeError, /:foobar/) {ISeq.load(ary)}
@@ -86,7 +86,7 @@ class TestISeq < Test::Unit::TestCase
# CDHASH was not built properly when loading from binary and
# was causing opt_case_dispatch to clobber its stack canary
# for its "leaf" instruction attribute.
- iseq = compile(<<~EOF)
+ iseq = compile(<<~EOF, __LINE__+1)
case Class.new(String).new("foo")
when "foo"
42
@@ -95,6 +95,74 @@ class TestISeq < Test::Unit::TestCase
assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
end
+ def test_super_with_block
+ iseq = compile(<<~EOF, __LINE__+1)
+ def (Object.new).touch(*) # :nodoc:
+ foo { super }
+ end
+ 42
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
+ def test_super_with_block_hash_0
+ iseq = compile(<<~EOF, __LINE__+1)
+ # [Bug #18250] `req` specifically cause `Assertion failed: (key != 0), function hash_table_raw_insert`
+ def (Object.new).touch(req, *)
+ foo { super }
+ end
+ 42
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
+ def test_super_with_block_and_kwrest
+ iseq = compile(<<~EOF, __LINE__+1)
+ def (Object.new).touch(**) # :nodoc:
+ foo { super }
+ end
+ 42
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
+ def test_lambda_with_ractor_roundtrip
+ iseq = compile(<<~EOF, __LINE__+1)
+ x = 42
+ y = lambda { x }
+ Ractor.make_shareable(y)
+ y.call
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
+ def test_super_with_anonymous_block
+ iseq = compile(<<~EOF, __LINE__+1)
+ def (Object.new).touch(&) # :nodoc:
+ foo { super }
+ end
+ 42
+ EOF
+ assert_equal(42, ISeq.load_from_binary(iseq.to_binary).eval)
+ end
+
+ def test_ractor_unshareable_outer_variable
+ name = "\u{2603 26a1}"
+ y = eval("proc {#{name} = nil; proc {|x| #{name} = x}}").call
+ assert_raise_with_message(ArgumentError, /\(#{name}\)/) do
+ Ractor.make_shareable(y)
+ end
+ y = eval("proc {#{name} = []; proc {|x| #{name}}}").call
+ assert_raise_with_message(Ractor::IsolationError, /`#{name}'/) do
+ Ractor.make_shareable(y)
+ end
+ obj = Object.new
+ def obj.foo(*) ->{super} end
+ assert_raise_with_message(Ractor::IsolationError, /hidden variable/) do
+ Ractor.make_shareable(obj.foo)
+ end
+ end
+
def test_disasm_encoding
src = "\u{3042} = 1; \u{3042}; \u{3043}"
asm = compile(src).disasm
@@ -137,16 +205,16 @@ class TestISeq < Test::Unit::TestCase
end
def test_line_trace
- iseq = compile \
- %q{ a = 1
+ iseq = compile(<<~EOF, __LINE__+1)
+ a = 1
b = 2
c = 3
# d = 4
e = 5
# f = 6
g = 7
+ EOF
- }
assert_equal([1, 2, 3, 5, 7], iseq.line_trace_all)
iseq.line_trace_specify(1, true) # line 2
iseq.line_trace_specify(3, true) # line 5
@@ -318,6 +386,22 @@ class TestISeq < Test::Unit::TestCase
end
end
+ def anon_star(*); end
+
+ def test_anon_param_in_disasm
+ iseq = RubyVM::InstructionSequence.of(method(:anon_star))
+ param_names = iseq.to_a[iseq.to_a.index(:method) + 1]
+ assert_equal [2], param_names
+ end
+
+ def anon_block(&); end
+
+ def test_anon_block_param_in_disasm
+ iseq = RubyVM::InstructionSequence.of(method(:anon_block))
+ param_names = iseq.to_a[iseq.to_a.index(:method) + 1]
+ assert_equal [:&], param_names
+ end
+
def strip_lineno(source)
source.gsub(/^.*?: /, "")
end
@@ -454,6 +538,11 @@ class TestISeq < Test::Unit::TestCase
a1 = iseq.to_a
a2 = iseq2.to_a
assert_equal(a1, a2, message(mesg) {diff iseq.disassemble, iseq2.disassemble})
+ if iseq2.script_lines
+ assert_kind_of(Array, iseq2.script_lines)
+ else
+ assert_nil(iseq2.script_lines)
+ end
iseq2
end
@@ -625,4 +714,11 @@ class TestISeq < Test::Unit::TestCase
RubyVM::InstructionSequence.compile("", debug_level: 5)
end;
end
+
+ def test_mandatory_only
+ assert_separately [], <<~RUBY
+ at0 = Time.at(0)
+ assert_equal at0, Time.public_send(:at, 0, 0)
+ RUBY
+ end
end
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index 60e128b3d9c..dcbe694d7a1 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -53,8 +53,9 @@ class TestJIT < Test::Unit::TestCase
# ruby -w -Itest/lib test/ruby/test_jit.rb
if $VERBOSE
+ pid = $$
at_exit do
- unless TestJIT.untested_insns.empty?
+ if pid == $$ && !TestJIT.untested_insns.empty?
warn "you may want to add tests for following insns, when you have a chance: #{TestJIT.untested_insns.join(' ')}"
end
end
@@ -242,8 +243,8 @@ class TestJIT < Test::Unit::TestCase
end;
end
- def test_compile_insn_putstring_concatstrings_tostring
- assert_compile_once('"a#{}b" + "c"', result_inspect: '"abc"', insns: %i[putstring concatstrings tostring])
+ def test_compile_insn_putstring_concatstrings_objtostring
+ assert_compile_once('"a#{}b" + "c"', result_inspect: '"abc"', insns: %i[putstring concatstrings objtostring])
end
def test_compile_insn_toregexp
@@ -481,8 +482,8 @@ class TestJIT < Test::Unit::TestCase
end;
end
- def test_compile_insn_checktype
- assert_compile_once("#{<<~"begin;"}\n#{<<~'end;'}", result_inspect: '"42"', insns: %i[checktype])
+ def test_compile_insn_objtostring
+ assert_compile_once("#{<<~"begin;"}\n#{<<~'end;'}", result_inspect: '"42"', insns: %i[objtostring])
begin;
a = '2'
"4#{a}"
@@ -608,6 +609,17 @@ class TestJIT < Test::Unit::TestCase
assert_eval_with_jit('print "\x00".unpack("c")', stdout: '[0]', success_count: 1)
end
+ def test_compile_insn_checkmatch
+ assert_compile_once("#{<<~"begin;"}\n#{<<~"end;"}", result_inspect: '"world"', insns: %i[checkmatch])
+ begin;
+ ary = %w(hello good-bye)
+ case 'hello'
+ when *ary
+ 'world'
+ end
+ end;
+ end
+
def test_jit_output
out, err = eval_with_jit('5.times { puts "MJIT" }', verbose: 1, min_calls: 5)
assert_equal("MJIT\n" * 5, out)
@@ -1219,7 +1231,9 @@ class TestJIT < Test::Unit::TestCase
end
def mark_tested_insn(insn, used_insns:, uplevel: 1)
- unless used_insns.include?(insn)
+ # Currently, this check emits a false-positive warning against opt_regexpmatch2,
+ # so the insn is excluded explicitly. See https://bugs.ruby-lang.org/issues/18269
+ if !used_insns.include?(insn) && insn != :opt_regexpmatch2
$stderr.puts
warn "'#{insn}' insn is not included in the script. Actual insns are: #{used_insns.join(' ')}\n", uplevel: uplevel
end
diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb
index 3a8ff7857f2..8c3256c0346 100644
--- a/test/ruby/test_literal.rb
+++ b/test/ruby/test_literal.rb
@@ -474,6 +474,17 @@ class TestRubyLiteral < Test::Unit::TestCase
assert_nil(h['c'])
assert_equal(nil, h.key('300'))
+ a = []
+ h = EnvUtil.suppress_warning do
+ eval <<~end
+ # This is a syntax that renders warning at very early stage.
+ # eval used to delay warning, to be suppressible by EnvUtil.
+ {"a" => a.push(100).last, "b" => a.push(200).last, "a" => a.push(300).last, "a" => a.push(400).last}
+ end
+ end
+ assert_equal({'a' => 400, 'b' => 200}, h)
+ assert_equal([100, 200, 300, 400], a)
+
assert_all_assertions_foreach(
"duplicated literal key",
':foo',
diff --git a/test/ruby/test_m17n.rb b/test/ruby/test_m17n.rb
index 3f28d55ac1a..c793520ac4a 100644
--- a/test/ruby/test_m17n.rb
+++ b/test/ruby/test_m17n.rb
@@ -299,6 +299,9 @@ class TestM17N < Test::Unit::TestCase
orig_v, $VERBOSE = $VERBOSE, false
orig_int, Encoding.default_internal = Encoding.default_internal, nil
orig_ext = Encoding.default_external
+
+ skip "https://bugs.ruby-lang.org/issues/18338"
+
o = Object.new
Encoding.default_external = Encoding::UTF_16BE
@@ -1331,8 +1334,8 @@ class TestM17N < Test::Unit::TestCase
env_encoding = Encoding.find("locale")
end
ENV.each {|k, v|
- assert_equal(env_encoding, k.encoding, k)
- assert_equal(env_encoding, v.encoding, v)
+ assert_equal(env_encoding, k.encoding, proc {"key(#{k.encoding})=#{k.dump}"})
+ assert_equal(env_encoding, v.encoding, proc {"key(#{k.encoding})=#{k.dump}\n" "value(#{v.encoding})=#{v.dump}"})
}
end
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index a0d9d96a1f2..361d18dd4b4 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -806,8 +806,26 @@ class TestMarshal < Test::Unit::TestCase
def test_marshal_with_ruby2_keywords_hash
flagged_hash = ruby2_keywords_hash(key: 42)
- hash = Marshal.load(Marshal.dump(flagged_hash))
+ data = Marshal.dump(flagged_hash)
+ hash = Marshal.load(data)
assert_equal(42, ruby2_keywords_test(*[hash]))
+
+ hash2 = Marshal.load(data.sub(/\x06K(?=T\z)/, "\x08KEY"))
+ assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
+ ruby2_keywords_test(*[hash2])
+ }
+ hash2 = Marshal.load(data.sub(/:\x06K(?=T\z)/, "I\\&\x06:\x0dencoding\"\x0aUTF-7"))
+ assert_raise(ArgumentError, /\(given 1, expected 0\)/) {
+ ruby2_keywords_test(*[hash2])
+ }
+ end
+
+ def test_invalid_byte_sequence_symbol
+ data = Marshal.dump(:K)
+ data = data.sub(/:\x06K/, "I\\&\x06:\x0dencoding\"\x0dUTF-16LE")
+ assert_raise(ArgumentError, /UTF-16LE: "\\x4B"/) {
+ Marshal.load(data)
+ }
end
def exception_test
@@ -840,4 +858,73 @@ class TestMarshal < Test::Unit::TestCase
assert_nil(e2.backtrace_locations) # temporal
end
end
+
+ class TestMarshalFreezeProc < Test::Unit::TestCase
+ include MarshalTestLib
+
+ def encode(o)
+ Marshal.dump(o)
+ end
+
+ def decode(s)
+ Marshal.load(s, :freeze.to_proc)
+ end
+ end
+
+ def _test_hash_compared_by_identity(h)
+ h.compare_by_identity
+ h["a" + "0"] = 1
+ h["a" + "0"] = 2
+ h = Marshal.load(Marshal.dump(h))
+ assert_predicate(h, :compare_by_identity?)
+ a = h.to_a
+ assert_equal([["a0", 1], ["a0", 2]], a.sort)
+ assert_not_same(a[1][0], a[0][0])
+ end
+
+ def test_hash_compared_by_identity
+ _test_hash_compared_by_identity(Hash.new)
+ end
+
+ def test_hash_default_compared_by_identity
+ _test_hash_compared_by_identity(Hash.new(true))
+ end
+
+ class TestMarshalFreeze < Test::Unit::TestCase
+ include MarshalTestLib
+
+ def encode(o)
+ Marshal.dump(o)
+ end
+
+ def decode(s)
+ Marshal.load(s, freeze: true)
+ end
+
+ def test_return_objects_are_frozen
+ source = ["foo", {}, /foo/, 1..2]
+ objects = decode(encode(source))
+ assert_equal source, objects
+ assert_predicate objects, :frozen?
+ objects.each do |obj|
+ assert_predicate obj, :frozen?
+ end
+ end
+
+ def test_proc_returned_object_are_not_frozen
+ source = ["foo", {}, /foo/, 1..2]
+ objects = Marshal.load(encode(source), ->(o) { o.dup }, freeze: true)
+ assert_equal source, objects
+ refute_predicate objects, :frozen?
+ objects.each do |obj|
+ refute_predicate obj, :frozen?
+ end
+ end
+
+ def test_modules_and_classes_are_not_frozen
+ _objects = Marshal.load(encode([Object, Kernel]), freeze: true)
+ refute_predicate Object, :frozen?
+ refute_predicate Kernel, :frozen?
+ end
+ end
end
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 385d8dddfe0..e1524a5d815 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -446,6 +446,35 @@ class TestModule < Test::Unit::TestCase
end
end
+ class Bug18185 < Module
+ module InstanceMethods
+ end
+ attr_reader :ancestor_list
+ def initialize
+ @ancestor_list = ancestors
+ include InstanceMethods
+ end
+ class Foo
+ attr_reader :key
+ def initialize(key:)
+ @key = key
+ end
+ end
+ end
+
+ def test_module_subclass_initialize
+ mod = Bug18185.new
+ c = Class.new(Bug18185::Foo) do
+ include mod
+ end
+ anc = c.ancestors
+ assert_include(anc, mod)
+ assert_equal(1, anc.count(BasicObject), ->{anc.inspect})
+ b = c.new(key: 1)
+ assert_equal(1, b.key)
+ assert_not_include(mod.ancestor_list, BasicObject)
+ end
+
def test_dup
OtherSetup.call
@@ -985,6 +1014,28 @@ class TestModule < Test::Unit::TestCase
assert_raise(NoMethodError, /protected method/) {o.aClass2}
end
+ def test_visibility_method_return_value
+ no_arg_results = nil
+ c = Module.new do
+ singleton_class.send(:public, :public, :private, :protected, :module_function)
+ def foo; end
+ def bar; end
+ no_arg_results = [public, private, protected, module_function]
+ end
+
+ assert_equal([nil]*4, no_arg_results)
+
+ assert_equal(:foo, c.private(:foo))
+ assert_equal(:foo, c.public(:foo))
+ assert_equal(:foo, c.protected(:foo))
+ assert_equal(:foo, c.module_function(:foo))
+
+ assert_equal([:foo, :bar], c.private(:foo, :bar))
+ assert_equal([:foo, :bar], c.public(:foo, :bar))
+ assert_equal([:foo, :bar], c.protected(:foo, :bar))
+ assert_equal([:foo, :bar], c.module_function(:foo, :bar))
+ end
+
def test_s_constants
c1 = Module.constants
Object.module_eval "WALTER = 99"
diff --git a/test/ruby/test_objectspace.rb b/test/ruby/test_objectspace.rb
index 24a190b2dfc..e0f9eecd119 100644
--- a/test/ruby/test_objectspace.rb
+++ b/test/ruby/test_objectspace.rb
@@ -219,7 +219,7 @@ End
assert_same(new_obj, found[0])
end
- def test_each_object_no_gabage
+ def test_each_object_no_garbage
assert_separately([], <<-End)
GC.disable
eval('begin; 1.times{}; rescue; ensure; end')
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 2075bf35136..a8349967888 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -150,6 +150,18 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_redefine_method('String', '-@', 'assert_nil(-"foo")')
end
+ def test_array_min
+ assert_equal 1, [1, 2, 4].min
+ assert_redefine_method('Array', 'min', 'assert_nil([1, 2, 4].min)')
+ assert_redefine_method('Array', 'min', 'assert_nil([1 + 0, 2, 4].min)')
+ end
+
+ def test_array_max
+ assert_equal 4, [1, 2, 4].max
+ assert_redefine_method('Array', 'max', 'assert_nil([1, 2, 4].max)')
+ assert_redefine_method('Array', 'max', 'assert_nil([1 + 0, 2, 4].max)')
+ end
+
def test_trace_optimized_methods
bug14870 = "[ruby-core:87638]"
expected = [:-@, :max, :min, :+, :-, :*, :/, :%, :==, :<, :<=, :>, :>=, :<<,
@@ -891,4 +903,34 @@ class TestRubyOptimization < Test::Unit::TestCase
raise "END"
end;
end
+
+ class Objtostring
+ end
+
+ def test_objtostring
+ assert_raise(NoMethodError){"#{BasicObject.new}"}
+ assert_redefine_method('Symbol', 'to_s', <<-'end')
+ assert_match %r{\A#<Symbol:0x[0-9a-f]+>\z}, "#{:foo}"
+ end
+ assert_redefine_method('NilClass', 'to_s', <<-'end')
+ assert_match %r{\A#<NilClass:0x[0-9a-f]+>\z}, "#{nil}"
+ end
+ assert_redefine_method('TrueClass', 'to_s', <<-'end')
+ assert_match %r{\A#<TrueClass:0x[0-9a-f]+>\z}, "#{true}"
+ end
+ assert_redefine_method('FalseClass', 'to_s', <<-'end')
+ assert_match %r{\A#<FalseClass:0x[0-9a-f]+>\z}, "#{false}"
+ end
+ assert_redefine_method('Integer', 'to_s', <<-'end')
+ (-1..10).each { |i|
+ assert_match %r{\A#<Integer:0x[0-9a-f]+>\z}, "#{i}"
+ }
+ end
+ assert_equal "TestRubyOptimization::Objtostring", "#{Objtostring}"
+ assert_match %r{\A#<Class:0x[0-9a-f]+>\z}, "#{Class.new}"
+ assert_match %r{\A#<Module:0x[0-9a-f]+>\z}, "#{Module.new}"
+ o = Object.new
+ def o.to_s; 1; end
+ assert_match %r{\A#<Object:0x[0-9a-f]+>\z}, "#{o}"
+ end
end
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index c9ca9c3dfd4..9738f82b7e2 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -638,6 +638,14 @@ EXPECTED
end;
end
+ def test_bug_18343
+ bug18343 = '[ruby-core:106096] [Bug #18343]'
+ assert_separately(%W[- #{bug18343}], <<-'end;')
+ bug = ARGV.shift
+ assert_raise(ArgumentError, bug){[0].pack('c', {})}
+ end;
+ end
+
def test_pack_unpack_m0
assert_equal("", [""].pack("m0"))
assert_equal("AA==", ["\0"].pack("m0"))
@@ -869,4 +877,30 @@ EXPECTED
assert_equal "hogefuga", "aG9nZWZ1Z2E=".unpack1("m")
assert_equal "01000001", "A".unpack1("B*")
end
+
+ def test_unpack1_offset
+ assert_equal 65, "ZA".unpack1("C", offset: 1)
+ assert_equal "01000001", "YZA".unpack1("B*", offset: 2)
+ assert_nil "abc".unpack1("C", offset: 3)
+ assert_raise_with_message(ArgumentError, /offset can't be negative/) {
+ "a".unpack1("C", offset: -1)
+ }
+ assert_raise_with_message(ArgumentError, /offset outside of string/) {
+ "a".unpack1("C", offset: 2)
+ }
+ assert_nil "a".unpack1("C", offset: 1)
+ end
+
+ def test_unpack_offset
+ assert_equal [65], "ZA".unpack("C", offset: 1)
+ assert_equal ["01000001"], "YZA".unpack("B*", offset: 2)
+ assert_equal [nil, nil, nil], "abc".unpack("CCC", offset: 3)
+ assert_raise_with_message(ArgumentError, /offset can't be negative/) {
+ "a".unpack("C", offset: -1)
+ }
+ assert_raise_with_message(ArgumentError, /offset outside of string/) {
+ "a".unpack("C", offset: 2)
+ }
+ assert_equal [nil], "a".unpack("C", offset: 1)
+ end
end
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 625b6eb2234..d697a29c1c8 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1044,7 +1044,7 @@ x = __ENCODING__
end;
assert_syntax_error("def\nf(000)end", /^ \^~~/)
- assert_syntax_error("def\nf(&)end", /^ \^/)
+ assert_syntax_error("def\nf(&0)end", /^ \^/)
end
def test_method_location_in_rescue
@@ -1162,6 +1162,10 @@ x = __ENCODING__
assert_syntax_error("def m\n\C-z""end", /unexpected/)
end
+ def test_unexpected_eof
+ assert_syntax_error('unless', /^ \^\Z/)
+ end
+
def test_location_of_invalid_token
assert_syntax_error('class xxx end', /^ \^~~\Z/)
end
@@ -1227,10 +1231,12 @@ x = __ENCODING__
assert_valid_syntax('let () { m(a) do; end }')
end
- def test_void_value_in_command_rhs
+ def test_void_value_in_rhs
w = "void value expression"
- ex = assert_syntax_error("x = return 1", w)
- assert_equal(1, ex.message.scan(w).size, "same #{w.inspect} warning should be just once")
+ ["x = return 1", "x = return, 1", "x = 1, return", "x, y = return"].each do |code|
+ ex = assert_syntax_error(code, w)
+ assert_equal(1, ex.message.scan(w).size, ->{"same #{w.inspect} warning should be just once\n#{w.message}"})
+ end
end
def eval_separately(code)
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb
index 277a0dcc518..35c41eb8b65 100644
--- a/test/ruby/test_pattern_matching.rb
+++ b/test/ruby/test_pattern_matching.rb
@@ -4,6 +4,25 @@ require 'test/unit'
experimental, Warning[:experimental] = Warning[:experimental], false # suppress "warning: Pattern matching is experimental, and the behavior may change in future versions of Ruby!"
eval "\n#{<<~'END_of_GUARD'}", binding, __FILE__, __LINE__
class TestPatternMatching < Test::Unit::TestCase
+ class NullFormatter
+ def message_for(corrections)
+ ""
+ end
+ end
+
+ def setup
+ if defined?(DidYouMean)
+ @original_formatter = DidYouMean.formatter
+ DidYouMean.formatter = NullFormatter.new
+ end
+ end
+
+ def teardown
+ if defined?(DidYouMean)
+ DidYouMean.formatter = @original_formatter
+ end
+ end
+
class C
class << self
attr_accessor :keys
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index 16efd13d7c5..51872e49beb 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1597,18 +1597,24 @@ class TestProc < Test::Unit::TestCase
def test_isolate
assert_raise_with_message ArgumentError, /\(a\)/ do
a = :a
- Proc.new{p a}.isolate.call
+ Proc.new{p a}.isolate
end
assert_raise_with_message ArgumentError, /\(a\)/ do
a = :a
1.times{
- Proc.new{p a}.isolate.call
+ Proc.new{p a}.isolate
}
end
assert_raise_with_message ArgumentError, /yield/ do
- Proc.new{yield}.isolate.call
+ Proc.new{yield}.isolate
+ end
+
+
+ name = "\u{2603 26a1}"
+ assert_raise_with_message(ArgumentError, /\(#{name}\)/) do
+ eval("#{name} = :#{name}; Proc.new {p #{name}}").isolate
end
# binding
diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb
index 07aa58418b7..636871f8223 100644
--- a/test/ruby/test_process.rb
+++ b/test/ruby/test_process.rb
@@ -1732,6 +1732,9 @@ class TestProcess < Test::Unit::TestCase
end
def test_no_curdir
+ if /solaris/i =~ RUBY_PLATFORM
+ skip "Temporary skip to avoid CI failures after commit to use realpath on required files"
+ end
with_tmpchdir {|d|
Dir.mkdir("vd")
status = nil
@@ -2542,4 +2545,96 @@ EOS
end
assert_empty(Process.waitall)
end
+
+ def test__fork
+ r, w = IO.pipe
+ pid = Process._fork
+ if pid == 0
+ begin
+ r.close
+ w << "ok: #$$"
+ w.close
+ ensure
+ exit!
+ end
+ else
+ w.close
+ assert_equal("ok: #{pid}", r.read)
+ r.close
+ Process.waitpid(pid)
+ end
+ end if Process.respond_to?(:_fork)
+
+ def test__fork_hook
+ %w(fork Process.fork).each do |method|
+ feature17795 = '[ruby-core:103400] [Feature #17795]'
+ assert_in_out_err([], <<-"end;", [], [], feature17795, timeout: 60) do |r, e|
+ module ForkHook
+ def _fork
+ p :before
+ ret = super
+ p :after
+ ret
+ end
+ end
+
+ Process.singleton_class.prepend(ForkHook)
+
+ pid = #{ method }
+ p pid
+ Process.waitpid(pid) if pid
+ end;
+ assert_equal([], e)
+ assert_equal(":before", r.shift)
+ assert_equal(":after", r.shift)
+ s = r.map {|s| s.chomp }.sort #=> [pid, ":after", "nil"]
+ assert_match(/^\d+$/, s[0]) # pid
+ assert_equal(":after", s[1])
+ assert_equal("nil", s[2])
+ end
+ end
+ end if Process.respond_to?(:_fork)
+
+ def test__fork_hook_popen
+ feature17795 = '[ruby-core:103400] [Feature #17795]'
+ assert_in_out_err([], <<-"end;", %w(:before :after :after foo bar), [], feature17795, timeout: 60)
+ module ForkHook
+ def _fork
+ p :before
+ ret = super
+ p :after
+ ret
+ end
+ end
+
+ Process.singleton_class.prepend(ForkHook)
+
+ IO.popen("-") {|io|
+ if !io
+ puts "foo"
+ else
+ puts io.read + "bar"
+ end
+ }
+ end;
+ end if Process.respond_to?(:_fork)
+
+ def test__fork_wrong_type_hook
+ feature17795 = '[ruby-core:103400] [Feature #17795]'
+ assert_in_out_err([], <<-"end;", ["OK"], [], feature17795, timeout: 60)
+ module ForkHook
+ def _fork
+ "BOO"
+ end
+ end
+
+ Process.singleton_class.prepend(ForkHook)
+
+ begin
+ fork
+ rescue TypeError
+ puts "OK"
+ end
+ end;
+ end if Process.respond_to?(:_fork)
end
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index a623432cf14..19857b035c0 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -747,6 +747,13 @@ class TestRefinement < Test::Unit::TestCase
end
end
+ def self.suppress_verbose
+ verbose, $VERBOSE = $VERBOSE, nil
+ yield
+ ensure
+ $VERBOSE = verbose
+ end
+
module IncludeIntoRefinement
class C
def bar
@@ -774,7 +781,9 @@ class TestRefinement < Test::Unit::TestCase
module M
refine C do
- include Mixin
+ TestRefinement.suppress_verbose do
+ include Mixin
+ end
def baz
return super << " M#baz"
@@ -837,7 +846,9 @@ class TestRefinement < Test::Unit::TestCase
module M
refine C do
- prepend Mixin
+ TestRefinement.suppress_verbose do
+ prepend Mixin
+ end
def baz
return super << " M#baz"
@@ -2537,6 +2548,25 @@ class TestRefinement < Test::Unit::TestCase
assert_equal(:second, klass.new.foo)
end
+ class Bug18180
+ module M
+ refine Array do
+ def min; :min; end
+ def max; :max; end
+ end
+ end
+
+ using M
+
+ def t
+ [[1+0, 2, 4].min, [1, 2, 4].min, [1+0, 2, 4].max, [1, 2, 4].max]
+ end
+ end
+
+ def test_refine_array_min_max
+ assert_equal([:min, :min, :max, :max], Bug18180.new.t)
+ end
+
class Bug17822
module Ext
refine(Bug17822) do
@@ -2571,6 +2601,77 @@ class TestRefinement < Test::Unit::TestCase
assert_equal([refinement], as, "[ruby-core:86949] [Bug #14744]")
end
+ module TestImport
+ class A
+ def foo
+ "original"
+ end
+ end
+
+ module B
+ BAR = "bar"
+
+ def bar
+ "#{foo}:#{BAR}"
+ end
+ end
+
+ module C
+ refine A do
+ import_methods B
+
+ def foo
+ "refined"
+ end
+ end
+ end
+
+ module D
+ refine A do
+ TestRefinement.suppress_verbose do
+ include B
+ end
+
+ def foo
+ "refined"
+ end
+ end
+ end
+
+ module UsingC
+ using C
+
+ def self.call_bar
+ A.new.bar
+ end
+ end
+
+ module UsingD
+ using D
+
+ def self.call_bar
+ A.new.bar
+ end
+ end
+ end
+
+ def test_import_methods
+ assert_equal("refined:bar", TestImport::UsingC.call_bar)
+ assert_equal("original:bar", TestImport::UsingD.call_bar)
+
+ assert_raise(ArgumentError) do
+ Module.new do
+ refine Integer do
+ import_methods Enumerable
+ end
+ end
+ end
+ end
+
+ def test_inherit_singleton_methods_of_module
+ assert_equal([], Refinement.used_modules)
+ end
+
private
def eval_using(mod, s)
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 7c76f5c1509..2bf4649f144 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -265,6 +265,27 @@ class TestRegexp < Test::Unit::TestCase
assert_equal(re, re.match("foo").regexp)
end
+ def test_match_lambda_multithread
+ bug17507 = "[ruby-core:101901]"
+ str = "a-x-foo-bar-baz-z-b"
+
+ worker = lambda do
+ m = /foo-([A-Za-z0-9_\.]+)-baz/.match(str)
+ assert_equal("bar", m[1], bug17507)
+
+ # These two lines are needed to trigger the bug
+ File.exist? "/tmp"
+ str.gsub(/foo-bar-baz/, "foo-abc-baz")
+ end
+
+ def self. threaded_test(worker)
+ 6.times.map {Thread.new {10_000.times {worker.call}}}.each(&:join)
+ end
+
+ # The bug only occurs in a method calling a block/proc/lambda
+ threaded_test(worker)
+ end
+
def test_source
bug5484 = '[ruby-core:40364]'
assert_equal('', //.source)
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index 401b274ef62..77cdae64d9e 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -367,6 +367,38 @@ class TestRequire < Test::Unit::TestCase
}
end
+ def test_load_into_module
+ Tempfile.create(["test_ruby_test_require", ".rb"]) {|t|
+ t.puts "def b; 1 end"
+ t.puts "class Foo"
+ t.puts " def c; 2 end"
+ t.puts "end"
+ t.close
+
+ m = Module.new
+ load(t.path, m)
+ assert_equal([:b], m.private_instance_methods(false))
+ c = Class.new do
+ include m
+ public :b
+ end
+ assert_equal(1, c.new.b)
+ assert_equal(2, m::Foo.new.c)
+ }
+ end
+
+ def test_load_wrap_nil
+ Dir.mktmpdir do |tmp|
+ File.write("#{tmp}/1.rb", "class LoadWrapNil; end\n")
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ path = ""#{tmp.dump}"/1.rb"
+ begin;
+ load path, nil
+ assert_instance_of(Class, LoadWrapNil)
+ end;
+ end
+ end
+
def test_load_ospath
bug = '[ruby-list:49994] path in ospath'
base = "test_load\u{3042 3044 3046 3048 304a}".encode(Encoding::Windows_31J)
@@ -434,6 +466,32 @@ class TestRequire < Test::Unit::TestCase
}
end
+ def test_relative_symlink_realpath
+ Dir.mktmpdir {|tmp|
+ Dir.chdir(tmp) {
+ Dir.mkdir "a"
+ File.open("a/a.rb", "w") {|f| f.puts 'require_relative "b"' }
+ File.open("a/b.rb", "w") {|f| f.puts '$t += 1' }
+ Dir.mkdir "b"
+ File.binwrite("c.rb", <<~RUBY)
+ $t = 0
+ $:.unshift(File.expand_path('../b', __FILE__))
+ require "b"
+ require "a"
+ print $t
+ RUBY
+ begin
+ File.symlink("../a/a.rb", "b/a.rb")
+ File.symlink("../a/b.rb", "b/b.rb")
+ result = IO.popen([EnvUtil.rubybin, "c.rb"], &:read)
+ assert_equal("1", result, "bug17885 [ruby-core:104010]")
+ rescue NotImplementedError, Errno::EACCES
+ skip "File.symlink is not implemented"
+ end
+ }
+ }
+ end
+
def test_frozen_loaded_features
bug3756 = '[ruby-core:31913]'
assert_in_out_err(['-e', '$LOADED_FEATURES.freeze; require "ostruct"'], "",
@@ -531,6 +589,28 @@ class TestRequire < Test::Unit::TestCase
$".replace(features)
end
+ def test_default_loaded_features_encoding
+ Dir.mktmpdir {|tmp|
+ Dir.mkdir("#{tmp}/1")
+ Dir.mkdir("#{tmp}/2")
+ File.write("#{tmp}/1/bug18191-1.rb", "")
+ File.write("#{tmp}/2/bug18191-2.rb", "")
+ assert_separately(%W[-Eutf-8 -I#{tmp}/1 -], "#{<<~"begin;"}\n#{<<~'end;'}")
+ tmp = #{tmp.dump}"/2"
+ begin;
+ $:.unshift(tmp)
+ require "bug18191-1"
+ require "bug18191-2"
+ encs = [Encoding::US_ASCII, Encoding.find("filesystem")]
+ message = -> {
+ require "pp"
+ {filesystem: encs[1], **$".group_by(&:encoding)}.pretty_inspect
+ }
+ assert($".all? {|n| encs.include?(n.encoding)}, message)
+ end;
+ }
+ end
+
def test_require_changed_current_dir
bug7158 = '[ruby-core:47970]'
Dir.mktmpdir {|tmp|
@@ -711,8 +791,8 @@ class TestRequire < Test::Unit::TestCase
assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], "#{<<~"begin;"}\n#{<<~"end;"}", %w(:ok), [], bug7530, timeout: 60)
begin;
PATH = ARGV.shift
- THREADS = 4
- ITERATIONS_PER_THREAD = 1000
+ THREADS = 30
+ ITERATIONS_PER_THREAD = 300
THREADS.times.map {
Thread.new do
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index e26a24e8ada..b4080010e24 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -7,9 +7,13 @@ require 'tempfile'
require_relative '../lib/jit_support'
class TestRubyOptions < Test::Unit::TestCase
+ def self.yjit_enabled? = defined?(RubyVM::YJIT.enabled?) && RubyVM::YJIT.enabled?
+
NO_JIT_DESCRIPTION =
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
RUBY_DESCRIPTION.sub(/\+JIT /, '')
+ elsif yjit_enabled? # checking -DYJIT_FORCE_ENABLE
+ RUBY_DESCRIPTION.sub(/\+YJIT /, '')
else
RUBY_DESCRIPTION
end
@@ -140,10 +144,12 @@ class TestRubyOptions < Test::Unit::TestCase
private_constant :VERSION_PATTERN_WITH_JIT
def test_verbose
- assert_in_out_err(["-vve", ""]) do |r, e|
+ assert_in_out_err([{'RUBY_YJIT_ENABLE' => nil}, "-vve", ""]) do |r, e|
assert_match(VERSION_PATTERN, r[0])
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? && !mjit_force_enabled? # checking -DMJIT_FORCE_ENABLE
assert_equal(NO_JIT_DESCRIPTION, r[0])
+ elsif self.class.yjit_enabled? && !yjit_force_enabled? # checking -DYJIT_FORCE_ENABLE
+ assert_equal(NO_JIT_DESCRIPTION, r[0])
else
assert_equal(RUBY_DESCRIPTION, r[0])
end
@@ -203,9 +209,12 @@ class TestRubyOptions < Test::Unit::TestCase
end
def test_version
- assert_in_out_err(%w(--version)) do |r, e|
+ env = {'RUBY_YJIT_ENABLE' => nil} # unset in children
+ assert_in_out_err([env, '--version']) do |r, e|
assert_match(VERSION_PATTERN, r[0])
- if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
+ if ENV['RUBY_YJIT_ENABLE'] == '1'
+ assert_equal(NO_JIT_DESCRIPTION, r[0])
+ elsif defined?(RubyVM::JIT) && RubyVM::JIT.enabled? || self.class.yjit_enabled? # checking -D(M|Y)JIT_FORCE_ENABLE
assert_equal(EnvUtil.invoke_ruby(['-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
else
assert_equal(RUBY_DESCRIPTION, r[0])
@@ -214,13 +223,14 @@ class TestRubyOptions < Test::Unit::TestCase
end
return if RbConfig::CONFIG["MJIT_SUPPORT"] == 'no'
+ return if yjit_force_enabled?
[
%w(--version --jit --disable=jit),
%w(--version --enable=jit --disable=jit),
%w(--version --enable-jit --disable-jit),
].each do |args|
- assert_in_out_err(args) do |r, e|
+ assert_in_out_err([env] + args) do |r, e|
assert_match(VERSION_PATTERN, r[0])
assert_match(NO_JIT_DESCRIPTION, r[0])
assert_equal([], e)
@@ -233,12 +243,12 @@ class TestRubyOptions < Test::Unit::TestCase
%w(--version --enable=jit),
%w(--version --enable-jit),
].each do |args|
- assert_in_out_err(args) do |r, e|
+ assert_in_out_err([env] + args) do |r, e|
assert_match(VERSION_PATTERN_WITH_JIT, r[0])
if defined?(RubyVM::JIT) && RubyVM::JIT.enabled? # checking -DMJIT_FORCE_ENABLE
assert_equal(RUBY_DESCRIPTION, r[0])
else
- assert_equal(EnvUtil.invoke_ruby(['--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
+ assert_equal(EnvUtil.invoke_ruby([env, '--jit', '-e', 'print RUBY_DESCRIPTION'], '', true).first, r[0])
end
assert_equal([], e)
end
@@ -1103,7 +1113,7 @@ class TestRubyOptions < Test::Unit::TestCase
# mswin uses prebuilt precompiled header. Thus it does not show a pch compilation log to check "-O0 -O1".
if JITSupport.supported? && !RUBY_PLATFORM.match?(/mswin/)
env = { 'MJIT_SEARCH_BUILD_DIR' => 'true' }
- assert_in_out_err([env, "--jit-debug=-O0 -O1", "--jit-verbose=2", "" ], "", [], /-O0 -O1/)
+ assert_in_out_err([env, "--disable-yjit", "--jit-debug=-O0 -O1", "--jit-verbose=2", "" ], "", [], /-O0 -O1/)
end
end
@@ -1112,4 +1122,8 @@ class TestRubyOptions < Test::Unit::TestCase
def mjit_force_enabled?
"#{RbConfig::CONFIG['CFLAGS']} #{RbConfig::CONFIG['CPPFLAGS']}".match?(/(\A|\s)-D ?MJIT_FORCE_ENABLE\b/)
end
+
+ def yjit_force_enabled?
+ "#{RbConfig::CONFIG['CFLAGS']} #{RbConfig::CONFIG['CPPFLAGS']}".match?(/(\A|\s)-D ?YJIT_FORCE_ENABLE\b/)
+ end
end
diff --git a/test/ruby/test_rubyvm.rb b/test/ruby/test_rubyvm.rb
index 67d46e27adb..7d4588a165c 100644
--- a/test/ruby/test_rubyvm.rb
+++ b/test/ruby/test_rubyvm.rb
@@ -15,4 +15,57 @@ class TestRubyVM < Test::Unit::TestCase
assert_raise(ArgumentError){ RubyVM.stat(:unknown) }
assert_raise_with_message(ArgumentError, /\u{30eb 30d3 30fc}/) {RubyVM.stat(:"\u{30eb 30d3 30fc}")}
end
+
+ def parse_and_compile
+ script = <<~RUBY
+ _a = 1
+ def foo
+ _b = 2
+ end
+ 1.times{
+ _c = 3
+ }
+ RUBY
+
+ ast = RubyVM::AbstractSyntaxTree.parse(script)
+ iseq = RubyVM::InstructionSequence.compile(script)
+
+ [ast, iseq]
+ end
+
+ def test_keep_script_lines
+ prev_conf = RubyVM.keep_script_lines
+
+ # keep
+ RubyVM.keep_script_lines = true
+
+ ast, iseq = *parse_and_compile
+
+ lines = ast.script_lines
+ assert_equal Array, lines.class
+
+ lines = iseq.script_lines
+ assert_equal Array, lines.class
+ iseq.each_child{|child|
+ assert_equal lines, child.script_lines
+ }
+ assert lines.frozen?
+
+ # don't keep
+ RubyVM.keep_script_lines = false
+
+ ast, iseq = *parse_and_compile
+
+ lines = ast.script_lines
+ assert_equal nil, lines
+
+ lines = iseq.script_lines
+ assert_equal nil, lines
+ iseq.each_child{|child|
+ assert_equal lines, child.script_lines
+ }
+
+ ensure
+ RubyVM.keep_script_lines = prev_conf
+ end
end
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 88488aef5c4..d737c84af5e 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -393,7 +393,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
[["c-return", 3, :set_trace_func, Kernel],
["line", 6, __method__, self.class],
["call", 1, :foobar, FooBar],
- ["return", 6, :foobar, FooBar],
+ ["return", 1, :foobar, FooBar],
["line", 7, __method__, self.class],
["c-call", 7, :set_trace_func, Kernel]].each{|e|
assert_equal(e, events.shift)
@@ -564,6 +564,16 @@ class TestSetTraceFunc < Test::Unit::TestCase
}
end
+ # Bug #18264
+ def test_tracepoint_memory_leak
+ assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true)
+code = proc { TracePoint.new(:line) { } }
+1_000.times(&code)
+PREP
+1_000_000.times(&code)
+CODE
+ end
+
def trace_by_set_trace_func
events = []
trace = nil
@@ -1941,7 +1951,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
end
define_method(:f_break_defined) do
- return :f_break_defined
+ break :f_break_defined
end
define_method(:f_raise_defined) do
@@ -1962,27 +1972,44 @@ class TestSetTraceFunc < Test::Unit::TestCase
tp_return_value(:f_last_defined),
'[Bug #13369]'
- assert_equal [[:b_return, :f_return_defined, nil], # current limitation
+ assert_equal [[:b_return, :f_return_defined, :f_return_defined],
[:return, :f_return_defined, :f_return_defined]],
tp_return_value(:f_return_defined),
'[Bug #13369]'
- assert_equal [[:b_return, :f_break_defined, nil],
+ assert_equal [[:b_return, :f_break_defined, :f_break_defined],
[:return, :f_break_defined, :f_break_defined]],
tp_return_value(:f_break_defined),
'[Bug #13369]'
- assert_equal [[:b_return, :f_raise_defined, nil],
+ assert_equal [[:b_return, :f_raise_defined, f_raise_defined],
[:return, :f_raise_defined, f_raise_defined]],
tp_return_value(:f_raise_defined),
'[Bug #13369]'
- assert_equal [[:b_return, :f_break_in_rescue_defined, nil],
+ assert_equal [[:b_return, :f_break_in_rescue_defined, f_break_in_rescue_defined],
[:return, :f_break_in_rescue_defined, f_break_in_rescue_defined]],
tp_return_value(:f_break_in_rescue_defined),
'[Bug #13369]'
end
+ define_method(:just_yield) do |&block|
+ block.call
+ end
+
+ define_method(:unwind_multiple_bmethods) do
+ just_yield { return :unwind_multiple_bmethods }
+ end
+
+ def test_non_local_return_across_multiple_define_methods
+ assert_equal [[:b_return, :unwind_multiple_bmethods, nil],
+ [:b_return, :just_yield, nil],
+ [:return, :just_yield, nil],
+ [:b_return, :unwind_multiple_bmethods, :unwind_multiple_bmethods],
+ [:return, :unwind_multiple_bmethods, :unwind_multiple_bmethods]],
+ tp_return_value(:unwind_multiple_bmethods)
+ end
+
def f_iter
yield
end
@@ -2393,6 +2420,99 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_equal Array.new(2){th}, events
end
+ def test_return_bmethod_location
+ bug13392 = "[ruby-core:80515] incorrect bmethod return location"
+ actual = nil
+ obj = Object.new
+ expected = __LINE__ + 1
+ obj.define_singleton_method(:t){}
+ tp = TracePoint.new(:return) do
+ next unless target_thread?
+ actual = tp.lineno
+ end
+ tp.enable {obj.t}
+ assert_equal(expected, actual, bug13392)
+ end
+
+ def test_b_tracepoints_going_away
+ # test that call and return TracePoints continue to work
+ # when b_call and b_return TracePoints stop
+ events = []
+ record_events = ->(tp) do
+ next unless target_thread?
+ events << [tp.event, tp.method_id]
+ end
+
+ call_ret_tp = TracePoint.new(:call, :return, &record_events)
+ block_call_ret_tp = TracePoint.new(:b_call, :b_return, &record_events)
+
+ obj = Object.new
+ obj.define_singleton_method(:foo) {} # a bmethod
+
+ foo = obj.method(:foo)
+ call_ret_tp.enable(target: foo) do
+ block_call_ret_tp.enable(target: foo) do
+ obj.foo
+ end
+ obj.foo
+ end
+
+ assert_equal(
+ [
+ [:call, :foo],
+ [:b_call, :foo],
+ [:b_return, :foo],
+ [:return, :foo],
+ [:call, :foo],
+ [:return, :foo],
+ ],
+ events,
+ )
+ end
+
+ def test_target_different_bmethod_same_iseq
+ # make two bmethods that share the same block iseq
+ block = Proc.new {}
+ obj = Object.new
+ obj.define_singleton_method(:one, &block)
+ obj.define_singleton_method(:two, &block)
+
+ events = []
+ record_events = ->(tp) do
+ next unless target_thread?
+ events << [tp.event, tp.method_id]
+ end
+ tp_one = TracePoint.new(:call, :return, &record_events)
+ tp_two = TracePoint.new(:call, :return, &record_events)
+
+ tp_one.enable(target: obj.method(:one)) do
+ obj.one
+ obj.two # not targeted
+ end
+ assert_equal([[:call, :one], [:return, :one]], events)
+ events.clear
+
+ tp_one.enable(target: obj.method(:one)) do
+ obj.one
+ tp_two.enable(target: obj.method(:two)) do
+ obj.two
+ end
+ obj.two
+ obj.one
+ end
+ assert_equal(
+ [
+ [:call, :one],
+ [:return, :one],
+ [:call, :two],
+ [:return, :two],
+ [:call, :one],
+ [:return, :one],
+ ],
+ events
+ )
+ end
+
def test_return_event_with_rescue
obj = Object.new
def obj.example
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 7986e9d141a..f2e73eb58dc 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -528,19 +528,4 @@ class TestSprintf < Test::Unit::TestCase
sprintf("%*s", RbConfig::LIMITS["INT_MIN"], "")
end
end
-
- def test_no_hidden_garbage
- skip unless Thread.list.size == 1
-
- fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
- ObjectSpace.count_objects(res = {}) # creates strings on first call
- GC.disable
- before = ObjectSpace.count_objects(res)[:T_STRING]
- val = sprintf(fmt, 1970, 1, 1)
- after = ObjectSpace.count_objects(res)[:T_STRING]
- assert_equal before + 1, after, 'only new string is the created one'
- assert_equal '1970-01-01', val
- ensure
- GC.enable
- end
end
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 12e4b0fe2a8..3f7c06e0756 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1180,6 +1180,8 @@ CODE
assert_send([S("hello"), :end_with?, S("llo")])
assert_not_send([S("hello"), :end_with?, S("ll")])
assert_send([S("hello"), :end_with?, S("el"), S("lo")])
+ assert_send([S("hello"), :end_with?, S("")])
+ assert_not_send([S("hello"), :end_with?])
bug5536 = '[ruby-core:40623]'
assert_raise(TypeError, bug5536) {S("str").end_with? :not_convertible_to_string}
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 19577266c74..03016123953 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -489,6 +489,14 @@ module TestStruct
}
end
+ def test_public_send
+ klass = @Struct.new(:a)
+ x = klass.new(1)
+ assert_equal(1, x.public_send("a"))
+ assert_equal(42, x.public_send("a=", 42))
+ assert_equal(42, x.public_send("a"))
+ end
+
class TopStruct < Test::Unit::TestCase
include TestStruct
diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb
index d94f4679d32..6a575b88c51 100644
--- a/test/ruby/test_super.rb
+++ b/test/ruby/test_super.rb
@@ -521,6 +521,43 @@ class TestSuper < Test::Unit::TestCase
assert_equal(%w[B A], result, bug9721)
end
+ # [Bug #18329]
+ def test_super_missing_prepended_module
+ a = Module.new do
+ def probe(*methods)
+ prepend(probing_module(methods))
+ end
+
+ def probing_module(methods)
+ Module.new do
+ methods.each do |method|
+ define_method(method) do |*args, **kwargs, &block|
+ super(*args, **kwargs, &block)
+ end
+ end
+ end
+ end
+ end
+
+ b = Class.new do
+ extend a
+
+ probe :danger!, :missing
+
+ def danger!; end
+ end
+
+ o = b.new
+ o.danger!
+ begin
+ original_gc_stress = GC.stress
+ GC.stress = true
+ 2.times { o.missing rescue NoMethodError }
+ ensure
+ GC.stress = original_gc_stress
+ end
+ end
+
def test_from_eval
bug10263 = '[ruby-core:65122] [Bug #10263a]'
a = Class.new do
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index 8aa169ac0c7..ce1e489992e 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -66,6 +66,18 @@ class TestSyntax < Test::Unit::TestCase
f&.close!
end
+ def test_anonymous_block_forwarding
+ assert_syntax_error("def b; c(&); end", /no anonymous block parameter/)
+ assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
+ begin;
+ def b(&); c(&) end
+ def c(&); yield 1 end
+ a = nil
+ b{|c| a = c}
+ assert_equal(1, a)
+ end;
+ end
+
def test_newline_in_block_parameters
bug = '[ruby-dev:45292]'
["", "a", "a, b"].product(["", ";x", [";", "x"]]) do |params|
@@ -200,17 +212,29 @@ class TestSyntax < Test::Unit::TestCase
bug10315 = '[ruby-core:65625] [Bug #10315]'
a = []
def a.add(x) push(x); x; end
- def a.f(k:) k; end
+ b = a.clone
+ def a.f(k:, **) k; end
+ def b.f(k:) k; end
a.clear
r = nil
- assert_warn(/duplicated/) {r = eval("a.f(k: a.add(1), k: a.add(2))")}
+ assert_warn(/duplicated/) {r = eval("b.f(k: b.add(1), k: b.add(2))")}
assert_equal(2, r)
- assert_equal([1, 2], a, bug10315)
+ assert_equal([1, 2], b, bug10315)
+ b.clear
+ r = nil
+ assert_warn(/duplicated/) {r = eval("a.f(k: a.add(1), j: a.add(2), k: a.add(3), k: a.add(4))")}
+ assert_equal(4, r)
+ assert_equal([1, 2, 3, 4], a)
a.clear
r = nil
- assert_warn(/duplicated/) {r = eval("a.f(**{k: a.add(1), k: a.add(2)})")}
+ assert_warn(/duplicated/) {r = eval("b.f(**{k: b.add(1), k: b.add(2)})")}
assert_equal(2, r)
- assert_equal([1, 2], a, bug10315)
+ assert_equal([1, 2], b, bug10315)
+ b.clear
+ r = nil
+ assert_warn(/duplicated/) {r = eval("a.f(**{k: a.add(1), j: a.add(2), k: a.add(3), k: a.add(4)})")}
+ assert_equal(4, r)
+ assert_equal([1, 2, 3, 4], a)
end
def test_keyword_empty_splat
@@ -1061,19 +1085,19 @@ eom
end
def test_warning_literal_in_condition
- assert_warn(/literal in condition/) do
+ assert_warn(/string literal in condition/) do
eval('1 if ""')
end
- assert_warn(/literal in condition/) do
+ assert_warn(/regex literal in condition/) do
eval('1 if //')
end
assert_warning(/literal in condition/) do
eval('1 if 1')
end
- assert_warning(/literal in condition/) do
+ assert_warning(/symbol literal in condition/) do
eval('1 if :foo')
end
- assert_warning(/literal in condition/) do
+ assert_warning(/symbol literal in condition/) do
eval('1 if :"#{"foo".upcase}"')
end
@@ -1563,6 +1587,7 @@ eom
def test_argument_forwarding
assert_valid_syntax('def foo(...) bar(...) end')
assert_valid_syntax('def foo(...) end')
+ assert_valid_syntax("def foo ...\n bar(...)\nend")
assert_valid_syntax('def ==(...) end')
assert_valid_syntax('def [](...) end')
assert_valid_syntax('def nil(...) end')
@@ -1592,7 +1617,9 @@ eom
[args, kws]
end
end
+ obj4 = obj1.clone
obj1.instance_eval('def foo(...) bar(...) end', __FILE__, __LINE__)
+ obj4.instance_eval("def foo ...\n bar(...)\n""end", __FILE__, __LINE__)
klass = Class.new {
def foo(*args, **kws, &block)
@@ -1621,7 +1648,7 @@ eom
end
obj3.instance_eval('def foo(...) bar(...) end', __FILE__, __LINE__)
- [obj1, obj2, obj3].each do |obj|
+ [obj1, obj2, obj3, obj4].each do |obj|
assert_warning('') {
assert_equal([[1, 2, 3], {k1: 4, k2: 5}], obj.foo(1, 2, 3, k1: 4, k2: 5) {|*x| x})
}
@@ -1754,6 +1781,16 @@ eom
assert_equal [[4, 1, 5, 2], {a: 1}], obj.foo(4, 5, 2, a: 1)
assert_equal [[4, 1, 5, 2, 3], {a: 1}], obj.foo(4, 5, 2, 3, a: 1)
assert_equal [[4, 1, 5, 2, 3], {a: 1}], obj.foo(4, 5, 2, 3, a: 1){|args, kws| [args, kws]}
+
+ obj.singleton_class.send(:remove_method, :foo)
+ obj.instance_eval("def foo a, ...\n bar(a, ...)\n"" end", __FILE__, __LINE__)
+ assert_equal [[4], {}], obj.foo(4)
+ assert_equal [[4, 2], {}], obj.foo(4, 2)
+ assert_equal [[4, 2, 3], {}], obj.foo(4, 2, 3)
+ assert_equal [[4], {a: 1}], obj.foo(4, a: 1)
+ assert_equal [[4, 2], {a: 1}], obj.foo(4, 2, a: 1)
+ assert_equal [[4, 2, 3], {a: 1}], obj.foo(4, 2, 3, a: 1)
+ assert_equal [[4, 2, 3], {a: 1}], obj.foo(4, 2, 3, a: 1){|args, kws| [args, kws]}
end
def test_cdhash
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb
index 19a3529005c..7b37aeb202e 100644
--- a/test/ruby/test_thread.rb
+++ b/test/ruby/test_thread.rb
@@ -235,6 +235,14 @@ class TestThread < Test::Unit::TestCase
t3&.kill&.join
end
+ def test_join_argument_conversion
+ t = Thread.new {}
+ assert_raise(TypeError) {t.join(:foo)}
+
+ limit = Struct.new(:to_f, :count).new(0.05)
+ assert_same(t, t.join(limit))
+ end
+
{ 'FIXNUM_MAX' => RbConfig::LIMITS['FIXNUM_MAX'],
'UINT64_MAX' => RbConfig::LIMITS['UINT64_MAX'],
'INFINITY' => Float::INFINITY
diff --git a/test/ruby/test_thread_cv.rb b/test/ruby/test_thread_cv.rb
index 812c4221bcd..88733419da1 100644
--- a/test/ruby/test_thread_cv.rb
+++ b/test/ruby/test_thread_cv.rb
@@ -89,6 +89,9 @@ class TestThreadConditionVariable < Test::Unit::TestCase
end
assert_equal ["C1", "C1", "C1", "P1", "P2", "C2", "C2", "C2"], result
+ ensure
+ threads.each(&:kill)
+ threads.each(&:join)
end
def test_condvar_wait_deadlock
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index fc21c740789..c629a59c02a 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -37,8 +37,11 @@ class TestTime < Test::Unit::TestCase
end
def test_new
+ assert_equal(Time.new(2000,1,1,0,0,0), Time.new(2000))
+ assert_equal(Time.new(2000,2,1,0,0,0), Time.new("2000", "Feb"))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11))
+ assert_equal(Time.utc(2000,2,29,23,0,0), Time.new(2000, 3, 1, 0, 0, 0, 3600))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, "+11:00"))
assert_equal(Rational(1,2), Time.new(2000,2,10, 11,0,5.5, "+11:00").subsec)
bug4090 = '[ruby-dev:42631]'
@@ -240,6 +243,10 @@ class TestTime < Test::Unit::TestCase
assert_equal(1, Time.at(0, 0.001).nsec)
end
+ def test_at_splat
+ assert_equal(Time.at(1, 2), Time.at(*[1, 2]))
+ end
+
def test_at_with_unit
assert_equal(123456789, Time.at(0, 123456789, :nanosecond).nsec)
assert_equal(123456789, Time.at(0, 123456789, :nsec).nsec)
@@ -1281,22 +1288,6 @@ class TestTime < Test::Unit::TestCase
assert_equal("366", t.strftime("%j"))
end
- def test_strftime_no_hidden_garbage
- skip unless Thread.list.size == 1
-
- fmt = %w(Y m d).map { |x| "%#{x}" }.join('-') # defeats optimization
- t = Time.at(0).getutc
- ObjectSpace.count_objects(res = {}) # creates strings on first call
- GC.disable
- before = ObjectSpace.count_objects(res)[:T_STRING]
- val = t.strftime(fmt)
- after = ObjectSpace.count_objects(res)[:T_STRING]
- assert_equal before + 1, after, 'only new string is the created one'
- assert_equal '1970-01-01', val
- ensure
- GC.enable
- end
-
def test_num_exact_error
bad = EnvUtil.labeled_class("BadValue").new
x = EnvUtil.labeled_class("Inexact") do
diff --git a/test/ruby/test_undef.rb b/test/ruby/test_undef.rb
index e0add7c3aba..074b92be558 100644
--- a/test/ruby/test_undef.rb
+++ b/test/ruby/test_undef.rb
@@ -35,4 +35,20 @@ class TestUndef < Test::Unit::TestCase
end
end
end
+
+ def test_singleton_undef
+ klass = Class.new do
+ def foo
+ :ok
+ end
+ end
+
+ klass.new.foo
+
+ klass.new.instance_eval do
+ undef foo
+ end
+
+ klass.new.foo
+ end
end
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
new file mode 100644
index 00000000000..0106a091661
--- /dev/null
+++ b/test/ruby/test_yjit.rb
@@ -0,0 +1,662 @@
+# frozen_string_literal: true
+require 'test/unit'
+require 'envutil'
+require 'tmpdir'
+
+return unless defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
+
+# Tests for YJIT with assertions on compilation and side exits
+# insipired by the MJIT tests in test/ruby/test_jit.rb
+class TestYJIT < Test::Unit::TestCase
+ def test_yjit_in_ruby_description
+ assert_includes(RUBY_DESCRIPTION, '+YJIT')
+ end
+
+ def test_yjit_in_version
+ [
+ %w(--version --yjit),
+ %w(--version --disable-yjit --yjit),
+ %w(--version --disable-yjit --enable-yjit),
+ %w(--version --disable-yjit --enable=yjit),
+ %w(--version --disable=yjit --yjit),
+ %w(--version --disable=yjit --enable-yjit),
+ %w(--version --disable=yjit --enable=yjit),
+ ].each do |version_args|
+ assert_in_out_err(version_args) do |stdout, stderr|
+ assert_equal(RUBY_DESCRIPTION, stdout.first)
+ assert_equal([], stderr)
+ end
+ end
+ end
+
+ def test_command_line_switches
+ assert_in_out_err('--yjit-', '', [], /invalid option --yjit-/)
+ assert_in_out_err('--yjithello', '', [], /invalid option --yjithello/)
+ assert_in_out_err('--yjit-call-threshold', '', [], /--yjit-call-threshold needs an argument/)
+ assert_in_out_err('--yjit-call-threshold=', '', [], /--yjit-call-threshold needs an argument/)
+ assert_in_out_err('--yjit-greedy-versioning=1', '', [], /warning: argument to --yjit-greedy-versioning is ignored/)
+ end
+
+ def test_yjit_stats_and_v_no_error
+ _stdout, stderr, _status = EnvUtil.invoke_ruby(%w(-v --yjit-stats), '', true, true)
+ refute_includes(stderr, "NoMethodError")
+ end
+
+ def test_enable_from_env_var
+ yjit_child_env = {'RUBY_YJIT_ENABLE' => '1'}
+ assert_in_out_err([yjit_child_env, '--version'], '') do |stdout, stderr|
+ assert_equal(RUBY_DESCRIPTION, stdout.first)
+ assert_equal([], stderr)
+ end
+ assert_in_out_err([yjit_child_env, '-e puts RUBY_DESCRIPTION'], '', [RUBY_DESCRIPTION])
+ assert_in_out_err([yjit_child_env, '-e p RubyVM::YJIT.enabled?'], '', ['true'])
+ end
+
+ def test_compile_setclassvariable
+ script = 'class Foo; def self.foo; @@foo = 1; end; end; Foo.foo'
+ assert_compiles(script, insns: %i[setclassvariable], result: 1)
+ end
+
+ def test_compile_getclassvariable
+ script = 'class Foo; @@foo = 1; def self.foo; @@foo; end; end; Foo.foo'
+ assert_compiles(script, insns: %i[getclassvariable], result: 1)
+ end
+
+ def test_compile_putnil
+ assert_compiles('nil', insns: %i[putnil], result: nil)
+ end
+
+ def test_compile_putobject
+ assert_compiles('true', insns: %i[putobject], result: true)
+ assert_compiles('123', insns: %i[putobject], result: 123)
+ assert_compiles(':foo', insns: %i[putobject], result: :foo)
+ end
+
+ def test_compile_opt_not
+ assert_compiles('!false', insns: %i[opt_not], result: true)
+ assert_compiles('!nil', insns: %i[opt_not], result: true)
+ assert_compiles('!true', insns: %i[opt_not], result: false)
+ assert_compiles('![]', insns: %i[opt_not], result: false)
+ end
+
+ def test_compile_opt_newarray
+ assert_compiles('[]', insns: %i[newarray], result: [])
+ assert_compiles('[1+1]', insns: %i[newarray opt_plus], result: [2])
+ assert_compiles('[1,1+1,3,4,5,6]', insns: %i[newarray opt_plus], result: [1, 2, 3, 4, 5, 6])
+ end
+
+ def test_compile_opt_duparray
+ assert_compiles('[1]', insns: %i[duparray], result: [1])
+ assert_compiles('[1, 2, 3]', insns: %i[duparray], result: [1, 2, 3])
+ end
+
+ def test_compile_newrange
+ assert_compiles('s = 1; (s..5)', insns: %i[newrange], result: 1..5)
+ assert_compiles('s = 1; e = 5; (s..e)', insns: %i[newrange], result: 1..5)
+ assert_compiles('s = 1; (s...5)', insns: %i[newrange], result: 1...5)
+ assert_compiles('s = 1; (s..)', insns: %i[newrange], result: 1..)
+ assert_compiles('e = 5; (..e)', insns: %i[newrange], result: ..5)
+ end
+
+ def test_compile_duphash
+ assert_compiles('{ two: 2 }', insns: %i[duphash], result: { two: 2 })
+ end
+
+ def test_compile_newhash
+ assert_compiles('{}', insns: %i[newhash], result: {})
+ assert_compiles('{ two: 1 + 1 }', insns: %i[newhash], result: { two: 2 })
+ assert_compiles('{ 1 + 1 => :two }', insns: %i[newhash], result: { 2 => :two })
+ end
+
+ def test_compile_opt_nil_p
+ assert_compiles('nil.nil?', insns: %i[opt_nil_p], result: true)
+ assert_compiles('false.nil?', insns: %i[opt_nil_p], result: false)
+ assert_compiles('true.nil?', insns: %i[opt_nil_p], result: false)
+ assert_compiles('(-"").nil?', insns: %i[opt_nil_p], result: false)
+ assert_compiles('123.nil?', insns: %i[opt_nil_p], result: false)
+ end
+
+ def test_compile_eq_fixnum
+ assert_compiles('123 == 123', insns: %i[opt_eq], result: true)
+ assert_compiles('123 == 456', insns: %i[opt_eq], result: false)
+ end
+
+ def test_compile_eq_string
+ assert_compiles('-"" == -""', insns: %i[opt_eq], result: true)
+ assert_compiles('-"foo" == -"foo"', insns: %i[opt_eq], result: true)
+ assert_compiles('-"foo" == -"bar"', insns: %i[opt_eq], result: false)
+ end
+
+ def test_compile_eq_symbol
+ assert_compiles(':foo == :foo', insns: %i[opt_eq], result: true)
+ assert_compiles(':foo == :bar', insns: %i[opt_eq], result: false)
+ assert_compiles(':foo == "foo".to_sym', insns: %i[opt_eq], result: true)
+ end
+
+ def test_compile_eq_object
+ assert_compiles(<<~RUBY, insns: %i[opt_eq], result: false)
+ def eq(a, b)
+ a == b
+ end
+
+ eq(Object.new, Object.new)
+ RUBY
+
+ assert_compiles(<<~RUBY, insns: %i[opt_eq], result: true)
+ def eq(a, b)
+ a == b
+ end
+
+ obj = Object.new
+ eq(obj, obj)
+ RUBY
+ end
+
+ def test_compile_eq_arbitrary_class
+ assert_compiles(<<~RUBY, insns: %i[opt_eq], result: "yes")
+ def eq(a, b)
+ a == b
+ end
+
+ class Foo
+ def ==(other)
+ "yes"
+ end
+ end
+
+ eq(Foo.new, Foo.new)
+ eq(Foo.new, Foo.new)
+ RUBY
+ end
+
+ def test_compile_opt_lt
+ assert_compiles('1 < 2', insns: %i[opt_lt])
+ assert_compiles('"a" < "b"', insns: %i[opt_lt])
+ end
+
+ def test_compile_opt_le
+ assert_compiles('1 <= 2', insns: %i[opt_le])
+ assert_compiles('"a" <= "b"', insns: %i[opt_le])
+ end
+
+ def test_compile_opt_gt
+ assert_compiles('1 > 2', insns: %i[opt_gt])
+ assert_compiles('"a" > "b"', insns: %i[opt_gt])
+ end
+
+ def test_compile_opt_ge
+ assert_compiles('1 >= 2', insns: %i[opt_ge])
+ assert_compiles('"a" >= "b"', insns: %i[opt_ge])
+ end
+
+ def test_compile_opt_plus
+ assert_compiles('1 + 2', insns: %i[opt_plus])
+ assert_compiles('"a" + "b"', insns: %i[opt_plus])
+ assert_compiles('[:foo] + [:bar]', insns: %i[opt_plus])
+ end
+
+ def test_compile_opt_minus
+ assert_compiles('1 - 2', insns: %i[opt_minus])
+ assert_compiles('[:foo, :bar] - [:bar]', insns: %i[opt_minus])
+ end
+
+ def test_compile_opt_or
+ assert_compiles('1 | 2', insns: %i[opt_or])
+ assert_compiles('[:foo] | [:bar]', insns: %i[opt_or])
+ end
+
+ def test_compile_opt_and
+ assert_compiles('1 & 2', insns: %i[opt_and])
+ assert_compiles('[:foo, :bar] & [:bar]', insns: %i[opt_and])
+ end
+
+ def test_compile_set_and_get_global
+ assert_compiles('$foo = 123; $foo', insns: %i[setglobal], result: 123)
+ end
+
+ def test_compile_putspecialobject
+ assert_compiles('-> {}', insns: %i[putspecialobject])
+ end
+
+ def test_compile_tostring
+ assert_no_exits('"i am a string #{true}"')
+ end
+
+ def test_compile_opt_aset
+ assert_compiles('[1,2,3][2] = 4', insns: %i[opt_aset])
+ assert_compiles('{}[:foo] = :bar', insns: %i[opt_aset])
+ assert_compiles('[1,2,3][0..-1] = []', insns: %i[opt_aset])
+ assert_compiles('"foo"[3] = "d"', insns: %i[opt_aset])
+ end
+
+ def test_compile_attr_set
+ assert_no_exits(<<~EORB)
+ class Foo
+ attr_accessor :bar
+ end
+
+ foo = Foo.new
+ foo.bar = 3
+ foo.bar = 3
+ foo.bar = 3
+ foo.bar = 3
+ EORB
+ end
+
+ def test_compile_regexp
+ assert_no_exits('/#{true}/')
+ end
+
+ def test_getlocal_with_level
+ assert_compiles(<<~RUBY, insns: %i[getlocal opt_plus], result: [[7]])
+ def foo(foo, bar)
+ [1].map do |x|
+ [1].map do |y|
+ foo + bar
+ end
+ end
+ end
+
+ foo(5, 2)
+ RUBY
+ end
+
+ def test_setlocal_with_level
+ assert_no_exits(<<~RUBY)
+ def sum(arr)
+ sum = 0
+ arr.each do |x|
+ sum += x
+ end
+ sum
+ end
+
+ sum([1,2,3])
+ RUBY
+ end
+
+ def test_string_then_nil
+ assert_compiles(<<~RUBY, insns: %i[opt_nil_p], result: true)
+ def foo(val)
+ val.nil?
+ end
+
+ foo("foo")
+ foo(nil)
+ RUBY
+ end
+
+ def test_nil_then_string
+ assert_compiles(<<~RUBY, insns: %i[opt_nil_p], result: false)
+ def foo(val)
+ val.nil?
+ end
+
+ foo(nil)
+ foo("foo")
+ RUBY
+ end
+
+ def test_opt_length_in_method
+ assert_compiles(<<~RUBY, insns: %i[opt_length], result: 5)
+ def foo(str)
+ str.length
+ end
+
+ foo("hello, ")
+ foo("world")
+ RUBY
+ end
+
+ def test_opt_regexpmatch2
+ assert_compiles(<<~RUBY, insns: %i[opt_regexpmatch2], result: 0)
+ def foo(str)
+ str =~ /foo/
+ end
+
+ foo("foobar")
+ RUBY
+ end
+
+ def test_expandarray
+ assert_compiles(<<~'RUBY', insns: %i[expandarray], result: [1, 2])
+ a, b = [1, 2]
+ RUBY
+ end
+
+ def test_expandarray_nil
+ assert_compiles(<<~'RUBY', insns: %i[expandarray], result: [nil, nil])
+ a, b = nil
+ [a, b]
+ RUBY
+ end
+
+ def test_getspecial_backref
+ assert_compiles("'foo' =~ /(o)./; $&", insns: %i[getspecial], result: "oo")
+ assert_compiles("'foo' =~ /(o)./; $`", insns: %i[getspecial], result: "f")
+ assert_compiles("'foo' =~ /(o)./; $'", insns: %i[getspecial], result: "")
+ assert_compiles("'foo' =~ /(o)./; $+", insns: %i[getspecial], result: "o")
+ assert_compiles("'foo' =~ /(o)./; $1", insns: %i[getspecial], result: "o")
+ assert_compiles("'foo' =~ /(o)./; $2", insns: %i[getspecial], result: nil)
+ end
+
+ def test_compile_opt_getinlinecache
+ assert_compiles(<<~RUBY, insns: %i[opt_getinlinecache], result: 123, min_calls: 2)
+ def get_foo
+ FOO
+ end
+
+ FOO = 123
+
+ get_foo # warm inline cache
+ get_foo
+ RUBY
+ end
+
+ def test_opt_getinlinecache_slowpath
+ assert_compiles(<<~RUBY, exits: { opt_getinlinecache: 1 }, result: [42, 42, 1, 1], min_calls: 2)
+ class A
+ FOO = 42
+ class << self
+ def foo
+ _foo = nil
+ FOO
+ end
+ end
+ end
+
+ result = []
+
+ result << A.foo
+ result << A.foo
+
+ class << A
+ FOO = 1
+ end
+
+ result << A.foo
+ result << A.foo
+
+ result
+ RUBY
+ end
+
+ def test_string_interpolation
+ assert_compiles(<<~'RUBY', insns: %i[objtostring anytostring concatstrings], result: "foobar", min_calls: 2)
+ def make_str(foo, bar)
+ "#{foo}#{bar}"
+ end
+
+ make_str("foo", "bar")
+ make_str("foo", "bar")
+ RUBY
+ end
+
+ def test_string_interpolation_cast
+ assert_compiles(<<~'RUBY', insns: %i[objtostring anytostring concatstrings], result: "123")
+ def make_str(foo, bar)
+ "#{foo}#{bar}"
+ end
+
+ make_str(1, 23)
+ RUBY
+ end
+
+ def test_checkkeyword
+ assert_compiles(<<~'RUBY', insns: %i[checkkeyword], result: [2, 5])
+ def foo(foo: 1+1)
+ foo
+ end
+
+ [foo, foo(foo: 5)]
+ RUBY
+ end
+
+ def test_struct_aref
+ assert_compiles(<<~RUBY)
+ def foo(obj)
+ obj.foo
+ obj.bar
+ end
+
+ Foo = Struct.new(:foo, :bar)
+ foo(Foo.new(123))
+ foo(Foo.new(123))
+ RUBY
+ end
+
+ def test_struct_aset
+ assert_compiles(<<~RUBY)
+ def foo(obj)
+ obj.foo = 123
+ obj.bar = 123
+ end
+
+ Foo = Struct.new(:foo, :bar)
+ foo(Foo.new(123))
+ foo(Foo.new(123))
+ RUBY
+ end
+
+ def test_super_iseq
+ assert_compiles(<<~'RUBY', insns: %i[invokesuper opt_plus opt_mult], result: 15)
+ class A
+ def foo
+ 1 + 2
+ end
+ end
+
+ class B < A
+ def foo
+ super * 5
+ end
+ end
+
+ B.new.foo
+ RUBY
+ end
+
+ def test_super_cfunc
+ assert_compiles(<<~'RUBY', insns: %i[invokesuper], result: "Hello")
+ class Gnirts < String
+ def initialize
+ super(-"olleH")
+ end
+
+ def to_s
+ super().reverse
+ end
+ end
+
+ Gnirts.new.to_s
+ RUBY
+ end
+
+ # Tests calling a variadic cfunc with many args
+ def test_build_large_struct
+ assert_compiles(<<~RUBY, insns: %i[opt_send_without_block], min_calls: 2)
+ ::Foo = Struct.new(:a, :b, :c, :d, :e, :f, :g, :h)
+
+ def build_foo
+ ::Foo.new(:a, :b, :c, :d, :e, :f, :g, :h)
+ end
+
+ build_foo
+ build_foo
+ RUBY
+ end
+
+ def test_fib_recursion
+ assert_compiles(<<~'RUBY', insns: %i[opt_le opt_minus opt_plus opt_send_without_block], result: 34)
+ def fib(n)
+ return n if n <= 1
+ fib(n-1) + fib(n-2)
+ end
+
+ fib(9)
+ RUBY
+ end
+
+ def test_ctx_different_mappings
+ # regression test simplified from URI::Generic#hostname=
+ assert_compiles(<<~'RUBY', frozen_string_literal: true)
+ def foo(v)
+ !(v&.start_with?('[')) && v&.index(':')
+ end
+
+ foo(nil)
+ foo("example.com")
+ RUBY
+ end
+
+ def test_no_excessive_opt_getinlinecache_invalidation
+ assert_compiles(<<~'RUBY', exits: :any, result: :ok)
+ objects = [Object.new, Object.new]
+
+ objects.each do |o|
+ class << o
+ def foo
+ Object
+ end
+ end
+ end
+
+ 9000.times {
+ objects[0].foo
+ objects[1].foo
+ }
+
+ stats = RubyVM::YJIT.runtime_stats
+ return :ok unless stats[:all_stats]
+ return :ok if stats[:invalidation_count] < 10
+
+ :fail
+ RUBY
+ end
+
+ def assert_no_exits(script)
+ assert_compiles(script)
+ end
+
+ ANY = Object.new
+ def assert_compiles(test_script, insns: [], min_calls: 1, stdout: nil, exits: {}, result: ANY, frozen_string_literal: nil)
+ reset_stats = <<~RUBY
+ RubyVM::YJIT.runtime_stats
+ RubyVM::YJIT.reset_stats!
+ RUBY
+
+ write_results = <<~RUBY
+ stats = RubyVM::YJIT.runtime_stats
+
+ def collect_blocks(blocks)
+ blocks.sort_by(&:address).map { |b| [b.iseq_start_index, b.iseq_end_index] }
+ end
+
+ def collect_iseqs(iseq)
+ iseq_array = iseq.to_a
+ insns = iseq_array.last.grep(Array)
+ blocks = RubyVM::YJIT.blocks_for(iseq)
+ h = {
+ name: iseq_array[5],
+ insns: insns,
+ blocks: collect_blocks(blocks),
+ }
+ arr = [h]
+ iseq.each_child { |c| arr.concat collect_iseqs(c) }
+ arr
+ end
+
+ iseq = RubyVM::InstructionSequence.of(_test_proc)
+ IO.open(3).write Marshal.dump({
+ result: #{result == ANY ? "nil" : "result"},
+ stats: stats,
+ iseqs: collect_iseqs(iseq),
+ disasm: iseq.disasm
+ })
+ RUBY
+
+ script = <<~RUBY
+ #{"# frozen_string_literal: true" if frozen_string_literal}
+ _test_proc = -> {
+ #{test_script}
+ }
+ #{reset_stats}
+ result = _test_proc.call
+ #{write_results}
+ RUBY
+
+ status, out, err, stats = eval_with_jit(script, min_calls: min_calls)
+
+ assert status.success?, "exited with status #{status.to_i}, stderr:\n#{err}"
+
+ assert_equal stdout.chomp, out.chomp if stdout
+
+ unless ANY.equal?(result)
+ assert_equal result, stats[:result]
+ end
+
+ runtime_stats = stats[:stats]
+ iseqs = stats[:iseqs]
+ disasm = stats[:disasm]
+
+ # Only available when RUBY_DEBUG enabled
+ if runtime_stats[:all_stats]
+ recorded_exits = runtime_stats.select { |k, v| k.to_s.start_with?("exit_") }
+ recorded_exits = recorded_exits.reject { |k, v| v == 0 }
+
+ recorded_exits.transform_keys! { |k| k.to_s.gsub("exit_", "").to_sym }
+ if exits != :any && exits != recorded_exits
+ flunk "Expected #{exits.empty? ? "no" : exits.inspect} exits" \
+ ", but got\n#{recorded_exits.inspect}"
+ end
+ end
+
+ # Only available when RUBY_DEBUG enabled
+ if runtime_stats[:all_stats]
+ missed_insns = insns.dup
+ all_compiled_blocks = {}
+ iseqs.each do |iseq|
+ compiled_blocks = iseq[:blocks].map { |from, to| (from...to) }
+ all_compiled_blocks[iseq[:name]] = compiled_blocks
+ compiled_insns = iseq[:insns]
+ next_idx = 0
+ compiled_insns.map! do |insn|
+ # TODO: not sure this is accurate for determining insn size
+ idx = next_idx
+ next_idx += insn.length
+ [idx, *insn]
+ end
+
+ compiled_insns.each do |idx, op, *arguments|
+ next unless missed_insns.include?(op)
+ next unless compiled_blocks.any? { |block| block === idx }
+
+ # This instruction was compiled
+ missed_insns.delete(op)
+ end
+ end
+
+ unless missed_insns.empty?
+ flunk "Expected to compile instructions #{missed_insns.join(", ")} but didn't.\nCompiled ranges: #{all_compiled_blocks.inspect}\niseq:\n#{disasm}"
+ end
+ end
+ end
+
+ def eval_with_jit(script, min_calls: 1, timeout: 1000)
+ args = [
+ "--disable-gems",
+ "--yjit-call-threshold=#{min_calls}",
+ "--yjit-stats"
+ ]
+ args << "-e" << script
+ stats_r, stats_w = IO.pipe
+ out, err, status = EnvUtil.invoke_ruby(args,
+ '', true, true, timeout: timeout, ios: {3 => stats_w}
+ )
+ stats_w.close
+ stats = stats_r.read
+ stats = Marshal.load(stats) if !stats.empty?
+ stats_r.close
+ [status, out, err, stats]
+ end
+end
diff --git a/test/rubygems/encrypted_private_key.pem b/test/rubygems/encrypted_private_key.pem
index 868f332b7ce..d9667689a62 100644
--- a/test/rubygems/encrypted_private_key.pem
+++ b/test/rubygems/encrypted_private_key.pem
@@ -1,30 +1,30 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
-DEK-Info: DES-CBC,4E38D58B5A059DB6
+DEK-Info: AES-256-CBC,CB6FD0B173EF450C6EE21A01DD785C1D
-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
+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
-----END RSA PRIVATE KEY-----
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb
index b25c9a93985..40ed62fc77c 100644
--- a/test/rubygems/helper.rb
+++ b/test/rubygems/helper.rb
@@ -16,16 +16,6 @@ begin
rescue Gem::LoadError
end
-begin
- require 'simplecov'
- SimpleCov.start do
- add_filter "/test/"
- add_filter "/bundler/"
- add_filter "/lib/rubygems/resolver/molinillo"
- end
-rescue LoadError
-end
-
if File.exist?(bundler_gemspec)
require_relative '../../bundler/lib/bundler'
else
@@ -255,16 +245,14 @@ class Gem::TestCase < Test::Unit::TestCase
output.scan(/^#{Regexp.escape make_command}(?:[[:blank:]].*)?$/)
end
- def parse_make_command_line(line)
- command, *args = line.shellsplit
+ def parse_make_command_line_targets(line)
+ args = line.sub(/^#{Regexp.escape make_command}/, "").shellsplit
targets = []
- macros = {}
args.each do |arg|
case arg
when /\A(\w+)=/
- macros[$1] = $'
else
targets << arg
end
@@ -272,11 +260,7 @@ class Gem::TestCase < Test::Unit::TestCase
targets << '' if targets.empty?
- {
- :command => command,
- :targets => targets,
- :macros => macros,
- }
+ targets
end
def assert_contains_make_command(target, output, msg = nil)
@@ -289,7 +273,7 @@ class Gem::TestCase < Test::Unit::TestCase
)
else
msg = build_message(msg,
- 'Expected make command "%s": %s' % [
+ 'Expected make command "%s", but was "%s"' % [
('%s %s' % [make_command, target]).rstrip,
output,
]
@@ -297,10 +281,9 @@ class Gem::TestCase < Test::Unit::TestCase
end
assert scan_make_command_lines(output).any? {|line|
- make = parse_make_command_line(line)
+ targets = parse_make_command_line_targets(line)
- if make[:targets].include?(target)
- yield make, line if block_given?
+ if targets.include?(target)
true
else
false
@@ -396,6 +379,7 @@ class Gem::TestCase < Test::Unit::TestCase
ENV['GEM_PRIVATE_KEY_PASSPHRASE'] = PRIVATE_KEY_PASSPHRASE
+ Gem.instance_variable_set(:@default_specifications_dir, nil)
if Gem.java_platform?
@orig_default_gem_home = RbConfig::CONFIG['default_gem_home']
RbConfig::CONFIG['default_gem_home'] = @gemhome
@@ -406,6 +390,14 @@ class Gem::TestCase < Test::Unit::TestCase
@orig_bindir = RbConfig::CONFIG["bindir"]
RbConfig::CONFIG["bindir"] = File.join @gemhome, "bin"
+ @orig_sitelibdir = RbConfig::CONFIG["sitelibdir"]
+ new_sitelibdir = @orig_sitelibdir.sub(RbConfig::CONFIG["prefix"], @gemhome)
+ $LOAD_PATH.insert(Gem.load_path_insert_index, new_sitelibdir)
+ RbConfig::CONFIG["sitelibdir"] = new_sitelibdir
+
+ @orig_mandir = RbConfig::CONFIG["mandir"]
+ RbConfig::CONFIG["mandir"] = File.join @gemhome, "share", "man"
+
Gem::Specification.unresolved_deps.clear
Gem.use_paths(@gemhome)
@@ -477,15 +469,17 @@ class Gem::TestCase < Test::Unit::TestCase
Gem.ruby = @orig_ruby if @orig_ruby
+ RbConfig::CONFIG['mandir'] = @orig_mandir
+ RbConfig::CONFIG['sitelibdir'] = @orig_sitelibdir
RbConfig::CONFIG['bindir'] = @orig_bindir
+ Gem.instance_variable_set :@default_specifications_dir, nil
if Gem.java_platform?
RbConfig::CONFIG['default_gem_home'] = @orig_default_gem_home
else
Gem.instance_variable_set :@default_dir, nil
end
- Gem::Specification._clear_load_cache
Gem::Specification.unresolved_deps.clear
Gem::refresh
@@ -595,7 +589,7 @@ class Gem::TestCase < Test::Unit::TestCase
def have_git?
return if in_path? @git
- skip 'cannot find git executable, use GIT environment variable to set'
+ pend 'cannot find git executable, use GIT environment variable to set'
end
def in_path?(executable) # :nodoc:
@@ -823,16 +817,6 @@ class Gem::TestCase < Test::Unit::TestCase
Gem::Specification.unresolved_deps.values.map(&:to_s).sort
end
- def save_loaded_features
- old_loaded_features = $LOADED_FEATURES.dup
- yield
- ensure
- prefix = File.dirname(__FILE__) + "/"
- new_features = ($LOADED_FEATURES - old_loaded_features)
- old_loaded_features.concat(new_features.select {|f| f.rindex(prefix, 0) })
- $LOADED_FEATURES.replace old_loaded_features
- end
-
def new_default_spec(name, version, deps = nil, *files)
spec = util_spec name, version, deps
@@ -1090,19 +1074,23 @@ Also, a list:
@fetcher.data["#{@gem_repo}latest_specs.#{v}.gz"] = l_zip
@fetcher.data["#{@gem_repo}prerelease_specs.#{v}.gz"] = p_zip
- v = Gem.marshal_version
-
- all_specs.each do |spec|
- path = "#{@gem_repo}quick/Marshal.#{v}/#{spec.original_name}.gemspec.rz"
- data = Marshal.dump spec
- data_deflate = Zlib::Deflate.deflate data
- @fetcher.data[path] = data_deflate
- end
+ write_marshalled_gemspecs(*all_specs)
end
nil # force errors
end
+ def write_marshalled_gemspecs(*all_specs)
+ v = Gem.marshal_version
+
+ all_specs.each do |spec|
+ path = "#{@gem_repo}quick/Marshal.#{v}/#{spec.original_name}.gemspec.rz"
+ data = Marshal.dump spec
+ data_deflate = Zlib::Deflate.deflate data
+ @fetcher.data[path] = data_deflate
+ end
+ end
+
##
# Deflates +data+
@@ -1527,14 +1515,14 @@ Also, a list:
end
##
- # Loads an RSA private key named +key_name+ with +passphrase+ in <tt>test/rubygems/</tt>
+ # Loads a private key named +key_name+ with +passphrase+ in <tt>test/rubygems/</tt>
def self.load_key(key_name, passphrase = nil)
key_file = key_path key_name
key = File.read key_file
- OpenSSL::PKey::RSA.new key, passphrase
+ OpenSSL::PKey.read key, passphrase
end
##
diff --git a/test/rubygems/private_ec_key.pem b/test/rubygems/private_ec_key.pem
new file mode 100644
index 00000000000..5d855d0dfc8
--- /dev/null
+++ b/test/rubygems/private_ec_key.pem
@@ -0,0 +1,9 @@
+-----BEGIN EC PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: AES-256-CBC,4107F98A374CB8EC18F1AA4EA4B6A0DB
+
+BRklFxJGcz7gqQYxek8TZkt8qbPhB0FSR6nyw3SYuio/2tlT9ohs74mlK3EbG9Lt
+Y4OquJbksBFmoB7fIoM4vnuIZ0Eoz2ooxn9tjhBtqJ3mVscYXwZmA3UDUWDMlviQ
+Fu37OpikQv4TFA1jlmUK0LM8xmUCfUeLl0kHD17lFsz2gkO2kwg8mn/YUMOIaDOu
+EnnmxbAwnZBpemQkQfpTt2mYL9gu3CcMt5gokBuGDxY=
+-----END EC PRIVATE KEY-----
diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb
index da6fdc54fa4..3c95982d4be 100644
--- a/test/rubygems/test_gem.rb
+++ b/test/rubygems/test_gem.rb
@@ -25,72 +25,66 @@ class TestGem < Gem::TestCase
end
def test_self_finish_resolve
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1"
- c2 = util_spec "c", "2"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2"
- install_specs c1, c2, b1, b2, a1
+ install_specs c1, c2, b1, b2, a1
- a1.activate
+ a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- Gem.finish_resolve
+ Gem.finish_resolve
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1 b-2 c-2], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_self_finish_resolve_wtf
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
- b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" # this
- b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb"
- c1 = util_spec "c", "1" # this
- c2 = util_spec "c", "2"
- d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
- d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
+ a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
+ b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b.rb" # this
+ b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b.rb"
+ c1 = util_spec "c", "1" # this
+ c2 = util_spec "c", "2"
+ d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d.rb"
+ d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d.rb" # this
- install_specs c1, c2, b1, b2, d1, d2, a1
+ install_specs c1, c2, b1, b2, d1, d2, a1
- a1.activate
+ a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
- Gem.finish_resolve
+ Gem.finish_resolve
- assert_equal %w[a-1 b-1 c-1 d-2], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1 b-1 c-1 d-2], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_self_finish_resolve_respects_loaded_specs
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1"
- c2 = util_spec "c", "2"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2"
- install_specs c1, c2, b1, b2, a1
+ install_specs c1, c2, b1, b2, a1
- a1.activate
- c1.activate
+ a1.activate
+ c1.activate
- assert_equal %w[a-1 c-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ assert_equal %w[a-1 c-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- Gem.finish_resolve
+ Gem.finish_resolve
- assert_equal %w[a-1 b-1 c-1], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1 b-1 c-1], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_self_install
@@ -210,25 +204,21 @@ class TestGem < Gem::TestCase
end
def test_require_missing
- save_loaded_features do
- assert_raise ::LoadError do
- require "test_require_missing"
- end
+ assert_raise ::LoadError do
+ require "test_require_missing"
end
end
def test_require_does_not_glob
- save_loaded_features do
- a1 = util_spec "a", "1", nil, "lib/a1.rb"
+ a1 = util_spec "a", "1", nil, "lib/a1.rb"
- install_specs a1
-
- assert_raise ::LoadError do
- require "a*"
- end
+ install_specs a1
- assert_equal [], loaded_spec_names
+ assert_raise ::LoadError do
+ require "a*"
end
+
+ assert_equal [], loaded_spec_names
end
def test_self_bin_path_active
@@ -1444,24 +1434,22 @@ class TestGem < Gem::TestCase
end
def test_self_needs_picks_up_unresolved_deps
- save_loaded_features do
- a = util_spec "a", "1"
- b = util_spec "b", "1", "c" => nil
- c = util_spec "c", "2"
- d = util_spec "d", "1", {'e' => '= 1'}, "lib/d#{$$}.rb"
- e = util_spec "e", "1"
-
- install_specs a, c, b, e, d
+ a = util_spec "a", "1"
+ b = util_spec "b", "1", "c" => nil
+ c = util_spec "c", "2"
+ d = util_spec "d", "1", {'e' => '= 1'}, "lib/d#{$$}.rb"
+ e = util_spec "e", "1"
- Gem.needs do |r|
- r.gem "a"
- r.gem "b", "= 1"
+ install_specs a, c, b, e, d
- require "d#{$$}"
- end
+ Gem.needs do |r|
+ r.gem "a"
+ r.gem "b", "= 1"
- assert_equal %w[a-1 b-1 c-2 d-1 e-1], loaded_spec_names
+ require "d#{$$}"
end
+
+ assert_equal %w[a-1 b-1 c-2 d-1 e-1], loaded_spec_names
end
def test_self_gunzip
diff --git a/test/rubygems/test_gem_command.rb b/test/rubygems/test_gem_command.rb
index 43ce6ea39f5..65b9b040b77 100644
--- a/test/rubygems/test_gem_command.rb
+++ b/test/rubygems/test_gem_command.rb
@@ -118,7 +118,7 @@ class TestGemCommand < Gem::TestCase
use_ui @ui do
@cmd.when_invoked { true }
- ex = assert_raise OptionParser::InvalidOption do
+ ex = assert_raise Gem::OptionParser::InvalidOption do
@cmd.invoke('-zzz')
end
diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb
index f722678a192..901bf5aed62 100644
--- a/test/rubygems/test_gem_commands_cert_command.rb
+++ b/test/rubygems/test_gem_commands_cert_command.rb
@@ -14,9 +14,10 @@ class TestGemCommandsCertCommand < Gem::TestCase
ALTERNATE_CERT = load_cert 'alternate'
EXPIRED_PUBLIC_CERT = load_cert 'expired'
- ALTERNATE_KEY_FILE = key_path 'alternate'
- PRIVATE_KEY_FILE = key_path 'private'
- PUBLIC_KEY_FILE = key_path 'public'
+ ALTERNATE_KEY_FILE = key_path 'alternate'
+ PRIVATE_KEY_FILE = key_path 'private'
+ PRIVATE_EC_KEY_FILE = key_path 'private_ec'
+ PUBLIC_KEY_FILE = key_path 'public'
ALTERNATE_CERT_FILE = cert_path 'alternate'
CHILD_CERT_FILE = cert_path 'child'
@@ -142,6 +143,42 @@ Added '/CN=alternate/DC=example'
assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
end
+ def test_execute_build_key_algorithm_ec_key
+ passphrase = 'Foo bar'
+
+ @cmd.handle_options %W[--build nobody@example.com --key-algorithm ec]
+
+ @build_ui = Gem::MockGemUi.new "#{passphrase}\n#{passphrase}"
+
+ use_ui @build_ui do
+ @cmd.execute
+ end
+
+ output = @build_ui.output.squeeze("\n").split "\n"
+
+ assert_equal "Passphrase for your Private Key: ",
+ output.shift
+ assert_equal "Please repeat the passphrase for your Private Key: ",
+ output.shift
+ assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
+ output.shift
+ assert_equal "Private Key: #{File.join @tempdir, 'gem-private_key.pem'}",
+ output.shift
+
+ assert_equal "Don't forget to move the key file to somewhere private!",
+ output.shift
+
+ assert_empty output
+ assert_empty @build_ui.error
+
+ assert_path_exist File.join(@tempdir, 'gem-private_key.pem')
+
+ cert_path = File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_exist cert_path
+ cert = OpenSSL::X509::Certificate.new(File.read(cert_path))
+ assert cert.public_key.is_a? OpenSSL::PKey::EC
+ end
+
def test_execute_build_bad_email_address
passphrase = 'Foo bar'
email = "nobody@"
@@ -279,6 +316,28 @@ Added '/CN=alternate/DC=example'
assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
end
+ def test_execute_build_ec_key
+ @cmd.handle_options %W[
+ --build nobody@example.com
+ --private-key #{PRIVATE_EC_KEY_FILE}
+ ]
+
+ use_ui @ui do
+ @cmd.execute
+ end
+
+ output = @ui.output.split "\n"
+
+ assert_equal "Certificate: #{File.join @tempdir, 'gem-public_cert.pem'}",
+ output.shift
+
+ assert_empty output
+ assert_empty @ui.error
+
+ assert_path_exist File.join(@tempdir, 'gem-public_cert.pem')
+ assert_path_not_exist File.join(@tempdir, 'gem-private_key.pem')
+ end
+
def test_execute_certificate
use_ui @ui do
@cmd.handle_options %W[--certificate #{PUBLIC_CERT_FILE}]
@@ -686,7 +745,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
def test_handle_options_add_bad
nonexistent = File.join @tempdir, 'nonexistent'
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--add #{nonexistent}]
end
@@ -696,7 +755,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
bad = File.join @tempdir, 'bad'
FileUtils.touch bad
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--add #{bad}]
end
@@ -706,7 +765,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
def test_handle_options_certificate
nonexistent = File.join @tempdir, 'nonexistent'
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--certificate #{nonexistent}]
end
@@ -716,7 +775,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
bad = File.join @tempdir, 'bad'
FileUtils.touch bad
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--certificate #{bad}]
end
@@ -727,7 +786,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
def test_handle_options_key_bad
nonexistent = File.join @tempdir, 'nonexistent'
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--private-key #{nonexistent}]
end
@@ -738,14 +797,14 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
bad = File.join @tempdir, 'bad'
FileUtils.touch bad
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--private-key #{bad}]
end
- assert_equal "invalid argument: --private-key #{bad}: invalid RSA key",
+ assert_equal "invalid argument: --private-key #{bad}: invalid RSA, DSA, or EC key",
e.message
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[--private-key #{PUBLIC_KEY_FILE}]
end
@@ -792,7 +851,7 @@ ERROR: --private-key not specified and ~/.gem/gem-private_key.pem does not exis
def test_handle_options_sign_nonexistent
nonexistent = File.join @tempdir, 'nonexistent'
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %W[
--private-key #{ALTERNATE_KEY_FILE}
diff --git a/test/rubygems/test_gem_commands_fetch_command.rb b/test/rubygems/test_gem_commands_fetch_command.rb
index 35ee00f7638..c745648d569 100644
--- a/test/rubygems/test_gem_commands_fetch_command.rb
+++ b/test/rubygems/test_gem_commands_fetch_command.rb
@@ -79,6 +79,42 @@ class TestGemCommandsFetchCommand < Gem::TestCase
"#{a2.full_name} not fetched")
end
+ def test_execute_platform
+ a2_spec, a2 = util_gem("a", "2")
+
+ a2_universal_darwin_spec, a2_universal_darwin = util_gem("a", "2") do |s|
+ s.platform = 'universal-darwin'
+ end
+
+ Gem::RemoteFetcher.fetcher = @fetcher = Gem::FakeFetcher.new
+
+ write_marshalled_gemspecs(a2_spec, a2_universal_darwin_spec)
+
+ @cmd.options[:args] = %w[a]
+
+ @fetcher.data["#{@gem_repo}latest_specs.#{Gem.marshal_version}.gz"] = util_gzip(Marshal.dump([
+ Gem::NameTuple.new(a2_spec.name, a2_spec.version, a2_spec.platform),
+ Gem::NameTuple.new(a2_universal_darwin_spec.name, a2_universal_darwin_spec.version, a2_universal_darwin_spec.platform),
+ ]))
+
+ @fetcher.data["#{@gem_repo}gems/#{a2_spec.file_name}"] = Gem.read_binary(a2)
+ FileUtils.cp a2, a2_spec.cache_file
+
+ @fetcher.data["#{@gem_repo}gems/#{a2_universal_darwin_spec.file_name}"] = Gem.read_binary(a2_universal_darwin)
+ FileUtils.cp a2_universal_darwin, a2_universal_darwin_spec.cache_file
+
+ util_set_arch 'arm64-darwin20' do
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+ end
+
+ assert_path_exist(File.join(@tempdir, a2_universal_darwin_spec.file_name),
+ "#{a2_universal_darwin_spec.full_name} not fetched")
+ end
+
def test_execute_specific_prerelease
specs = spec_fetcher do |fetcher|
fetcher.gem 'a', 2
diff --git a/test/rubygems/test_gem_commands_server_command.rb b/test/rubygems/test_gem_commands_server_command.rb
index 09cec63c155..96c328f93fa 100644
--- a/test/rubygems/test_gem_commands_server_command.rb
+++ b/test/rubygems/test_gem_commands_server_command.rb
@@ -9,53 +9,11 @@ class TestGemCommandsServerCommand < Gem::TestCase
@cmd = Gem::Commands::ServerCommand.new
end
- def test_handle_options
- @cmd.send :handle_options, %w[-p 8808 --no-daemon]
-
- assert_equal false, @cmd.options[:daemon]
- assert_equal [], @cmd.options[:gemdir]
- assert_equal 8808, @cmd.options[:port]
-
- @cmd.send :handle_options, %w[-p 9999 -d /nonexistent --daemon]
-
- assert_equal true, @cmd.options[:daemon]
- assert_equal [File.expand_path('/nonexistent')], @cmd.options[:gemdir]
- assert_equal 9999, @cmd.options[:port]
- end
-
- def test_handle_options_gemdir
- @cmd.send :handle_options, %w[--dir a --dir b]
-
- assert_equal [File.expand_path('a'), File.expand_path('b')],
- @cmd.options[:gemdir]
- end
-
- def test_handle_options_port
- @cmd.send :handle_options, %w[-p 0]
- assert_equal 0, @cmd.options[:port]
-
- @cmd.send :handle_options, %w[-p 65535]
- assert_equal 65535, @cmd.options[:port]
-
- begin
- @cmd.send :handle_options, %w[-p discard]
- assert_equal 9, @cmd.options[:port]
- rescue OptionParser::InvalidArgument
- # for container environment on GitHub Actions
- end
-
- e = assert_raise OptionParser::InvalidArgument do
- @cmd.send :handle_options, %w[-p nonexistent]
- end
-
- assert_equal 'invalid argument: -p nonexistent: no such named service',
- e.message
-
- e = assert_raise OptionParser::InvalidArgument do
- @cmd.send :handle_options, %w[-p 65536]
+ def test_execute
+ use_ui @ui do
+ @cmd.execute
end
- assert_equal 'invalid argument: -p 65536: not a port number',
- e.message
+ assert_match %r{Install the rubygems-server}i, @ui.error
end
end
diff --git a/test/rubygems/test_gem_commands_setup_command.rb b/test/rubygems/test_gem_commands_setup_command.rb
index 3aa6bfa2fe5..50f99bc4198 100644
--- a/test/rubygems/test_gem_commands_setup_command.rb
+++ b/test/rubygems/test_gem_commands_setup_command.rb
@@ -14,9 +14,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
def setup
super
- @install_dir = File.join @tempdir, 'install'
@cmd = Gem::Commands::SetupCommand.new
- @cmd.options[:prefix] = @install_dir
filelist = %w[
bin/gem
@@ -227,27 +225,60 @@ class TestGemCommandsSetupCommand < Gem::TestCase
f.puts 'echo "hello"'
end
- bindir(bin_dir) do
- @cmd.options[:force] = true
+ @cmd.options[:force] = true
- @cmd.install_default_bundler_gem bin_dir
-
- bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
- default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
- spec = Gem::Specification.load(default_spec_path)
+ @cmd.install_default_bundler_gem bin_dir
- spec.executables.each do |e|
- if Gem.win_platform?
- assert_path_exist File.join(bin_dir, "#{e}.bat")
- end
+ bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
+ default_spec_path = File.join(Gem.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
+ spec = Gem::Specification.load(default_spec_path)
- assert_path_exist File.join bin_dir, e
+ spec.executables.each do |e|
+ if Gem.win_platform?
+ assert_path_exist File.join(bin_dir, "#{e}.bat")
end
+
+ assert_path_exist File.join bin_dir, e
+ end
+ end
+
+ def test_install_default_bundler_gem_with_destdir_flag
+ @cmd.extend FileUtils
+
+ destdir = File.join(@tempdir, 'foo')
+ bin_dir = File.join(destdir, 'bin')
+
+ @cmd.options[:destdir] = destdir
+
+ @cmd.install_default_bundler_gem bin_dir
+
+ spec = Gem::Specification.load("bundler/bundler.gemspec")
+
+ spec.executables.each do |e|
+ assert_path_exist File.join destdir, @gemhome.gsub(/^[a-zA-Z]:/, ''), 'gems', spec.full_name, spec.bindir, e
+ end
+ end
+
+ def test_install_default_bundler_gem_with_destdir_and_prefix_flags
+ @cmd.extend FileUtils
+
+ destdir = File.join(@tempdir, 'foo')
+ bin_dir = File.join(destdir, 'bin')
+
+ @cmd.options[:destdir] = destdir
+ @cmd.options[:prefix] = "/"
+
+ @cmd.install_default_bundler_gem bin_dir
+
+ spec = Gem::Specification.load("bundler/bundler.gemspec")
+
+ spec.executables.each do |e|
+ assert_path_exist File.join destdir, 'gems', spec.full_name, spec.bindir, e
end
end
def test_remove_old_lib_files
- lib = File.join @install_dir, 'lib'
+ lib = RbConfig::CONFIG["sitelibdir"]
lib_rubygems = File.join lib, 'rubygems'
lib_bundler = File.join lib, 'bundler'
lib_rubygems_defaults = File.join lib_rubygems, 'defaults'
@@ -278,7 +309,7 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def test_remove_old_man_files
- man = File.join @install_dir, 'man'
+ man = File.join RbConfig::CONFIG['mandir'], 'man'
ruby_1 = File.join man, 'man1', 'ruby.1'
bundle_b_1 = File.join man, 'man1', 'bundle-b.1'
@@ -384,14 +415,14 @@ class TestGemCommandsSetupCommand < Gem::TestCase
end
def default_gem_bin_path
- File.join @install_dir, 'bin', 'gem'
+ File.join RbConfig::CONFIG['bindir'], 'gem'
end
def default_bundle_bin_path
- File.join @install_dir, 'bin', 'bundle'
+ File.join RbConfig::CONFIG['bindir'], 'bundle'
end
def default_bundler_bin_path
- File.join @install_dir, 'bin', 'bundler'
+ File.join RbConfig::CONFIG['bindir'], 'bundler'
end
end unless Gem.java_platform?
diff --git a/test/rubygems/test_gem_commands_signin_command.rb b/test/rubygems/test_gem_commands_signin_command.rb
index eaf32886b34..0f856a53ba4 100644
--- a/test/rubygems/test_gem_commands_signin_command.rb
+++ b/test/rubygems/test_gem_commands_signin_command.rb
@@ -80,7 +80,7 @@ class TestGemCommandsSigninCommand < Gem::TestCase
assert_equal api_key, credentials[:rubygems_api_key]
end
- def test_excute_with_key_name_and_scope
+ def test_execute_with_key_name_and_scope
email = 'you@example.com'
password = 'secret'
api_key = '1234'
diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb
index 55f1049266b..5bd2c40d593 100644
--- a/test/rubygems/test_gem_commands_uninstall_command.rb
+++ b/test/rubygems/test_gem_commands_uninstall_command.rb
@@ -436,7 +436,7 @@ WARNING: Use your OS package manager to uninstall vendor gems
def test_handle_options_vendor_missing
vendordir(nil) do
- e = assert_raise OptionParser::InvalidOption do
+ e = assert_raise Gem::OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
end
diff --git a/test/rubygems/test_gem_commands_yank_command.rb b/test/rubygems/test_gem_commands_yank_command.rb
index 3b0956e1c41..b798eb3689e 100644
--- a/test/rubygems/test_gem_commands_yank_command.rb
+++ b/test/rubygems/test_gem_commands_yank_command.rb
@@ -35,7 +35,7 @@ class TestGemCommandsYankCommand < Gem::TestCase
def test_handle_options_missing_argument
%w[-v --version -p --platform].each do |option|
- assert_raise OptionParser::MissingArgument do
+ assert_raise Gem::OptionParser::MissingArgument do
@cmd.handle_options %W[a #{option}]
end
end
diff --git a/test/rubygems/test_gem_ext_ext_conf_builder.rb b/test/rubygems/test_gem_ext_ext_conf_builder.rb
index 70833f35cfc..10a544cbbc4 100644
--- a/test/rubygems/test_gem_ext_ext_conf_builder.rb
+++ b/test/rubygems/test_gem_ext_ext_conf_builder.rb
@@ -66,8 +66,11 @@ class TestGemExtExtConfBuilder < Gem::TestCase
end
end
- def test_class_build_env_make
- env_make = ENV.delete 'MAKE'
+ def test_class_build_env_MAKE
+ env_make = ENV.delete 'make'
+ ENV['make'] = nil
+
+ env_MAKE = ENV.delete 'MAKE'
ENV['MAKE'] = 'anothermake'
if java_platform?
@@ -89,7 +92,8 @@ class TestGemExtExtConfBuilder < Gem::TestCase
assert_contains_make_command 'clean', output[4]
end
ensure
- ENV['MAKE'] = env_make
+ ENV['MAKE'] = env_MAKE
+ ENV['make'] = env_make
end
def test_class_build_extconf_fail
diff --git a/test/rubygems/test_gem_install_update_options.rb b/test/rubygems/test_gem_install_update_options.rb
index 33cb5c08bfd..a499c2be3be 100644
--- a/test/rubygems/test_gem_install_update_options.rb
+++ b/test/rubygems/test_gem_install_update_options.rb
@@ -104,7 +104,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
@cmd.add_install_update_options
- e = assert_raise OptionParser::InvalidArgument do
+ e = assert_raise Gem::OptionParser::InvalidArgument do
@cmd.handle_options %w[-P UnknownSecurity]
end
assert_includes e.message, "UnknownSecurity"
@@ -169,7 +169,7 @@ class TestGemInstallUpdateOptions < Gem::InstallerTestCase
def test_vendor_missing
vendordir(nil) do
- e = assert_raise OptionParser::InvalidOption do
+ e = assert_raise Gem::OptionParser::InvalidOption do
@cmd.handle_options %w[--vendor]
end
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index 988f14146d7..dae2b070d57 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -288,6 +288,33 @@ gem 'other', version
"(SyntaxError)", e.message
end
+ def test_ensure_no_race_conditions_between_installing_and_loading_gemspecs
+ a, a_gem = util_gem 'a', 2
+
+ Gem::Installer.at(a_gem).install
+
+ t1 = Thread.new do
+ 5.times do
+ Gem::Installer.at(a_gem).install
+ sleep 0.1
+ end
+ end
+
+ t2 = Thread.new do
+ _, err = capture_output do
+ 20.times do
+ Gem::Specification.load(a.spec_file)
+ Gem::Specification.send(:clear_load_cache)
+ end
+ end
+
+ assert_empty err
+ end
+
+ t1.join
+ t2.join
+ end
+
def test_ensure_loadable_spec_security_policy
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
@@ -948,7 +975,6 @@ gem 'other', version
Gem.pre_install do
assert_path_not_exist cache_file, 'cache file must not exist yet'
- assert_path_not_exist spec_file, 'spec file must not exist yet'
true
end
@@ -956,13 +982,11 @@ gem 'other', version
assert_path_exist gemdir, 'gem install dir must exist'
assert_path_exist rakefile, 'gem executable must exist'
assert_path_not_exist stub_exe, 'gem executable must not exist'
- assert_path_not_exist spec_file, 'spec file must not exist yet'
true
end
Gem.post_install do
assert_path_exist cache_file, 'cache file must exist'
- assert_path_exist spec_file, 'spec file must exist'
end
@newspec = nil
@@ -1237,7 +1261,11 @@ gem 'other', version
end
def test_install_post_build_false
- installer = setup_base_installer
+ @spec = util_spec 'a'
+
+ util_build_gem @spec
+
+ installer = util_installer @spec, @gemhome
Gem.post_build do
false
@@ -1279,7 +1307,11 @@ gem 'other', version
end
def test_install_pre_install_false
- installer = setup_base_installer
+ @spec = util_spec 'a'
+
+ util_build_gem @spec
+
+ installer = util_installer @spec, @gemhome
Gem.pre_install do
false
diff --git a/test/rubygems/test_gem_package.rb b/test/rubygems/test_gem_package.rb
index 3fa2c1911c4..48dcbee9f1f 100644
--- a/test/rubygems/test_gem_package.rb
+++ b/test/rubygems/test_gem_package.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative 'package/tar_test_case'
-require 'digest'
+require 'rubygems/openssl'
class TestGemPackage < Gem::Package::TarTestCase
def setup
@@ -84,17 +84,17 @@ class TestGemPackage < Gem::Package::TarTestCase
io.write spec.to_yaml
end
- metadata_sha256 = Digest::SHA256.hexdigest s.string
- metadata_sha512 = Digest::SHA512.hexdigest s.string
+ metadata_sha256 = OpenSSL::Digest::SHA256.hexdigest s.string
+ metadata_sha512 = OpenSSL::Digest::SHA512.hexdigest s.string
expected = {
'SHA512' => {
'metadata.gz' => metadata_sha512,
- 'data.tar.gz' => Digest::SHA512.hexdigest(tar),
+ 'data.tar.gz' => OpenSSL::Digest::SHA512.hexdigest(tar),
},
'SHA256' => {
'metadata.gz' => metadata_sha256,
- 'data.tar.gz' => Digest::SHA256.hexdigest(tar),
+ 'data.tar.gz' => OpenSSL::Digest::SHA256.hexdigest(tar),
},
}
@@ -574,18 +574,19 @@ class TestGemPackage < Gem::Package::TarTestCase
destination_subdir = File.join @destination, 'subdir'
FileUtils.mkdir_p destination_subdir
- e = assert_raise(Gem::Package::PathError, Errno::EACCES) do
+ expected_exceptions = win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
+
+ e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir
end
- if Gem::Package::PathError === e
- assert_equal("installing into parent path lib/link/outside.txt of " +
- "#{destination_subdir} is not allowed", e.message)
- elsif win_platform?
- pend "symlink - must be admin with no UAC on Windows"
- else
- raise e
- end
+ pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e
+
+ assert_equal("installing symlink 'lib/link' pointing to parent path #{@destination} of " +
+ "#{destination_subdir} is not allowed", e.message)
+
+ assert_path_not_exist File.join(@destination, "outside.txt")
+ assert_path_not_exist File.join(destination_subdir, "lib/link")
end
def test_extract_symlink_parent_doesnt_delete_user_dir
@@ -608,20 +609,20 @@ class TestGemPackage < Gem::Package::TarTestCase
tar.add_symlink 'link/dir', '.', 16877
end
- e = assert_raise(Gem::Package::PathError, Errno::EACCES) do
+ expected_exceptions = win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError]
+
+ e = assert_raise(*expected_exceptions) do
package.extract_tar_gz tgz_io, destination_subdir
end
- assert_path_exist destination_user_subdir
+ pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e
- if Gem::Package::PathError === e
- assert_equal("installing into parent path #{destination_user_subdir} of " +
- "#{destination_subdir} is not allowed", e.message)
- elsif win_platform?
- pend "symlink - must be admin with no UAC on Windows"
- else
- raise e
- end
+ assert_equal("installing symlink 'link' pointing to parent path #{destination_user_dir} of " +
+ "#{destination_subdir} is not allowed", e.message)
+
+ assert_path_exist destination_user_subdir
+ assert_path_not_exist File.join(destination_subdir, "link/dir")
+ assert_path_not_exist File.join(destination_subdir, "link")
end
def test_extract_tar_gz_directory
@@ -856,7 +857,7 @@ class TestGemPackage < Gem::Package::TarTestCase
io.write metadata_gz
end
- digest = Digest::SHA1.new
+ digest = OpenSSL::Digest::SHA1.new
digest << metadata_gz
checksums = {
@@ -1015,7 +1016,7 @@ class TestGemPackage < Gem::Package::TarTestCase
bogus_data = Gem::Util.gzip 'hello'
fake_signer = Class.new do
def digest_name; 'SHA512'; end
- def digest_algorithm; Digest(:SHA512).new; end
+ def digest_algorithm; OpenSSL::Digest(:SHA512).new; end
def key; 'key'; end
def sign(*); 'fake_sig'; end
end
diff --git a/test/rubygems/test_gem_request.rb b/test/rubygems/test_gem_request.rb
index 0c370c8a04f..47654f6fa41 100644
--- a/test/rubygems/test_gem_request.rb
+++ b/test/rubygems/test_gem_request.rb
@@ -185,7 +185,7 @@ class TestGemRequest < Gem::TestCase
end
def test_fetch
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}")
response = util_stub_net_http(:body => :junk, :code => 200) do
@request = make_request(uri, Net::HTTP::Get, nil, nil)
@@ -198,7 +198,7 @@ class TestGemRequest < Gem::TestCase
def test_fetch_basic_auth
Gem.configuration.verbose = :really
- uri = URI.parse "https://user:pass@example.rubygems/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "https://user:pass@example.rubygems/specs.#{Gem.marshal_version}")
conn = util_stub_net_http(:body => :junk, :code => 200) do |c|
use_ui @ui do
@request = make_request(uri, Net::HTTP::Get, nil, nil)
@@ -214,7 +214,7 @@ class TestGemRequest < Gem::TestCase
def test_fetch_basic_auth_encoded
Gem.configuration.verbose = :really
- uri = URI.parse "https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "https://user:%7BDEScede%7Dpass@example.rubygems/specs.#{Gem.marshal_version}")
conn = util_stub_net_http(:body => :junk, :code => 200) do |c|
use_ui @ui do
@@ -231,7 +231,7 @@ class TestGemRequest < Gem::TestCase
def test_fetch_basic_oauth_encoded
Gem.configuration.verbose = :really
- uri = URI.parse "https://%7BDEScede%7Dpass:x-oauth-basic@example.rubygems/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "https://%7BDEScede%7Dpass:x-oauth-basic@example.rubygems/specs.#{Gem.marshal_version}")
conn = util_stub_net_http(:body => :junk, :code => 200) do |c|
use_ui @ui do
@@ -247,7 +247,7 @@ class TestGemRequest < Gem::TestCase
end
def test_fetch_head
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}")
response = util_stub_net_http(:body => '', :code => 200) do |conn|
@request = make_request(uri, Net::HTTP::Get, nil, nil)
@request.fetch
@@ -258,7 +258,7 @@ class TestGemRequest < Gem::TestCase
end
def test_fetch_unmodified
- uri = URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}"
+ uri = Gem::Uri.new(URI.parse "#{@gem_repo}/specs.#{Gem.marshal_version}")
t = Time.utc(2013, 1, 2, 3, 4, 5)
conn, response = util_stub_net_http(:body => '', :code => 304) do |c|
@request = make_request(uri, Net::HTTP::Get, t, nil)
@@ -354,30 +354,36 @@ class TestGemRequest < Gem::TestCase
def test_verify_certificate
pend if Gem.java_platform?
+
+ error_number = OpenSSL::X509::V_ERR_OUT_OF_MEM
+
store = OpenSSL::X509::Store.new
context = OpenSSL::X509::StoreContext.new store
- context.error = OpenSSL::X509::V_ERR_OUT_OF_MEM
+ context.error = error_number
use_ui @ui do
Gem::Request.verify_certificate context
end
- assert_equal "ERROR: SSL verification error at depth 0: out of memory (17)\n",
+ assert_equal "ERROR: SSL verification error at depth 0: out of memory (#{error_number})\n",
@ui.error
end
def test_verify_certificate_extra_message
pend if Gem.java_platform?
+
+ error_number = OpenSSL::X509::V_ERR_INVALID_CA
+
store = OpenSSL::X509::Store.new
context = OpenSSL::X509::StoreContext.new store
- context.error = OpenSSL::X509::V_ERR_INVALID_CA
+ context.error = error_number
use_ui @ui do
Gem::Request.verify_certificate context
end
expected = <<-ERROR
-ERROR: SSL verification error at depth 0: invalid CA certificate (24)
+ERROR: SSL verification error at depth 0: invalid CA certificate (#{error_number})
ERROR: Certificate is an invalid CA certificate
ERROR
diff --git a/test/rubygems/test_gem_resolver.rb b/test/rubygems/test_gem_resolver.rb
index eb798ad557a..ea9f9049ceb 100644
--- a/test/rubygems/test_gem_resolver.rb
+++ b/test/rubygems/test_gem_resolver.rb
@@ -266,14 +266,14 @@ class TestGemResolver < Gem::TestCase
res = Gem::Resolver.new [a_dep], Gem::Resolver::IndexSet.new
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
res.resolve
end
refute_empty e.errors
end
- def test_no_overlap_specificly
+ def test_no_overlap_specifically
a = util_spec "a", '1'
b = util_spec "b", "1"
@@ -469,7 +469,7 @@ class TestGemResolver < Gem::TestCase
r = Gem::Resolver.new([ad], set)
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
r.resolve
end
@@ -486,7 +486,7 @@ class TestGemResolver < Gem::TestCase
r = Gem::Resolver.new([ad], set(a1))
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
r.resolve
end
@@ -499,7 +499,7 @@ class TestGemResolver < Gem::TestCase
r = Gem::Resolver.new([ad], set(a1))
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
r.resolve
end
@@ -516,7 +516,7 @@ class TestGemResolver < Gem::TestCase
r = Gem::Resolver.new([ad], set(a1))
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
r.resolve
end
@@ -781,7 +781,7 @@ class TestGemResolver < Gem::TestCase
r = Gem::Resolver.new([ad], set(a1))
- e = assert_raise Gem::UnsatisfiableDepedencyError do
+ e = assert_raise Gem::UnsatisfiableDependencyError do
r.resolve
end
diff --git a/test/rubygems/test_gem_security.rb b/test/rubygems/test_gem_security.rb
index 2eabbea3bfe..415ec2b5f64 100644
--- a/test/rubygems/test_gem_security.rb
+++ b/test/rubygems/test_gem_security.rb
@@ -12,6 +12,7 @@ end
class TestGemSecurity < Gem::TestCase
CHILD_KEY = load_key 'child'
+ EC_KEY = load_key 'private_ec', 'Foo bar'
ALTERNATE_CERT = load_cert 'child'
CHILD_CERT = load_cert 'child'
@@ -103,11 +104,38 @@ class TestGemSecurity < Gem::TestCase
end
def test_class_create_key
- key = @SEC.create_key 1024
+ key = @SEC.create_key 'rsa'
assert_kind_of OpenSSL::PKey::RSA, key
end
+ def test_class_create_key_downcases
+ key = @SEC.create_key 'DSA'
+
+ assert_kind_of OpenSSL::PKey::DSA, key
+ end
+
+ def test_class_create_key_raises_unknown_algorithm
+ e = assert_raise Gem::Security::Exception do
+ @SEC.create_key 'NOT_RSA'
+ end
+
+ assert_equal "NOT_RSA algorithm not found. RSA, DSA, and EC algorithms are supported.",
+ e.message
+ end
+
+ def test_class_get_public_key_rsa
+ pkey_pem = PRIVATE_KEY.public_key.to_pem
+
+ assert_equal pkey_pem, @SEC.get_public_key(PRIVATE_KEY).to_pem
+ end
+
+ def test_class_get_public_key_ec
+ pkey = @SEC.get_public_key(EC_KEY)
+
+ assert_respond_to pkey, :to_pem
+ end
+
def test_class_email_to_name
assert_equal '/CN=nobody/DC=example',
@SEC.email_to_name('nobody@example').to_s
@@ -168,7 +196,7 @@ class TestGemSecurity < Gem::TestCase
def test_class_sign
issuer = PUBLIC_CERT.subject
- signee = OpenSSL::X509::Name.parse "/CN=signee/DC=example"
+ signee = OpenSSL::X509::Name.new([["CN", "signee"], ["DC", "example"]])
key = PRIVATE_KEY
cert = OpenSSL::X509::Certificate.new
@@ -259,7 +287,7 @@ class TestGemSecurity < Gem::TestCase
end
def test_class_write
- key = @SEC.create_key 1024
+ key = @SEC.create_key 'rsa'
path = File.join @tempdir, 'test-private_key.pem'
@@ -273,7 +301,7 @@ class TestGemSecurity < Gem::TestCase
end
def test_class_write_encrypted
- key = @SEC.create_key 1024
+ key = @SEC.create_key 'rsa'
path = File.join @tempdir, 'test-private_encrypted_key.pem'
@@ -289,7 +317,7 @@ class TestGemSecurity < Gem::TestCase
end
def test_class_write_encrypted_cipher
- key = @SEC.create_key 1024
+ key = @SEC.create_key 'rsa'
path = File.join @tempdir, 'test-private_encrypted__with_non_default_cipher_key.pem'
diff --git a/test/rubygems/test_gem_server.rb b/test/rubygems/test_gem_server.rb
deleted file mode 100644
index f6aa99fb02e..00000000000
--- a/test/rubygems/test_gem_server.rb
+++ /dev/null
@@ -1,608 +0,0 @@
-# frozen_string_literal: true
-require_relative 'helper'
-require 'rubygems/server'
-require 'stringio'
-
-class Gem::Server
- attr_reader :server
-end
-
-class TestGemServer < Gem::TestCase
- def process_based_port
- 0
- end
-
- def setup
- super
-
- @a1 = quick_gem 'a', '1'
- @a2 = quick_gem 'a', '2'
- @a3_p = quick_gem 'a', '3.a'
-
- @server = Gem::Server.new Gem.dir, process_based_port, false
- @req = WEBrick::HTTPRequest.new :Logger => nil
- @res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
- end
-
- def test_doc_root_3
- orig_rdoc_version = Gem::RDoc.rdoc_version
- Gem::RDoc.instance_variable_set :@rdoc_version, Gem::Version.new('3.12')
-
- assert_equal '/doc_root/X-1/rdoc/index.html', @server.doc_root('X-1')
-
- ensure
- Gem::RDoc.instance_variable_set :@rdoc_version, orig_rdoc_version
- end
-
- def test_doc_root_4
- orig_rdoc_version = Gem::RDoc.rdoc_version
- Gem::RDoc.instance_variable_set :@rdoc_version, Gem::Version.new('4.0')
-
- assert_equal '/doc_root/X-1/', @server.doc_root('X-1')
-
- ensure
- Gem::RDoc.instance_variable_set :@rdoc_version, orig_rdoc_version
- end
-
- def test_have_rdoc_4_plus_eh
- orig_rdoc_version = Gem::RDoc.rdoc_version
- Gem::RDoc.instance_variable_set(:@rdoc_version, Gem::Version.new('4.0'))
-
- server = Gem::Server.new Gem.dir, 0, false
- assert server.have_rdoc_4_plus?
-
- Gem::RDoc.instance_variable_set :@rdoc_version, Gem::Version.new('3.12')
-
- server = Gem::Server.new Gem.dir, 0, false
- refute server.have_rdoc_4_plus?
-
- Gem::RDoc.instance_variable_set(:@rdoc_version,
- Gem::Version.new('4.0.0.preview2'))
-
- server = Gem::Server.new Gem.dir, 0, false
- assert server.have_rdoc_4_plus?
- ensure
- Gem::RDoc.instance_variable_set :@rdoc_version, orig_rdoc_version
- end
-
- def test_spec_dirs
- s = Gem::Server.new Gem.dir, process_based_port, false
-
- assert_equal [File.join(Gem.dir, 'specifications')], s.spec_dirs
-
- s = Gem::Server.new [Gem.dir, Gem.dir], process_based_port, false
-
- assert_equal [File.join(Gem.dir, 'specifications'),
- File.join(Gem.dir, 'specifications')], s.spec_dirs
- end
-
- def test_latest_specs
- data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- @req.parse data
-
- Gem::Deprecate.skip_during do
- @server.latest_specs @req, @res
- end
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/octet-stream', @res['content-type']
- assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
- Marshal.load(@res.body)
- end
-
- def test_latest_specs_gemdirs
- data = StringIO.new "GET /latest_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'z', 9
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.latest_specs @req, @res
-
- assert_equal 200, @res.status
-
- assert_equal [['z', v(9), Gem::Platform::RUBY]], Marshal.load(@res.body)
- end
-
- def test_latest_specs_gz
- data = StringIO.new "GET /latest_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- Gem::Deprecate.skip_during do
- @server.latest_specs @req, @res
- end
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/x-gzip', @res['content-type']
- assert_equal [['a', Gem::Version.new(2), Gem::Platform::RUBY]],
- Marshal.load(Gem::Util.gunzip(@res.body))
- end
-
- def test_listen
- util_listen
-
- capture_output do
- @server.listen
- end
-
- assert_equal 1, @server.server.listeners.length
- end
-
- def test_listen_addresses
- util_listen
-
- capture_output do
- @server.listen %w[a b]
- end
-
- assert_equal 2, @server.server.listeners.length
- end
-
- def test_prerelease_specs
- data = StringIO.new "GET /prerelease_specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- @req.parse data
-
- Gem::Deprecate.skip_during do
- @server.prerelease_specs @req, @res
- end
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/octet-stream', @res['content-type']
- assert_equal [['a', v('3.a'), Gem::Platform::RUBY]],
- Marshal.load(@res.body)
- end
-
- def test_prerelease_specs_gz
- data = StringIO.new "GET /prerelease_specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- Gem::Deprecate.skip_during do
- @server.prerelease_specs @req, @res
- end
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/x-gzip', @res['content-type']
- assert_equal [['a', v('3.a'), Gem::Platform::RUBY]],
- Marshal.load(Gem::Util.gunzip(@res.body))
- end
-
- def test_quick_gemdirs
- data = StringIO.new "GET /quick/Marshal.4.8/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.quick @req, @res
-
- assert_equal 404, @res.status
-
- spec = util_spec 'z', 9
-
- specs_dir = File.join dir, 'specifications'
-
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- data.rewind
-
- req = WEBrick::HTTPRequest.new :Logger => nil
- res = WEBrick::HTTPResponse.new :HTTPVersion => '1.0'
- req.parse data
-
- server.quick req, res
-
- assert_equal 200, res.status
- end
-
- def test_quick_missing
- data = StringIO.new "GET /quick/Marshal.4.8/z-9.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 404, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'text/plain', @res['content-type']
- assert_equal 'No gems found matching "z-9"', @res.body
- assert_equal 404, @res.status
- end
-
- def test_quick_marshal_a_1_gemspec_rz
- data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
-
- spec = Marshal.load Gem::Util.inflate(@res.body)
- assert_equal 'a', spec.name
- assert_equal Gem::Version.new(1), spec.version
- end
-
- def test_quick_marshal_a_1_mswin32_gemspec_rz
- quick_gem 'a', '1' do |s|
- s.platform = Gem::Platform.local
- end
-
- data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-1-#{Gem::Platform.local}.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
-
- spec = Marshal.load Gem::Util.inflate(@res.body)
- assert_equal 'a', spec.name
- assert_equal Gem::Version.new(1), spec.version
- assert_equal Gem::Platform.local, spec.platform
- end
-
- def test_quick_marshal_a_3_a_gemspec_rz
- data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-3.a.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
-
- spec = Marshal.load Gem::Util.inflate(@res.body)
- assert_equal 'a', spec.name
- assert_equal v('3.a'), spec.version
- end
-
- def test_quick_marshal_a_b_3_a_gemspec_rz
- quick_gem 'a-b', '3.a'
-
- data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-b-3.a.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
-
- spec = Marshal.load Gem::Util.inflate(@res.body)
- assert_equal 'a-b', spec.name
- assert_equal v('3.a'), spec.version
- end
-
- def test_quick_marshal_a_b_1_3_a_gemspec_rz
- quick_gem 'a-b-1', '3.a'
-
- data = StringIO.new "GET /quick/Marshal.#{Gem.marshal_version}/a-b-1-3.a.gemspec.rz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.quick @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert @res['date']
- assert_equal 'application/x-deflate', @res['content-type']
-
- spec = Marshal.load Gem::Util.inflate(@res.body)
- assert_equal 'a-b-1', spec.name
- assert_equal v('3.a'), spec.version
- end
-
- def test_rdoc
- data = StringIO.new "GET /rdoc?q=a HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.rdoc @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{No documentation found}, @res.body
- assert_equal 'text/html', @res['content-type']
- end
-
- def test_root
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.root @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'text/html', @res['content-type']
- end
-
- def test_root_gemdirs
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'z', 9
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.root @req, @res
-
- assert_equal 200, @res.status
- assert_match 'z 9', @res.body
- end
-
- def test_xss_homepage_fix_289313
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'xsshomepagegem', 1
- spec.homepage = "javascript:confirm(document.domain)"
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.root @req, @res
-
- assert_equal 200, @res.status
- assert_match 'xsshomepagegem 1', @res.body
-
- # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a
- # valid HTTP/HTTPS URL and could be unsafe in an HTML context. We would prefer to throw an exception here,
- # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be
- # validated in future versions of Gem::Specification.
- #
- # There are two variant we're checking here, one where rdoc is not present, and one where rdoc is present in the same regex:
- #
- # Variant #1 - rdoc not installed
- #
- # <b>xsshomepagegem 1</b>
- #
- #
- # <span title="rdoc not installed">[rdoc]</span>
- #
- #
- #
- # <a href="." title=".">[www]</a>
- #
- # Variant #2 - rdoc installed
- #
- # <b>xsshomepagegem 1</b>
- #
- #
- # <a href="\/doc_root\/xsshomepagegem-1\/">\[rdoc\]<\/a>
- #
- #
- #
- # <a href="." title=".">[www]</a>
- regex_match = /xsshomepagegem 1<\/b>\s+(<span title="rdoc not installed">\[rdoc\]<\/span>|<a href="\/doc_root\/xsshomepagegem-1\/">\[rdoc\]<\/a>)\s+<a href="\." title="\.">\[www\]<\/a>/
- assert_match regex_match, @res.body
- end
-
- def test_invalid_homepage
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'invalidhomepagegem', 1
- spec.homepage = "notavalidhomepageurl"
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.root @req, @res
-
- assert_equal 200, @res.status
- assert_match 'invalidhomepagegem 1', @res.body
-
- # This verifies that the homepage for this spec is not displayed and is set to ".", because it's not a
- # valid HTTP/HTTPS URL and could be unsafe in an HTML context. We would prefer to throw an exception here,
- # but spec.homepage is currently free form and not currently required to be a URL, this behavior may be
- # validated in future versions of Gem::Specification.
- #
- # There are two variant we're checking here, one where rdoc is not present, and one where rdoc is present in the same regex:
- #
- # Variant #1 - rdoc not installed
- #
- # <b>invalidhomepagegem 1</b>
- #
- #
- # <span title="rdoc not installed">[rdoc]</span>
- #
- #
- #
- # <a href="." title=".">[www]</a>
- #
- # Variant #2 - rdoc installed
- #
- # <b>invalidhomepagegem 1</b>
- #
- #
- # <a href="\/doc_root\/invalidhomepagegem-1\/">\[rdoc\]<\/a>
- #
- #
- #
- # <a href="." title=".">[www]</a>
- regex_match = /invalidhomepagegem 1<\/b>\s+(<span title="rdoc not installed">\[rdoc\]<\/span>|<a href="\/doc_root\/invalidhomepagegem-1\/">\[rdoc\]<\/a>)\s+<a href="\." title="\.">\[www\]<\/a>/
- assert_match regex_match, @res.body
- end
-
- def test_valid_homepage_http
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'validhomepagegemhttp', 1
- spec.homepage = "http://rubygems.org"
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.root @req, @res
-
- assert_equal 200, @res.status
- assert_match 'validhomepagegemhttp 1', @res.body
-
- regex_match = /validhomepagegemhttp 1<\/b>\s+(<span title="rdoc not installed">\[rdoc\]<\/span>|<a href="\/doc_root\/validhomepagegemhttp-1\/">\[rdoc\]<\/a>)\s+<a href="http:\/\/rubygems\.org" title="http:\/\/rubygems\.org">\[www\]<\/a>/
- assert_match regex_match, @res.body
- end
-
- def test_valid_homepage_https
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'validhomepagegemhttps', 1
- spec.homepage = "https://rubygems.org"
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.root @req, @res
-
- assert_equal 200, @res.status
- assert_match 'validhomepagegemhttps 1', @res.body
-
- regex_match = /validhomepagegemhttps 1<\/b>\s+(<span title="rdoc not installed">\[rdoc\]<\/span>|<a href="\/doc_root\/validhomepagegemhttps-1\/">\[rdoc\]<\/a>)\s+<a href="https:\/\/rubygems\.org" title="https:\/\/rubygems\.org">\[www\]<\/a>/
- assert_match regex_match, @res.body
- end
-
- def test_specs
- data = StringIO.new "GET /specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.specs @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/octet-stream', @res['content-type']
-
- assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
- ['a', Gem::Version.new(2), Gem::Platform::RUBY],
- ['a', v('3.a'), Gem::Platform::RUBY]],
- Marshal.load(@res.body)
- end
-
- def test_specs_gemdirs
- data = StringIO.new "GET /specs.#{Gem.marshal_version} HTTP/1.0\r\n\r\n"
- dir = "#{@gemhome}2"
-
- spec = util_spec 'z', 9
-
- specs_dir = File.join dir, 'specifications'
- FileUtils.mkdir_p specs_dir
-
- File.open File.join(specs_dir, spec.spec_name), 'w' do |io|
- io.write spec.to_ruby
- end
-
- server = Gem::Server.new dir, process_based_port, false
-
- @req.parse data
-
- server.specs @req, @res
-
- assert_equal 200, @res.status
-
- assert_equal [['z', v(9), Gem::Platform::RUBY]], Marshal.load(@res.body)
- end
-
- def test_specs_gz
- data = StringIO.new "GET /specs.#{Gem.marshal_version}.gz HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.specs @req, @res
-
- assert_equal 200, @res.status, @res.body
- assert_match %r{ \d\d:\d\d:\d\d }, @res['date']
- assert_equal 'application/x-gzip', @res['content-type']
-
- assert_equal [['a', Gem::Version.new(1), Gem::Platform::RUBY],
- ['a', Gem::Version.new(2), Gem::Platform::RUBY],
- ['a', v('3.a'), Gem::Platform::RUBY]],
- Marshal.load(Gem::Util.gunzip(@res.body))
- end
-
- def test_uri_encode
- url_safe = @server.uri_encode 'http://rubyonrails.org/">malicious_content</a>'
- assert_equal url_safe, 'http://rubyonrails.org/%22%3Emalicious_content%3C/a%3E'
- end
-
- # Regression test for issue #1793: incorrect URL encoding.
- # Checking that no URLs have had '://' incorrectly encoded
- def test_regression_1793
- data = StringIO.new "GET / HTTP/1.0\r\n\r\n"
- @req.parse data
-
- @server.root @req, @res
-
- refute_match %r{%3A%2F%2F}, @res.body
- end
-
- def util_listen
- webrick = Object.new
- webrick.instance_variable_set :@listeners, []
- def webrick.listeners() @listeners end
- def webrick.listen(host, port)
- socket = Object.new
- socket.instance_variable_set :@host, host
- socket.instance_variable_set :@port, port
- def socket.addr() [nil, @port, @host] end
- @listeners << socket
- end
-
- @server.instance_variable_set :@server, webrick
- end
-end
diff --git a/test/rubygems/test_gem_source_fetch_problem.rb b/test/rubygems/test_gem_source_fetch_problem.rb
index 0b1472c0c60..816407781d4 100644
--- a/test/rubygems/test_gem_source_fetch_problem.rb
+++ b/test/rubygems/test_gem_source_fetch_problem.rb
@@ -23,4 +23,14 @@ class TestGemSourceFetchProblem < Gem::TestCase
refute_match sf.wordy, 'secret'
end
+
+ def test_source_password_no_redacted
+ source = Gem::Source.new 'https://username:secret@gemsource.com'
+ error = RuntimeError.new 'test'
+
+ sf = Gem::SourceFetchProblem.new source, error
+ sf.wordy
+
+ assert_match 'secret', source.uri.to_s
+ end
end
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 88afa3faa01..bfd0db347e6 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -127,265 +127,241 @@ end
end
def test_self_activate_ambiguous_direct
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec("b", "1", { "c" => ">= 1" }, "lib/d#{$$}.rb")
- b2 = util_spec("b", "2", { "c" => ">= 2" }, "lib/d#{$$}.rb")
- c1 = util_spec "c", "1"
- c2 = util_spec "c", "2"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec("b", "1", { "c" => ">= 1" }, "lib/d#{$$}.rb")
+ b2 = util_spec("b", "2", { "c" => ">= 2" }, "lib/d#{$$}.rb")
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2"
- Gem::Specification.reset
- install_specs c1, c2, b1, b2, a1
+ Gem::Specification.reset
+ install_specs c1, c2, b1, b2, a1
- a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1 b-2 c-2], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_find_in_unresolved_tree_is_not_exponentiental
- save_loaded_features do
- num_of_pkg = 7
- num_of_version_per_pkg = 3
- packages = (0..num_of_pkg).map do |pkgi|
- (0..num_of_version_per_pkg).map do |pkg_version|
- deps = Hash[((pkgi + 1)..num_of_pkg).map do |deppkgi|
- ["pkg#{deppkgi}", ">= 0"]
- end]
- util_spec "pkg#{pkgi}", pkg_version.to_s, deps
- end
+ num_of_pkg = 7
+ num_of_version_per_pkg = 3
+ packages = (0..num_of_pkg).map do |pkgi|
+ (0..num_of_version_per_pkg).map do |pkg_version|
+ deps = Hash[((pkgi + 1)..num_of_pkg).map do |deppkgi|
+ ["pkg#{deppkgi}", ">= 0"]
+ end]
+ util_spec "pkg#{pkgi}", pkg_version.to_s, deps
end
- base = util_spec "pkg_base", "1", {"pkg0" => ">= 0"}
+ end
+ base = util_spec "pkg_base", "1", {"pkg0" => ">= 0"}
- Gem::Specification.reset
- install_specs(*packages.flatten.reverse)
- install_specs base
- base.activate
+ Gem::Specification.reset
+ install_specs(*packages.flatten.reverse)
+ install_specs base
+ base.activate
- tms = Benchmark.measure do
- assert_raise(LoadError) { require 'no_such_file_foo' }
- end
- assert_operator tms.total, :<=, 10
+ tms = Benchmark.measure do
+ assert_raise(LoadError) { require 'no_such_file_foo' }
end
+ assert_operator tms.total, :<=, 10
end
def test_self_activate_ambiguous_indirect
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
- c2 = util_spec "c", "2", nil, "lib/d#{$$}.rb"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
+ c2 = util_spec "c", "2", nil, "lib/d#{$$}.rb"
- install_specs c1, c2, b1, b2, a1
+ install_specs c1, c2, b1, b2, a1
- a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1 b-2 c-2], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_self_activate_ambiguous_indirect_conflict
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- a2 = util_spec "a", "2", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
- c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
+ a1 = util_spec "a", "1", "b" => "> 0"
+ a2 = util_spec "a", "2", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
+ c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
- install_specs c1, b1, a1, a2, c2, b2
+ install_specs c1, b1, a1, a2, c2, b2
- a2.activate
- assert_equal %w[a-2], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a2.activate
+ assert_equal %w[a-2], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-2 b-1 c-1], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-2 b-1 c-1], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_self_activate_ambiguous_unrelated
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1"
- c2 = util_spec "c", "2"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb"
- install_specs d1, c1, c2, b1, b2, a1
+ install_specs d1, c1, c2, b1, b2, a1
- a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 d-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
- end
+ assert_equal %w[a-1 d-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
end
def test_require_should_prefer_latest_gem_level1
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
- b2 = util_spec "b", "2", "c" => ">= 0"
- c1 = util_spec "c", "1", nil, "lib/c#{$$}.rb" # 1st level
- c2 = util_spec "c", "2", nil, "lib/c#{$$}.rb"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = util_spec "b", "2", "c" => ">= 0"
+ c1 = util_spec "c", "1", nil, "lib/c#{$$}.rb" # 1st level
+ c2 = util_spec "c", "2", nil, "lib/c#{$$}.rb"
- install_specs c1, c2, b1, b2, a1
+ install_specs c1, c2, b1, b2, a1
- a1.activate
+ a1.activate
- require "c#{$$}"
+ require "c#{$$}"
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
- end
+ assert_equal %w[a-1 b-2 c-2], loaded_spec_names
end
def test_require_should_prefer_latest_gem_level2
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
- b2 = util_spec "b", "2", "c" => ">= 0"
- c1 = util_spec "c", "1", "d" => ">= 0" # 1st level
- c2 = util_spec "c", "2", "d" => ">= 0"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = util_spec "b", "2", "c" => ">= 0"
+ c1 = util_spec "c", "1", "d" => ">= 0" # 1st level
+ c2 = util_spec "c", "2", "d" => ">= 0"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
+ d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
- install_specs d1, d2, c1, c2, b1, b2, a1
+ install_specs d1, d2, c1, c2, b1, b2, a1
- a1.activate
+ a1.activate
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
- end
+ assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
def test_require_finds_in_2nd_level_indirect
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
- b2 = util_spec "b", "2", "c" => ">= 0"
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
- c2 = util_spec "c", "2", "d" => "<= 2"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = util_spec "b", "2", "c" => ">= 0"
+ c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = util_spec "c", "2", "d" => "<= 2"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
+ d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
+ d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
- install_specs d1, d2, d3, c1, c2, b1, b2, a1
+ install_specs d1, d2, d3, c1, c2, b1, b2, a1
- a1.activate
+ a1.activate
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
- end
+ assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
def test_require_should_prefer_reachable_gems
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
- b2 = util_spec "b", "2", "c" => ">= 0"
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
- c2 = util_spec "c", "2", "d" => "<= 2"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
- e = util_spec "anti_d", "1", nil, "lib/d#{$$}.rb"
-
- install_specs d1, d2, d3, e, c1, c2, b1, b2, a1
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 0" # unresolved
+ b2 = util_spec "b", "2", "c" => ">= 0"
+ c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = util_spec "c", "2", "d" => "<= 2"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
+ d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
+ d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
+ e = util_spec "anti_d", "1", nil, "lib/d#{$$}.rb"
+
+ install_specs d1, d2, d3, e, c1, c2, b1, b2, a1
- a1.activate
+ a1.activate
- require "d#{$$}"
+ require "d#{$$}"
- assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
- end
+ assert_equal %w[a-1 b-2 c-2 d-2], loaded_spec_names
end
def test_require_should_not_conflict
- save_loaded_features do
- base = util_spec "0", "1", "A" => ">= 1"
- a1 = util_spec "A", "1", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
- a2 = util_spec "A", "2", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
- b1 = util_spec "b", "1", {"c" => "= 1"}, "lib/d#{$$}.rb"
- b2 = util_spec "b", "2", {"c" => "= 2"}, "lib/d#{$$}.rb"
- c1 = util_spec "c", "1", {}, "lib/c.rb"
- c2 = util_spec "c", "2", {}, "lib/c.rb"
- c3 = util_spec "c", "3", {}, "lib/c.rb"
-
- install_specs c1, c2, c3, b1, b2, a1, a2, base
-
- base.activate
- assert_equal %w[0-1], loaded_spec_names
- assert_equal ["A (>= 1)"], unresolved_names
+ base = util_spec "0", "1", "A" => ">= 1"
+ a1 = util_spec "A", "1", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
+ a2 = util_spec "A", "2", {"c" => ">= 2", "b" => "> 0"}, "lib/a.rb"
+ b1 = util_spec "b", "1", {"c" => "= 1"}, "lib/d#{$$}.rb"
+ b2 = util_spec "b", "2", {"c" => "= 2"}, "lib/d#{$$}.rb"
+ c1 = util_spec "c", "1", {}, "lib/c.rb"
+ c2 = util_spec "c", "2", {}, "lib/c.rb"
+ c3 = util_spec "c", "3", {}, "lib/c.rb"
- require "d#{$$}"
+ install_specs c1, c2, c3, b1, b2, a1, a2, base
- assert_equal %w[0-1 A-2 b-2 c-2], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ base.activate
+ assert_equal %w[0-1], loaded_spec_names
+ assert_equal ["A (>= 1)"], unresolved_names
+
+ require "d#{$$}"
+
+ assert_equal %w[0-1 A-2 b-2 c-2], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_inner_clonflict_in_indirect_gems
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1" # unresolved
- b2 = util_spec "b", "2", "c" => ">= 1", "d" => "< 3"
- c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
- c2 = util_spec "c", "2", "d" => "<= 2"
- c3 = util_spec "c", "3", "d" => "<= 3"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
-
- install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1" # unresolved
+ b2 = util_spec "b", "2", "c" => ">= 1", "d" => "< 3"
+ c1 = util_spec "c", "1", "d" => "<= 2" # 1st level
+ c2 = util_spec "c", "2", "d" => "<= 2"
+ c3 = util_spec "c", "3", "d" => "<= 3"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
+ d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
+ d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
+
+ install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
- a1.activate
+ a1.activate
- require "d#{$$}"
+ require "d#{$$}"
- assert_includes [%w[a-1 b-2 c-3 d-2],%w[a-1 b-2 d-2]], loaded_spec_names
- end
+ assert_includes [%w[a-1 b-2 c-3 d-2],%w[a-1 b-2 d-2]], loaded_spec_names
end
def test_inner_clonflict_in_indirect_gems_reversed
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- b1 = util_spec "b", "1", "xc" => ">= 1" # unresolved
- b2 = util_spec "b", "2", "xc" => ">= 1", "d" => "< 3"
- c1 = util_spec "xc", "1", "d" => "<= 3" # 1st level
- c2 = util_spec "xc", "2", "d" => "<= 2"
- c3 = util_spec "xc", "3", "d" => "<= 3"
- d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
- d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
- d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
-
- install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
+ a1 = util_spec "a", "1", "b" => "> 0"
+ b1 = util_spec "b", "1", "xc" => ">= 1" # unresolved
+ b2 = util_spec "b", "2", "xc" => ">= 1", "d" => "< 3"
+ c1 = util_spec "xc", "1", "d" => "<= 3" # 1st level
+ c2 = util_spec "xc", "2", "d" => "<= 2"
+ c3 = util_spec "xc", "3", "d" => "<= 3"
+ d1 = util_spec "d", "1", nil, "lib/d#{$$}.rb" # 2nd level
+ d2 = util_spec "d", "2", nil, "lib/d#{$$}.rb"
+ d3 = util_spec "d", "3", nil, "lib/d#{$$}.rb"
+
+ install_specs d1, d2, d3, c1, c2, c3, b1, b2, a1
- a1.activate
+ a1.activate
- require "d#{$$}"
+ require "d#{$$}"
- assert_includes [%w[a-1 b-2 d-2 xc-3], %w[a-1 b-2 d-2]], loaded_spec_names
- end
+ assert_includes [%w[a-1 b-2 d-2 xc-3], %w[a-1 b-2 d-2]], loaded_spec_names
end
##
@@ -509,41 +485,37 @@ end
install_specs b1, b2, a1
a1.activate
- save_loaded_features do
- require "b/c"
- end
+ require "b/c"
assert_equal %w[a-1 b-1], loaded_spec_names
end
def test_self_activate_via_require_wtf
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
- b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b#{$$}.rb"
- b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b#{$$}.rb" # this
- c1 = util_spec "c", "1"
- c2 = util_spec "c", "2" # this
- d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d#{$$}.rb"
- d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d#{$$}.rb" # this
+ a1 = util_spec "a", "1", "b" => "> 0", "d" => "> 0" # this
+ b1 = util_spec "b", "1", { "c" => ">= 1" }, "lib/b#{$$}.rb"
+ b2 = util_spec "b", "2", { "c" => ">= 2" }, "lib/b#{$$}.rb" # this
+ c1 = util_spec "c", "1"
+ c2 = util_spec "c", "2" # this
+ d1 = util_spec "d", "1", { "c" => "< 2" }, "lib/d#{$$}.rb"
+ d2 = util_spec "d", "2", { "c" => "< 2" }, "lib/d#{$$}.rb" # this
- install_specs c1, c2, b1, b2, d1, d2, a1
+ install_specs c1, c2, b1, b2, d1, d2, a1
- a1.activate
+ a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal ["b (> 0)", "d (> 0)"], unresolved_names
- require "b#{$$}"
+ require "b#{$$}"
- e = assert_raise Gem::LoadError do
- require "d#{$$}"
- end
+ e = assert_raise Gem::LoadError do
+ require "d#{$$}"
+ end
- assert_equal "unable to find a version of 'd' to activate", e.message
+ assert_equal "unable to find a version of 'd' to activate", e.message
- assert_equal %w[a-1 b-2 c-2], loaded_spec_names
- assert_equal ["d (> 0)"], unresolved_names
- end
+ assert_equal %w[a-1 b-2 c-2], loaded_spec_names
+ assert_equal ["d (> 0)"], unresolved_names
end
def test_self_activate_deep_unambiguous
@@ -2146,43 +2118,39 @@ dependencies: []
end
def test_require_already_activated
- save_loaded_features do
- a1 = util_spec "a", "1", nil, "lib/d#{$$}.rb"
+ a1 = util_spec "a", "1", nil, "lib/d#{$$}.rb"
- install_specs a1 # , a2, b1, b2, c1, c2
+ install_specs a1 # , a2, b1, b2, c1, c2
- a1.activate
- assert_equal %w[a-1], loaded_spec_names
- assert_equal [], unresolved_names
+ a1.activate
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal [], unresolved_names
- assert require "d#{$$}"
+ assert require "d#{$$}"
- assert_equal %w[a-1], loaded_spec_names
- assert_equal [], unresolved_names
- end
+ assert_equal %w[a-1], loaded_spec_names
+ assert_equal [], unresolved_names
end
def test_require_already_activated_indirect_conflict
- save_loaded_features do
- a1 = util_spec "a", "1", "b" => "> 0"
- a2 = util_spec "a", "2", "b" => "> 0"
- b1 = util_spec "b", "1", "c" => ">= 1"
- b2 = util_spec "b", "2", "c" => ">= 2"
- c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
- c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
+ a1 = util_spec "a", "1", "b" => "> 0"
+ a2 = util_spec "a", "2", "b" => "> 0"
+ b1 = util_spec "b", "1", "c" => ">= 1"
+ b2 = util_spec "b", "2", "c" => ">= 2"
+ c1 = util_spec "c", "1", nil, "lib/d#{$$}.rb"
+ c2 = util_spec("c", "2", { "a" => "1" }, "lib/d#{$$}.rb") # conflicts with a-2
- install_specs c1, b1, a1, a2, c2, b2
+ install_specs c1, b1, a1, a2, c2, b2
- a1.activate
- c1.activate
- assert_equal %w[a-1 c-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
+ a1.activate
+ c1.activate
+ assert_equal %w[a-1 c-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
- assert require "d#{$$}"
+ assert require "d#{$$}"
- assert_equal %w[a-1 c-1], loaded_spec_names
- assert_equal ["b (> 0)"], unresolved_names
- end
+ assert_equal %w[a-1 c-1], loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
end
def test_requirements
@@ -2781,6 +2749,34 @@ duplicate dependency on c (>= 1.2.3, development), (~> 1.2) use:
end
assert_equal %("#{f}" or "#{t}" is not a description), e.message
+
+ # Adding #{f} anywhere after the start of the description should be fine.
+ @a1.description = "(some description) #{f}"
+
+ assert_nothing_raised do
+ @a1.validate
+ end
+
+ # Adding #{t} anywhere after the start of the description should be fine.
+ @a1.description = "(some description) #{t}"
+
+ assert_nothing_raised do
+ @a1.validate
+ end
+
+ # Adding #{f} at the start of the second or later line should be fine.
+ @a1.description = "(some description)\n#{f}"
+
+ assert_nothing_raised do
+ @a1.validate
+ end
+
+ # Adding #{t} at the start of the second or later line should be fine.
+ @a1.description = "(some description)\n#{t}"
+
+ assert_nothing_raised do
+ @a1.validate
+ end
end
end
@@ -3070,6 +3066,17 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license.
WARNING
end
+ def test_validate_license_ref
+ util_setup_validate
+
+ use_ui @ui do
+ @a1.licenses = ['LicenseRef-LICENSE.md']
+ @a1.validate
+ end
+
+ assert_empty @ui.error
+ end
+
def test_validate_license_values_plus
util_setup_validate
diff --git a/test/rubygems/test_gem_uri.rb b/test/rubygems/test_gem_uri.rb
index 0c70443f329..7fe572518b6 100644
--- a/test/rubygems/test_gem_uri.rb
+++ b/test/rubygems/test_gem_uri.rb
@@ -29,4 +29,11 @@ class TestUri < Gem::TestCase
def test_redacted_with_invalid_uri
assert_equal "https://www.example.com:80index", Gem::Uri.new("https://www.example.com:80index").redacted.to_s
end
+
+ def test_redacted_does_not_modify_uri
+ url = 'https://user:password@example.com'
+ uri = Gem::Uri.new(url)
+ assert_equal 'https://user:REDACTED@example.com', uri.redacted.to_s
+ assert_equal url, uri.to_s
+ end
end
diff --git a/test/rubygems/test_require.rb b/test/rubygems/test_require.rb
index 07e412cc765..4d0301742e3 100644
--- a/test/rubygems/test_require.rb
+++ b/test/rubygems/test_require.rb
@@ -466,8 +466,7 @@ class TestGemRequire < Gem::TestCase
end
def test_realworld_default_gem
- testing_ruby_repo = !ENV["GEM_COMMAND"].nil?
- pend "this test can't work under ruby-core setup" if testing_ruby_repo || java_platform?
+ omit "this test can't work under ruby-core setup" if testing_ruby_repo?
cmd = <<-RUBY
$stderr = $stdout
@@ -480,8 +479,7 @@ class TestGemRequire < Gem::TestCase
end
def test_realworld_upgraded_default_gem
- testing_ruby_repo = !ENV["GEM_COMMAND"].nil?
- pend "this test can't work under ruby-core setup" if testing_ruby_repo
+ omit "this test can't work under ruby-core setup" if testing_ruby_repo?
newer_json = util_spec("json", "999.99.9", nil, ["lib/json.rb"])
install_gem newer_json
@@ -720,6 +718,10 @@ class TestGemRequire < Gem::TestCase
private
+ def testing_ruby_repo?
+ !ENV["GEM_COMMAND"].nil?
+ end
+
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield
diff --git a/test/runner.rb b/test/runner.rb
index a24cfa31c63..1b1ae0956a8 100644
--- a/test/runner.rb
+++ b/test/runner.rb
@@ -4,6 +4,8 @@
ENV["GEM_SKIP"] = ENV["GEM_HOME"] = ENV["GEM_PATH"] = "".freeze
ENV.delete("RUBY_CODESIGN")
+Warning[:experimental] = false
+
# Get bundled gems on load path
Dir.glob("#{__dir__}/../.bundle/gems/*/*.gemspec")
.reject {|f| f =~ /minitest|test-unit|power_assert/ }
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index 9807db36743..16c359eca15 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -1,9 +1,5 @@
# frozen_string_literal: true
-# tentatively disabled due to IPv6 configuration issue on Solaris CI
-# http://rubyci.s3.amazonaws.com/solaris10-gcc/ruby-master/log/20210729T040002Z.fail.html.gz
-return if /solaris/ =~ RUBY_PLATFORM
-
begin
require "socket"
require "tmpdir"
diff --git a/test/test_getoptlong.rb b/test/test_getoptlong.rb
new file mode 100644
index 00000000000..0cd370b6c75
--- /dev/null
+++ b/test/test_getoptlong.rb
@@ -0,0 +1,163 @@
+require 'test/unit'
+require 'getoptlong'
+
+class TestGetoptLong < Test::Unit::TestCase
+
+ def verify(test_argv, expected_remaining_argv, expected_options)
+ # Save ARGV and replace it with a test ARGV.
+ argv_saved = ARGV.dup
+ ARGV.replace(test_argv)
+ # Define options.
+ opts = GetoptLong.new(
+ ['--xxx', '-x', '--aaa', '-a', GetoptLong::REQUIRED_ARGUMENT],
+ ['--yyy', '-y', '--bbb', '-b', GetoptLong::OPTIONAL_ARGUMENT],
+ ['--zzz', '-z', '--ccc', '-c', GetoptLong::NO_ARGUMENT]
+ )
+ opts.quiet = true
+ # Gather options.
+ actual_options = []
+ opts.each do |opt, arg|
+ actual_options << "#{opt}: #{arg}"
+ end
+ # Save remaining test ARGV and restore original ARGV.
+ actual_remaining_argv = ARGV.dup
+ ARGV.replace(argv_saved)
+ # Assert.
+ assert_equal(expected_remaining_argv, actual_remaining_argv, 'ARGV')
+ assert_equal(expected_options, actual_options, 'Options')
+ end
+
+ def test_no_options
+ expected_options = []
+ expected_argv = %w[foo bar]
+ argv = %w[foo bar]
+ verify(argv, expected_argv, expected_options)
+ end
+
+ def test_required_argument
+ expected_options = [
+ '--xxx: arg'
+ ]
+ expected_argv = %w[foo bar]
+ options = %w[--xxx --xx --x -x --aaa --aa --a -a]
+ options.each do |option|
+ argv = ['foo', option, 'arg', 'bar']
+ verify(argv, expected_argv, expected_options)
+ end
+ end
+
+ def test_required_argument_missing
+ options = %w[--xxx --xx --x -x --aaa --aa --a -a]
+ options.each do |option|
+ argv = [option]
+ e = assert_raise(GetoptLong::MissingArgument) do
+ verify(argv, [], [])
+ end
+ assert_match('requires an argument', e.message)
+ end
+ end
+
+ def test_optional_argument
+ expected_options = [
+ '--yyy: arg'
+ ]
+ expected_argv = %w[foo bar]
+ options = %w[--yyy --y --y -y --bbb --bb --b -b]
+ options.each do |option|
+ argv = ['foo', 'bar', option, 'arg']
+ verify(argv, expected_argv, expected_options)
+ end
+ end
+
+ def test_optional_argument_missing
+ expected_options = [
+ '--yyy: '
+ ]
+ expected_argv = %w[foo bar]
+ options = %w[--yyy --y --y -y --bbb --bb --b -b]
+ options.each do |option|
+ argv = ['foo', 'bar', option]
+ verify(argv, expected_argv, expected_options)
+ end
+ end
+
+ def test_no_argument
+ expected_options = [
+ '--zzz: '
+ ]
+ expected_argv = %w[foo bar]
+ options = %w[--zzz --zz --z -z --ccc --cc --c -c]
+ options.each do |option|
+ argv = ['foo', option, 'bar']
+ verify(argv, expected_argv, expected_options)
+ end
+ end
+
+ def test_new_with_empty_array
+ e = assert_raise(ArgumentError) do
+ GetoptLong.new([])
+ end
+ assert_match(/no argument-flag/, e.message)
+ end
+
+ def test_new_with_bad_array
+ e = assert_raise(ArgumentError) do
+ GetoptLong.new('foo')
+ end
+ assert_match(/option list contains non-Array argument/, e.message)
+ end
+
+ def test_new_with_empty_subarray
+ e = assert_raise(ArgumentError) do
+ GetoptLong.new([[]])
+ end
+ assert_match(/no argument-flag/, e.message)
+ end
+
+ def test_new_with_bad_subarray
+ e = assert_raise(ArgumentError) do
+ GetoptLong.new([1])
+ end
+ assert_match(/no option name/, e.message)
+ end
+
+ def test_new_with_invalid_option
+ invalid_options = %w[verbose -verbose -- +]
+ invalid_options.each do |invalid_option|
+ e = assert_raise(ArgumentError, invalid_option.to_s) do
+ arguments = [
+ [invalid_option, '-v', GetoptLong::NO_ARGUMENT]
+ ]
+ GetoptLong.new(*arguments)
+ end
+ assert_match(/invalid option/, e.message)
+ end
+ end
+
+ def test_new_with_invalid_alias
+ invalid_aliases = %w[v - -- +]
+ invalid_aliases.each do |invalid_alias|
+ e = assert_raise(ArgumentError, invalid_alias.to_s) do
+ arguments = [
+ ['--verbose', invalid_alias, GetoptLong::NO_ARGUMENT]
+ ]
+ GetoptLong.new(*arguments)
+ end
+ assert_match(/invalid option/, e.message)
+ end
+ end
+
+ def test_new_with_invalid_flag
+ invalid_flags = ['foo']
+ invalid_flags.each do |invalid_flag|
+ e = assert_raise(ArgumentError, invalid_flag.to_s) do
+ arguments = [
+ ['--verbose', '-v', invalid_flag]
+ ]
+ GetoptLong.new(*arguments)
+ end
+ assert_match(/no argument-flag/, e.message)
+ end
+ end
+
+end
diff --git a/test/test_ipaddr.rb b/test/test_ipaddr.rb
index 7b3a199bf3e..2afe749db3e 100644
--- a/test/test_ipaddr.rb
+++ b/test/test_ipaddr.rb
@@ -43,6 +43,17 @@ class TC_IPAddr < Test::Unit::TestCase
assert_equal("3ffe:0505:0002:0000:0000:0000:0000:0000", a.to_string)
assert_equal(Socket::AF_INET6, a.family)
assert_equal(48, a.prefix)
+ assert_nil(a.zone_id)
+
+ a = IPAddr.new("fe80::1%ab0")
+ assert_equal("fe80::1%ab0", a.to_s)
+ assert_equal("fe80:0000:0000:0000:0000:0000:0000:0001%ab0", a.to_string)
+ assert_equal(Socket::AF_INET6, a.family)
+ assert_equal(false, a.ipv4?)
+ assert_equal(true, a.ipv6?)
+ assert_equal("#<IPAddr: IPv6:fe80:0000:0000:0000:0000:0000:0000:0001%ab0/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>", a.inspect)
+ assert_equal(128, a.prefix)
+ assert_equal('%ab0', a.zone_id)
a = IPAddr.new("0.0.0.0")
assert_equal("0.0.0.0", a.to_s)
@@ -87,10 +98,14 @@ class TC_IPAddr < Test::Unit::TestCase
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.256") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.011") }
- assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("fe80::1%fxp0") }
+ assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("fe80::1%") }
+ assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("fe80::1%]") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[192.168.1.2]/120") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[2001:200:300::]\nINVALID") }
assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32\nINVALID") }
+ assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32/20") }
+ assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/032") }
+ assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/0128") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/255.255.255.0") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/129") }
assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/33") }
@@ -116,6 +131,23 @@ class TC_IPAddr < Test::Unit::TestCase
assert_equal("192.168.2.1", IPAddr.new_ntoh(a.hton).to_s)
end
+ def test_ntop
+ # IPv4
+ assert_equal("192.168.1.1", IPAddr.ntop("\xC0\xA8\x01\x01"))
+ # IPv6
+ assert_equal("0000:0000:0000:0000:0000:0000:0000:0001",
+ IPAddr.ntop("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"))
+
+ # Invalid parameters
+ assert_raise(IPAddr::AddressFamilyError) {
+ IPAddr.ntop("192.168.1.1")
+ }
+
+ assert_raise(IPAddr::AddressFamilyError) {
+ IPAddr.ntop("\xC0\xA8\x01\xFF1")
+ }
+ end
+
def test_ipv4_compat
a = IPAddr.new("::192.168.1.2")
assert_equal("::192.168.1.2", a.to_s)
@@ -200,6 +232,29 @@ class TC_IPAddr < Test::Unit::TestCase
assert_equal("3ffe:0505:0002:0000:0000:0000:0000:0001", IPAddr.new("3ffe:505:2::1").to_string)
assert_equal("3ffe:505:2::1", IPAddr.new("3ffe:505:2::1").to_s)
end
+
+ def test_netmask
+ a = IPAddr.new("192.168.1.2/8")
+ assert_equal(a.netmask, "255.0.0.0")
+
+ a = IPAddr.new("192.168.1.2/16")
+ assert_equal(a.netmask, "255.255.0.0")
+
+ a = IPAddr.new("192.168.1.2/24")
+ assert_equal(a.netmask, "255.255.255.0")
+ end
+
+ def test_zone_id
+ a = IPAddr.new("192.168.1.2")
+ assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%ab0' }
+ assert_raise(IPAddr::InvalidAddressError) { a.zone_id }
+
+ a = IPAddr.new("1:2:3:4:5:6:7:8")
+ a.zone_id = '%ab0'
+ assert_equal('%ab0', a.zone_id)
+ assert_equal("1:2:3:4:5:6:7:8%ab0", a.to_s)
+ assert_raise(IPAddr::InvalidAddressError) { a.zone_id = '%' }
+ end
end
class TC_Operator < Test::Unit::TestCase
@@ -295,6 +350,8 @@ class TC_Operator < Test::Unit::TestCase
assert_equal(true, net1.include?(IPAddr.new("192.168.2.0")))
assert_equal(true, net1.include?(IPAddr.new("192.168.2.255")))
assert_equal(false, net1.include?(IPAddr.new("192.168.3.0")))
+ assert_equal(true, net1.include?(IPAddr.new("192.168.2.0/28")))
+ assert_equal(false, net1.include?(IPAddr.new("192.168.2.0/16")))
# test with integer parameter
int = (192 << 24) + (168 << 16) + (2 << 8) + 13
diff --git a/test/test_timeout.rb b/test/test_timeout.rb
index 71607ed6805..74b65f119d2 100644
--- a/test/test_timeout.rb
+++ b/test/test_timeout.rb
@@ -3,6 +3,17 @@ require 'test/unit'
require 'timeout'
class TestTimeout < Test::Unit::TestCase
+
+ def test_non_timing_out_code_is_successful
+ assert_nothing_raised do
+ assert_equal :ok, Timeout.timeout(1){ :ok }
+ end
+ end
+
+ def test_yield_param
+ assert_equal [5, :ok], Timeout.timeout(5){|s| [s, :ok] }
+ end
+
def test_queue
q = Thread::Queue.new
assert_raise(Timeout::Error, "[ruby-dev:32935]") {
diff --git a/test/uri/test_http.rb b/test/uri/test_http.rb
index cc19046c8f4..748e90a3220 100644
--- a/test/uri/test_http.rb
+++ b/test/uri/test_http.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'uri/http'
+require 'uri/https'
module URI
@@ -24,14 +25,16 @@ class TestHTTP < Test::Unit::TestCase
def test_parse
u = URI.parse('http://a')
assert_kind_of(URI::HTTP, u)
- assert_equal(['http',
- nil, 'a', URI::HTTP.default_port,
- '', nil, nil], uri_to_ary(u))
+ assert_equal([
+ 'http',
+ nil, 'a', URI::HTTP.default_port,
+ '', nil, nil
+ ], uri_to_ary(u))
end
def test_normalize
host = 'aBcD'
- u1 = URI.parse('http://' + host + '/eFg?HiJ')
+ u1 = URI.parse('http://' + host + '/eFg?HiJ')
u2 = URI.parse('http://' + host.downcase + '/eFg?HiJ')
assert(u1.normalize.host == 'abcd')
assert(u1.normalize.path == u1.path)
@@ -49,11 +52,11 @@ class TestHTTP < Test::Unit::TestCase
end
def test_request_uri
- assert_equal('/', URI.parse('http://a.b.c/').request_uri)
+ assert_equal('/', URI.parse('http://a.b.c/').request_uri)
assert_equal('/?abc=def', URI.parse('http://a.b.c/?abc=def').request_uri)
- assert_equal('/', URI.parse('http://a.b.c').request_uri)
+ assert_equal('/', URI.parse('http://a.b.c').request_uri)
assert_equal('/?abc=def', URI.parse('http://a.b.c?abc=def').request_uri)
- assert_equal(nil, URI.parse('http:foo').request_uri)
+ assert_equal(nil, URI.parse('http:foo').request_uri)
end
def test_select
@@ -64,6 +67,20 @@ class TestHTTP < Test::Unit::TestCase
u.select(:scheme, :host, :not_exist, :port)
end
end
+
+ def test_authority
+ assert_equal('a.b.c', URI.parse('http://a.b.c/').authority)
+ assert_equal('a.b.c:8081', URI.parse('http://a.b.c:8081/').authority)
+ assert_equal('a.b.c', URI.parse('http://a.b.c:80/').authority)
+ end
+
+
+ def test_origin
+ assert_equal('http://a.b.c', URI.parse('http://a.b.c/').origin)
+ assert_equal('http://a.b.c:8081', URI.parse('http://a.b.c:8081/').origin)
+ assert_equal('http://a.b.c', URI.parse('http://a.b.c:80/').origin)
+ assert_equal('https://a.b.c', URI.parse('https://a.b.c/').origin)
+ end
end
diff --git a/test/win32ole/test_win32ole.rb b/test/win32ole/test_win32ole.rb
index 39417805285..e5f9d35e249 100644
--- a/test/win32ole/test_win32ole.rb
+++ b/test/win32ole/test_win32ole.rb
@@ -101,7 +101,7 @@ if defined?(WIN32OLE)
assert_include(mnames, 'Count')
end
- def test_ole_mehtod_help
+ def test_ole_method_help
minfo = @dict1.ole_method_help("Add")
assert_equal(2, minfo.size_params)
end
diff --git a/test/win32ole/test_win32ole_event.rb b/test/win32ole/test_win32ole_event.rb
index 742bff4f7a5..fa9e7b5b080 100644
--- a/test/win32ole/test_win32ole_event.rb
+++ b/test/win32ole/test_win32ole_event.rb
@@ -65,12 +65,13 @@ if defined?(WIN32OLE_EVENT)
if watch_ivar
# wait until event is proceeded
tries = 0
+ seconds = EnvUtil.apply_timeout_scale(1)
while tries < 5 && instance_variable_get(watch_ivar) == orig_ivar
- seconds = 2 ** tries # sleep at most 31s in total
$stderr.puts "test_win32ole_event.rb: retrying and sleeping #{seconds}s until #{watch_ivar} is changed from #{orig_ivar.inspect}..."
WIN32OLE_EVENT.message_loop
sleep(seconds)
tries += 1
+ seconds *= 2 # sleep at most 31s in total
end
end
end
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index a629c0c902a..1e57c5aa8c6 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -538,30 +538,36 @@ if defined? Zlib
end
def test_recursive_deflate
+ original_gc_stress = GC.stress
+ GC.stress = true
zd = Zlib::Deflate.new
s = SecureRandom.random_bytes(1024**2)
- assert_raise(Zlib::BufError) do
+ assert_raise(Zlib::InProgressError) do
zd.deflate(s) do
zd.deflate(s)
end
end
ensure
+ GC.stress = original_gc_stress
zd&.finish
zd&.close
end
def test_recursive_inflate
+ original_gc_stress = GC.stress
+ GC.stress = true
zi = Zlib::Inflate.new
s = Zlib.deflate(SecureRandom.random_bytes(1024**2))
- assert_raise(Zlib::DataError) do
+ assert_raise(Zlib::InProgressError) do
zi.inflate(s) do
zi.inflate(s)
end
end
ensure
+ GC.stress = original_gc_stress
zi&.close
end
end