Skip to content

Commit

Permalink
Update tests from MRI 2.5 branch (2.4ish)
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Dec 12, 2018
1 parent 7b964fd commit 0e23fb9
Show file tree
Hide file tree
Showing 104 changed files with 1,667 additions and 256 deletions.
16 changes: 16 additions & 0 deletions test/mri/-ext-/debug/test_debug.rb
Expand Up @@ -56,4 +56,20 @@ def test_inspector_open_in_eval
binds = inspector_in_eval
binds_check binds, bug7635
end

class MyRelation
include Enumerable

def each
yield :each_entry
end
end

def test_lazy_block
x = MyRelation.new.any? do
Bug::Debug.inspector
true
end
assert_equal true, x, '[Bug #15105]'
end
end
11 changes: 11 additions & 0 deletions test/mri/-ext-/funcall/test_funcall.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true
require 'test/unit'

class TestFuncall < Test::Unit::TestCase
require '-test-/funcall'

def test_funcall_extra_args
assert_equal 'TestFuncall', TestFuncall.extra_args_name,
'[ruby-core:85266] [Bug #14425]'
end
end
13 changes: 13 additions & 0 deletions test/mri/date/test_date_arith.rb
Expand Up @@ -262,4 +262,17 @@ def test_step__noblock
assert_equal(8, e.to_a.size)
end

def test_step__compare
o = Object.new
def o.<=>(*);end
assert_raise(ArgumentError) {
Date.new(2000, 1, 1).step(3, o).to_a
}

o = Object.new
def o.<=>(*);2;end
a = []
Date.new(2000, 1, 1).step(3, o) {|d| a << d}
assert_empty(a)
end
end
2 changes: 2 additions & 0 deletions test/mri/dbm/test_dbm.rb
Expand Up @@ -47,6 +47,8 @@ def teardown
end

def test_delete_rdonly
skip("skipped because root can read anything") if Process.uid == 0

