Skip to content

Commit

Permalink
Merge branch 'master' into ruby-2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Nov 14, 2016
2 parents befa5c5 + 4fcf792 commit 8aa6f68
Show file tree
Hide file tree
Showing 64 changed files with 920 additions and 219 deletions.
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -2805,6 +2805,11 @@ static IRubyObject nonblockEOF(final Ruby runtime, final boolean noException) {

@JRubyMethod(name = "readpartial", required = 1, optional = 1)
public IRubyObject readpartial(ThreadContext context, IRubyObject[] args) {
// ruby bug 11885
if (args.length == 2) {
args[1] = args[1].convertToString();
}

IRubyObject value = getPartial(context, args, false, false);

if (value.isNil()) {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -815,6 +815,7 @@ public static IRubyObject sprintf(ThreadContext context, IRubyObject recv, IRuby
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
final Ruby runtime = context.runtime;
int argc = args.length;
boolean forceCause = false;

// semi extract_raise_opts :
IRubyObject cause = null;
Expand All @@ -824,6 +825,7 @@ public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyOb
RubyHash opt = (RubyHash) last; RubySymbol key;
if ( ! opt.isEmpty() && ( opt.has_key_p( key = runtime.newSymbol("cause") ) == runtime.getTrue() ) ) {
cause = opt.delete(context, key, Block.NULL_BLOCK);
forceCause = true;
if ( opt.isEmpty() && --argc == 0 ) { // more opts will be passed along
throw runtime.newArgumentError("only cause is given with no arguments");
}
Expand Down Expand Up @@ -868,7 +870,7 @@ public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyOb
printExceptionSummary(context, runtime, raise.getException());
}

if (argc > 0 && raise.getException().getCause() == UNDEF && cause != raise.getException()) {
if (forceCause || argc > 0 && raise.getException().getCause() == UNDEF && cause != raise.getException()) {
raise.getException().setCause(cause);
}

Expand Down
13 changes: 10 additions & 3 deletions test/mri/-ext-/float/test_nextafter.rb
Expand Up @@ -46,9 +46,16 @@ class TestFloatExt < Test::Unit::TestCase
if v1 == 0
s1 = 1.0/v1 < 0 ? "negative-zero" : "positive-zero"
s2 = 1.0/v2 < 0 ? "negative-zero" : "positive-zero"
assert_equal(s1, s2,
"Bug::Float.missing_nextafter(#{'%a' % n1}, #{'%a' % n2}) = #{'%a' % v1} != " +
"#{'%a' % v2} = Bug::Float.system_nextafter(#{'%a' % n1}, #{'%a' % n2})")
begin
assert_equal(s1, s2,
"Bug::Float.missing_nextafter(#{'%a' % n1}, #{'%a' % n2}) = #{'%a' % v1} != " +
"#{'%a' % v2} = Bug::Float.system_nextafter(#{'%a' % n1}, #{'%a' % n2})")
rescue Minitest::Assertion
if /aix/ =~ RUBY_PLATFORM
skip "Known bug in nextafter(3) on AIX"
end
raise $!
end
end
end
}
Expand Down
6 changes: 6 additions & 0 deletions test/mri/-ext-/string/test_cstr.rb
Expand Up @@ -36,6 +36,12 @@ def test_frozen
end
end

def test_rb_str_new_frozen_embed
str = Bug::String.cstr_noembed("rbconfig.rb")
str = Bug::String.rb_str_new_frozen(str)
assert_equal true, Bug::String.cstr_embedded?(str)
end

WCHARS = [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE]

def test_wchar_embed
Expand Down
22 changes: 22 additions & 0 deletions test/mri/-ext-/struct/test_duplicate.rb
@@ -0,0 +1,22 @@
# frozen_string_literal: false
require 'test/unit'
require "-test-/struct"

class Bug::Struct::Test_Duplicate < Test::Unit::TestCase
def test_new_dupilicate
bug12291 = '[ruby-core:74971] [Bug #12291]'
assert_raise_with_message(ArgumentError, /duplicate member/, bug12291) {
Bug::Struct.new_duplicate(nil, "a")
}
assert_raise_with_message(ArgumentError, /duplicate member/, bug12291) {
Bug::Struct.new_duplicate("X", "a")
}
end

def test_new_dupilicate_under
bug12291 = '[ruby-core:74971] [Bug #12291]'
assert_raise_with_message(ArgumentError, /duplicate member/, bug12291) {
Bug::Struct.new_duplicate_under("x", "a")
}
end
end
8 changes: 8 additions & 0 deletions test/mri/-ext-/symbol/test_inadvertent_creation.rb
Expand Up @@ -54,6 +54,14 @@ def test_module_const_get
assert_not_interned_error(cl, :const_get, name.to_sym)
end

def test_module_const_get_toplevel
bug12089 = '[ruby-dev:49498] [Bug #12089]'
name = noninterned_name("A")
e = assert_not_interned_error(Object, :const_get, name)
assert_equal(name, e.name)
assert_not_match(/Object::/, e.message, bug12089)
end

def test_module_const_defined?
cl = Class.new
name = noninterned_name("A")
Expand Down
6 changes: 5 additions & 1 deletion test/mri/-ext-/time/test_new.rb
Expand Up @@ -23,7 +23,11 @@ def test_timespec_new
assert_equal(false, Bug::Time.timespec_new(1447087832, 476451125, 0).utc?)
assert_equal(true, Bug::Time.timespec_new(1447087832, 476451125, 0x7ffffffe).utc?)
assert_equal(false, Bug::Time.timespec_new(1447087832, 476451125, 0x7fffffff).utc?)
assert_equal(Time.now.gmtoff, Bug::Time.timespec_new(1447087832, 476451125, 0x7fffffff).gmtoff)
# Cannot compare Time.now.gmtoff with
# Bug::Time.timespec_new(1447087832, 476451125, 0x7fffffff).gmtoff, because
# it depends on whether the current time is in summer time (daylight-saving time) or not.
t = Time.now
assert_equal(t.gmtoff, Bug::Time.timespec_new(t.tv_sec, t.tv_nsec, 0x7fffffff).gmtoff)
assert_time_equal(Time.at(1447087832, 476451.125).localtime(86399),
Bug::Time.timespec_new(1447087832, 476451125, 86399))
assert_time_equal(Time.at(1447087832, 476451.125).localtime(-86399),
Expand Down
19 changes: 19 additions & 0 deletions test/mri/-ext-/vm/test_at_exit.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: false
class TestVM < Test::Unit::TestCase

# [Bug #12095]
def test_at_exit

assert_in_out_err([], <<-"end;", %w[begin end]) # do
require '-test-/vm/at_exit'
Bug::VM.register_at_exit(false)
1000.times do
Bug::VM.register_at_exit(nil)
["x"]*1000
end
GC.start
Bug::VM.register_at_exit(true)
end;
end
end

2 changes: 2 additions & 0 deletions test/mri/excludes/TestException.rb
Expand Up @@ -13,3 +13,5 @@
exclude :test_output_string_encoding, "Exception messages always go through Java String for us"
exclude :test_stackoverflow, reason
exclude :test_too_many_args_in_eval, "MRI raises SystemStackError for huge number of args, for some reason"
exclude :test_name_error_local_variables, "JRuby does not support extracting local variables from a NameError"
exclude :test_name_error_info_parent_iseq_mark, "JRuby does not support extracting local variables from a NameError"
4 changes: 4 additions & 0 deletions test/mri/excludes/TestJSON.rb
@@ -1,3 +1,7 @@
exclude :test_load_with_options, "needs investigation"
exclude :test_parse_generic_object, "needs investigation"
exclude :test_symbolize_names, "needs investigation"
exclude :test_argument_encoding, "jruby/jruby#4281"
exclude :test_error_message_encoding, "jruby/jruby#4281"
exclude :test_parse_json_primitive_values, "jruby/jruby#4282"
exclude :test_wrong_inputs, "jruby/jruby#4283"
3 changes: 1 addition & 2 deletions test/mri/io/console/test_io_console.rb
Expand Up @@ -302,8 +302,7 @@ class TestIO_Console < Test::Unit::TestCase
noctty = [EnvUtil.rubybin, "-e", "Process.daemon(true)"]
when !(rubyw = RbConfig::CONFIG["RUBYW_INSTALL_NAME"]).empty?
dir, base = File.split(EnvUtil.rubybin)
base = base.sub(/ruby/, rubyw) if base != rubyw
noctty = [File.join(dir, base)]
noctty = [File.join(dir, base.sub(/ruby/, rubyw))]
end

if noctty
Expand Down
30 changes: 26 additions & 4 deletions test/mri/lib/test/unit.rb
Expand Up @@ -87,7 +87,7 @@ def setup_options(opts, options)
end

opts.on '-n', '--name PATTERN', "Filter test method names on pattern: /REGEXP/ or STRING" do |a|
options[:filter] = a
(options[:filter] ||= []) << a
end

opts.on '--test-order=random|alpha|sorted', [:random, :alpha, :sorted] do |a|
Expand All @@ -96,6 +96,30 @@ def setup_options(opts, options)
end

def non_options(files, options)
filter = options[:filter]
if filter
pos_pat = /\A\/(.*)\/\z/
neg_pat = /\A!\/(.*)\/\z/
negative, positive = filter.partition {|s| neg_pat =~ s}
if positive.empty?
filter = nil
elsif negative.empty? and positive.size == 1 and pos_pat !~ positive[0]
filter = positive[0]
else
filter = Regexp.union(*positive.map! {|s| s[pos_pat, 1] || "\\A#{Regexp.quote(s)}\\z"})
end
unless negative.empty?
negative = Regexp.union(*negative.map! {|s| s[neg_pat, 1]})
filter = /\A(?!.*#{negative})#{filter}/
end
if Regexp === filter
# bypass conversion in minitest
def filter.=~(other) # :nodoc:
super unless Regexp === other
end
end
options[:filter] = filter
end
true
end
end
Expand Down Expand Up @@ -589,9 +613,7 @@ def _prepare_run(suites, type)
@verbose = !options[:parallel]
@output = Output.new(self)
end
if /\A\/(.*)\/\z/ =~ (filter = options[:filter])
filter = Regexp.new($1)
end
filter = options[:filter]
type = "#{type}_methods"
total = if filter
suites.inject(0) {|n, suite| n + suite.send(type).grep(filter).size}
Expand Down
1 change: 1 addition & 0 deletions test/mri/lib/test/unit/assertions.rb
Expand Up @@ -490,6 +490,7 @@ def assert_syntax_error(code, error, fname = caller_locations(1, 1)[0], mesg = f
catch {|tag| eval(code, binding, fname, line)}
end
assert_match(error, e.message, mesg)
e
ensure
$VERBOSE = verbose
end
Expand Down
8 changes: 8 additions & 0 deletions test/mri/net/ftp/test_ftp.rb
Expand Up @@ -29,6 +29,14 @@ def test_not_connected
end
end

def test_closed_when_not_connected
ftp = Net::FTP.new
assert_equal(true, ftp.closed?)
assert_nothing_raised(Net::FTPConnectionError) do
ftp.close
end
end

def test_connect_fail
server = create_ftp_server { |sock|
sock.print("421 Service not available, closing control connection.\r\n")
Expand Down
6 changes: 3 additions & 3 deletions test/mri/net/http/test_http.rb
Expand Up @@ -151,12 +151,12 @@ def test_proxy_eh_ENV_no_proxy

def test_proxy_port
clean_http_proxy_env do
http = Net::HTTP.new 'exmaple', nil, 'proxy.example'
http = Net::HTTP.new 'example', nil, 'proxy.example'
assert_equal 'proxy.example', http.proxy_address
assert_equal 80, http.proxy_port
http = Net::HTTP.new 'exmaple', nil, 'proxy.example', 8000
http = Net::HTTP.new 'example', nil, 'proxy.example', 8000
assert_equal 8000, http.proxy_port
http = Net::HTTP.new 'exmaple', nil
http = Net::HTTP.new 'example', nil
assert_equal nil, http.proxy_port
end
end
Expand Down
32 changes: 22 additions & 10 deletions test/mri/net/imap/test_imap.rb
Expand Up @@ -310,19 +310,31 @@ def test_idle_timeout
begin
imap = Net::IMAP.new(SERVER_ADDR, :port => port)
responses = []
Thread.pass
Thread.pass
imap.idle(0.2) do |res|
responses.push(res)
end
assert_equal(3, responses.length)
assert_instance_of(Net::IMAP::ContinuationRequest, responses[0])
assert_equal("EXISTS", responses[1].name)
assert_equal(3, responses[1].data)
assert_equal("EXPUNGE", responses[2].name)
assert_equal(2, responses[2].data)
assert_equal(2, requests.length)
assert_equal("RUBY0001 IDLE\r\n", requests[0])
assert_equal("DONE\r\n", requests[1])
# There is no gurantee that this thread has received all the responses,
# so check the response length.
if responses.length > 0
assert_instance_of(Net::IMAP::ContinuationRequest, responses[0])
if responses.length > 1
assert_equal("EXISTS", responses[1].name)
assert_equal(3, responses[1].data)
if responses.length > 2
assert_equal("EXPUNGE", responses[2].name)
assert_equal(2, responses[2].data)
end
end
end
# Also, there is no gurantee that the server thread has stored
# all the requests into the array, so check the length.
if requests.length > 0
assert_equal("RUBY0001 IDLE\r\n", requests[0])
if requests.length > 1
assert_equal("DONE\r\n", requests[1])
end
end
imap.logout
ensure
imap.disconnect if imap
Expand Down
2 changes: 1 addition & 1 deletion test/mri/openssl/test_config.rb
Expand Up @@ -168,7 +168,7 @@ def test_get_value_ENV
end

def test_value
# supress deprecation warnings
# suppress deprecation warnings
OpenSSL::TestUtils.silent do
assert_equal('CA_default', @it.value('ca', 'default_ca'))
assert_equal(nil, @it.value('ca', 'no such key'))
Expand Down
4 changes: 3 additions & 1 deletion test/mri/openssl/test_ssl.rb
Expand Up @@ -1064,7 +1064,9 @@ def test_alpn_protocol_selection_cancel
end
end

if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10001000
if OpenSSL::OPENSSL_VERSION_NUMBER > 0x10001000 &&
OpenSSL::SSL::SSLContext.method_defined?(:npn_select_cb)
# NPN may be disabled by OpenSSL configure option

def test_npn_protocol_selection_ary
advertised = ["http/1.1", "spdy/2"]
Expand Down
21 changes: 21 additions & 0 deletions test/mri/ostruct/test_ostruct.rb
Expand Up @@ -23,6 +23,10 @@ def test_respond_to_with_lazy_getter
assert_respond_to(o, :a=)
end

def test_respond_to_allocated
assert_not_respond_to(OpenStruct.allocate, :a)
end

def test_equality
o1 = OpenStruct.new
o2 = OpenStruct.new
Expand Down Expand Up @@ -160,4 +164,21 @@ def test_method_missing
e = assert_raise(ArgumentError) { os.send :foo=, true, true }
assert_match(/#{__callee__}/, e.backtrace[0])
end

def test_accessor_defines_method
os = OpenStruct.new(foo: 42)
assert os.respond_to? :foo
assert_equal([], os.singleton_methods)
assert_equal(42, os.foo)
assert_equal([:foo, :foo=], os.singleton_methods)
end

def test_does_not_redefine
os = OpenStruct.new(foo: 42)
def os.foo
43
end
os.foo = 44
assert_equal(43, os.foo)
end
end
2 changes: 1 addition & 1 deletion test/mri/psych/test_emitter.rb
Expand Up @@ -94,7 +94,7 @@ def test_start_sequence_arg_error

def test_resizing_tags
@emitter.start_stream Psych::Nodes::Stream::UTF8

tags = []
version = [1,1]
obj = Object.new
Expand Down
6 changes: 6 additions & 0 deletions test/mri/resolv/test_dns.rb
Expand Up @@ -199,6 +199,12 @@ def test_ipv6_name
assert_equal(expected, labels)
end

def test_ipv6_create
ref = '[Bug #11910] [ruby-core:72559]'
assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1')
assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1')
end

def test_too_big_label_address
n = 2000
m = Resolv::DNS::Message::MessageEncoder.new {|msg|
Expand Down
2 changes: 1 addition & 1 deletion test/mri/rexml/test_core.rb
Expand Up @@ -619,7 +619,7 @@ def test_stream
File.open(fixture_path("documentation.xml")) do |f|
Document.parse_stream( f, c )
end
assert(c.ts, "Stream parsing apparantly didn't parse the whole file")
assert(c.ts, "Stream parsing apparently didn't parse the whole file")
assert(c.te, "Stream parsing dropped end tag for documentation")

Document.parse_stream("<a.b> <c/> </a.b>", c)
Expand Down

0 comments on commit 8aa6f68

Please sign in to comment.