if /^CYGWIN_9/ !~ SYSTEM
assert_raise(DBMError) {
@dbm_rdonly.delete("foo")
Expand Down
7 changes: 7 additions & 0 deletions test/mri/erb/test_erb.rb
Expand Up @@ -622,6 +622,13 @@ def test_result_with_hash_with_invalid_keys_raises_type_error
erb = @erb.new("<%= 1 %>")
assert_raise(TypeError) { erb.result_with_hash({ 1 => "1" }) }
end

# Bug#14243
def test_half_working_comment_backward_compatibility
assert_nothing_raised do
@erb.new("<% # comment %>\n").result
end
end
end

class TestERBCoreWOStrScan < TestERBCore
Expand Down
4 changes: 4 additions & 0 deletions test/mri/gdbm/test_gdbm.rb
Expand Up @@ -43,6 +43,8 @@ def teardown
end

def test_delete_rdonly
skip("skipped because root can open anything") if Process.uid == 0

if /^CYGWIN_9/ !~ SYSTEM
assert_raise(GDBMError) {
@gdbm_rdonly.delete("foo")
Expand Down Expand Up @@ -211,6 +213,8 @@ def test_s_open_nolock
end if defined? GDBM::NOLOCK # gdbm 1.8.0 specific

def test_s_open_error
skip if Process.uid == 0 # because root can open anything

assert_instance_of(GDBM, gdbm = GDBM.open("#{@tmpdir}/#{@prefix}", 0))
assert_raise(Errno::EACCES, Errno::EWOULDBLOCK) {
GDBM.open("#{@tmpdir}/#{@prefix}", 0)
Expand Down
1 change: 1 addition & 0 deletions test/mri/irb/test_workspace.rb
Expand Up @@ -34,6 +34,7 @@ def test_code_around_binding

def test_code_around_binding_with_existing_unreadable_file
skip 'chmod cannot make file unreadable on windows' if windows?
skip 'skipped in root privilege' if Process.uid == 0

Tempfile.create do |f|
code = "IRB::WorkSpace.new(binding)\n"
Expand Down
10 changes: 0 additions & 10 deletions test/mri/json/json_addition_test.rb
Expand Up @@ -5,7 +5,6 @@
require 'json/add/rational'
require 'json/add/bigdecimal'
require 'json/add/ostruct'
require 'json/add/set'
require 'date'

class JSONAdditionTest < Test::Unit::TestCase
Expand Down Expand Up @@ -191,13 +190,4 @@ def test_ostruct
o.foo = { 'bar' => true }
assert_equal o, parse(JSON(o), :create_additions => true)
end

def test_set
s = Set.new([:a, :b, :c, :a])
assert_equal s, JSON.parse(JSON(s), :create_additions => true)
ss = SortedSet.new([:d, :b, :a, :c])
ss_again = JSON.parse(JSON(ss), :create_additions => true)
assert_kind_of ss.class, ss_again
assert_equal ss, ss_again
end
end
4 changes: 4 additions & 0 deletions test/mri/json/test_helper.rb
Expand Up @@ -15,3 +15,7 @@
require 'byebug'
rescue LoadError
end
if ENV['START_SIMPLECOV'].to_i == 1
require 'simplecov'
SimpleCov.start
end
2 changes: 1 addition & 1 deletion test/mri/lib/envutil.rb
Expand Up @@ -147,7 +147,7 @@ def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr =
stderr = stderr_filter.call(stderr) if stderr_filter
if timeout_error
bt = caller_locations
msg = "execution of #{bt.shift.label} expired"
msg = "execution of #{bt.shift.label} expired timeout (#{timeout} sec)"
msg = Test::Unit::Assertions::FailDesc[status, msg, [stdout, stderr].join("\n")].()
raise timeout_error, msg, bt.map(&:to_s)
end
Expand Down
2 changes: 0 additions & 2 deletions test/mri/lib/test/unit/assertions.rb
Expand Up @@ -595,8 +595,6 @@ def assert_normal_exit(testsrc, message = '', child_env: nil, **opt)

def assert_in_out_err(args, test_stdin = "", test_stdout = [], test_stderr = [], message = nil,
success: nil, **opt)
args = Array(args).dup
args.insert((Hash === args[0] ? 1 : 0), '--disable=gems')
stdout, stderr, status = EnvUtil.invoke_ruby(args, test_stdin, true, true, **opt)
if signo = status.termsig
EnvUtil.diagnostic_reports(Signal.signame(signo), status.pid, Time.now)
Expand Down
6 changes: 6 additions & 0 deletions test/mri/net/ftp/test_buffered_socket.rb
Expand Up @@ -33,6 +33,12 @@ def test_gets_two_lines_without_term
assert_equal("bar", sock.gets)
end

def test_read_nil
sock = create_buffered_socket("foo\nbar")
assert_equal("foo\nbar", sock.read)
assert_equal("", sock.read)
end

private

def create_buffered_socket(s)
Expand Down
2 changes: 1 addition & 1 deletion test/mri/net/ftp/test_ftp.rb
Expand Up @@ -425,7 +425,7 @@ def test_list_read_timeout_exceeded
end
conn.print(l, "\r\n")
end
rescue Errno::EPIPE, Errno::EPROTOTYPE
rescue Errno::EPIPE
ensure
assert_nil($!)
conn.close
Expand Down
37 changes: 37 additions & 0 deletions test/mri/net/imap/test_imap.rb
Expand Up @@ -530,6 +530,43 @@ def test_send_invalid_number
end
end

def test_send_literal
server = create_tcp_server
port = server.addr[1]
requests = []
literal = nil
@threads << Thread.start do
sock = server.accept
begin
sock.print("* OK test server\r\n")
line = sock.gets
requests.push(line)
size = line.slice(/{(\d+)}\r\n/, 1).to_i
sock.print("+ Ready for literal data\r\n")
literal = sock.read(size)
requests.push(sock.gets)
sock.print("RUBY0001 OK TEST completed\r\n")
sock.gets
sock.print("* BYE terminating connection\r\n")
sock.print("RUBY0002 OK LOGOUT completed\r\n")
ensure
sock.close
server.close
end
end
begin
imap = Net::IMAP.new(server_addr, :port => port)
imap.send(:send_command, "TEST", ["\xDE\xAD\xBE\xEF".b])
assert_equal(2, requests.length)
assert_equal("RUBY0001 TEST ({4}\r\n", requests[0])
assert_equal("\xDE\xAD\xBE\xEF".b, literal)
assert_equal(")\r\n", requests[1])
imap.logout
ensure
imap.disconnect
end
end

def test_disconnect
server = create_tcp_server
port = server.addr[1]
Expand Down
29 changes: 29 additions & 0 deletions test/mri/net/pop/test_pop.rb
Expand Up @@ -64,6 +64,35 @@ def test_apop_invalid_at
end
end

def test_popmail
# totally not representative of real messages, but
# enough to test frozen bugs
lines = [ "[ruby-core:85210]" , "[Bug #14416]" ].freeze
command = Object.new
command.instance_variable_set(:@lines, lines)

def command.retr(n)
@lines.each { |l| yield "#{l}\r\n" }
end

def command.top(number, nl)
@lines.each do |l|
yield "#{l}\r\n"
break if (nl -= 1) <= 0
end
end

net_pop = :unused
popmail = Net::POPMail.new(1, 123, net_pop, command)
res = popmail.pop
assert_equal "[ruby-core:85210]\r\n[Bug #14416]\r\n", res
assert_not_predicate res, :frozen?

res = popmail.top(1)
assert_equal "[ruby-core:85210]\r\n", res
assert_not_predicate res, :frozen?
end

def pop_test(apop=false)
host = 'localhost'
server = TCPServer.new(host, 0)
Expand Down
3 changes: 3 additions & 0 deletions test/mri/openssl/test_cipher.rb
Expand Up @@ -44,6 +44,9 @@ def test_pkcs5_keyivgen
s2 = cipher.update(pt) << cipher.final

assert_equal s1, s2

cipher2 = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
assert_raise(ArgumentError) { cipher2.pkcs5_keyivgen(pass, salt, -1, "MD5") }
end

def test_info
Expand Down
9 changes: 8 additions & 1 deletion test/mri/openssl/test_pkey_rsa.rb
Expand Up @@ -60,6 +60,13 @@ def test_new_with_exponent
end
end

def test_generate
key = OpenSSL::PKey::RSA.generate(512, 17)
assert_equal 512, key.n.num_bits
assert_equal 17, key.e
assert_not_nil key.d
end

def test_new_break
assert_nil(OpenSSL::PKey::RSA.new(1024) { break })
assert_raise(RuntimeError) do
Expand Down Expand Up @@ -289,7 +296,7 @@ def test_pem_passwd
end

def test_dup
key = OpenSSL::PKey::RSA.generate(256, 17)
key = Fixtures.pkey("rsa1024")
key2 = key.dup
assert_equal key.params, key2.params
key2.set_key(key2.n, 3, key2.d)
Expand Down

0 comments on commit 0e23fb9

Please sign in to comment.