From 749b1a8ad8a05c3e38022aa6ffb6db820e7d3e96 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 2 Aug 2023 18:53:47 +0200 Subject: [PATCH 1/3] Update to ruby/spec@9e278f5 --- spec/ruby/command_line/dash_upper_u_spec.rb | 7 + .../core/basicobject/instance_eval_spec.rb | 7 + spec/ruby/core/binding/eval_spec.rb | 16 ++- .../converter/primitive_convert_spec.rb | 4 + spec/ruby/core/exception/case_compare_spec.rb | 2 - spec/ruby/core/false/singleton_method_spec.rb | 15 ++ spec/ruby/core/kernel/eval_spec.rb | 53 +++++-- spec/ruby/core/module/const_get_spec.rb | 2 +- spec/ruby/core/module/define_method_spec.rb | 11 ++ spec/ruby/core/module/module_function_spec.rb | 136 +++++++++++++++--- spec/ruby/core/module/name_spec.rb | 49 ------- .../core/module/set_temporary_name_spec.rb | 68 +++++++++ spec/ruby/core/module/shared/class_eval.rb | 6 + spec/ruby/core/nil/singleton_method_spec.rb | 15 ++ spec/ruby/core/process/warmup_spec.rb | 11 ++ .../core/refinement/refined_class_spec.rb | 2 +- spec/ruby/core/sizedqueue/append_spec.rb | 7 + spec/ruby/core/sizedqueue/enq_spec.rb | 7 + spec/ruby/core/sizedqueue/push_spec.rb | 7 + spec/ruby/core/string/encode_spec.rb | 4 + spec/ruby/core/string/index_spec.rb | 18 +++ spec/ruby/core/string/rindex_spec.rb | 9 +- spec/ruby/core/string/tr_s_spec.rb | 9 ++ spec/ruby/core/string/tr_spec.rb | 9 ++ spec/ruby/core/string/upto_spec.rb | 6 + spec/ruby/core/tracepoint/path_spec.rb | 31 ++-- spec/ruby/core/true/singleton_method_spec.rb | 15 ++ spec/ruby/language/alias_spec.rb | 18 +++ spec/ruby/language/defined_spec.rb | 2 +- spec/ruby/language/file_spec.rb | 12 +- spec/ruby/language/return_spec.rb | 15 ++ spec/ruby/language/super_spec.rb | 19 +++ spec/ruby/language/undef_spec.rb | 9 +- .../ruby/library/bigdecimal/remainder_spec.rb | 2 +- spec/ruby/library/bigdecimal/round_spec.rb | 4 +- spec/ruby/library/bigdecimal/to_s_spec.rb | 31 ++-- .../library/date/deconstruct_keys_spec.rb | 2 +- spec/ruby/library/date/strftime_spec.rb | 4 +- .../library/datetime/deconstruct_keys_spec.rb | 2 +- spec/ruby/library/datetime/strftime_spec.rb | 4 +- spec/ruby/library/datetime/to_time_spec.rb | 3 +- spec/ruby/library/erb/new_spec.rb | 2 +- spec/ruby/library/ipaddr/new_spec.rb | 10 +- spec/ruby/library/logger/device/close_spec.rb | 15 +- spec/ruby/library/logger/device/write_spec.rb | 15 +- spec/ruby/library/matrix/unitary_spec.rb | 6 +- .../library/openssl/config/freeze_spec.rb | 22 --- spec/ruby/library/stringio/initialize_spec.rb | 13 +- spec/ruby/library/stringio/shared/each.rb | 4 +- spec/ruby/library/time/to_datetime_spec.rb | 3 +- spec/ruby/library/uri/generic/host_spec.rb | 2 +- spec/ruby/library/uri/generic/to_s_spec.rb | 2 +- spec/ruby/optional/capi/exception_spec.rb | 34 +++++ spec/ruby/optional/capi/ext/class_spec.c | 8 +- spec/ruby/optional/capi/ext/debug_spec.c | 2 +- spec/ruby/optional/capi/ext/encoding_spec.c | 8 +- spec/ruby/optional/capi/ext/exception_spec.c | 19 ++- spec/ruby/optional/capi/ext/gc_spec.c | 2 +- spec/ruby/optional/capi/ext/hash_spec.c | 9 ++ spec/ruby/optional/capi/ext/integer_spec.c | 5 +- spec/ruby/optional/capi/ext/io_spec.c | 8 +- spec/ruby/optional/capi/ext/kernel_spec.c | 8 +- spec/ruby/optional/capi/ext/object_spec.c | 36 ++--- spec/ruby/optional/capi/ext/range_spec.c | 2 +- spec/ruby/optional/capi/ext/string_spec.c | 17 ++- spec/ruby/optional/capi/ext/struct_spec.c | 13 +- spec/ruby/optional/capi/ext/tracepoint_spec.c | 2 +- spec/ruby/optional/capi/hash_spec.rb | 16 +++ spec/ruby/shared/sizedqueue/enque.rb | 24 +++- 69 files changed, 706 insertions(+), 254 deletions(-) create mode 100644 spec/ruby/core/false/singleton_method_spec.rb create mode 100644 spec/ruby/core/module/set_temporary_name_spec.rb create mode 100644 spec/ruby/core/nil/singleton_method_spec.rb create mode 100644 spec/ruby/core/process/warmup_spec.rb create mode 100644 spec/ruby/core/true/singleton_method_spec.rb delete mode 100644 spec/ruby/library/openssl/config/freeze_spec.rb diff --git a/spec/ruby/command_line/dash_upper_u_spec.rb b/spec/ruby/command_line/dash_upper_u_spec.rb index d62718b0957..15854e7b736 100644 --- a/spec/ruby/command_line/dash_upper_u_spec.rb +++ b/spec/ruby/command_line/dash_upper_u_spec.rb @@ -6,6 +6,13 @@ options: '-U').should == 'UTF-8' end + it "sets Encoding.default_internal to UTF-8 when RUBYOPT is empty or only spaces" do + ruby_exe('p Encoding.default_internal', + options: '-U', env: { 'RUBYOPT' => '' }).should == "#\n" + ruby_exe('p Encoding.default_internal', + options: '-U', env: { 'RUBYOPT' => ' ' }).should == "#\n" + end + it "does nothing different if specified multiple times" do ruby_exe('print Encoding.default_internal.name', options: '-U -U').should == 'UTF-8' diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb index 699c965171f..1f3a43f341b 100644 --- a/spec/ruby/core/basicobject/instance_eval_spec.rb +++ b/spec/ruby/core/basicobject/instance_eval_spec.rb @@ -84,6 +84,13 @@ def foo end + ruby_version_is "3.3" do + it "uses the caller location as default location" do + f = Object.new + f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] + end + end + it "has access to receiver's instance variables" do BasicObjectSpecs::IVars.new.instance_eval { @secret }.should == 99 BasicObjectSpecs::IVars.new.instance_eval("@secret").should == 99 diff --git a/spec/ruby/core/binding/eval_spec.rb b/spec/ruby/core/binding/eval_spec.rb index 1b3b670b5ec..bb2036f7391 100644 --- a/spec/ruby/core/binding/eval_spec.rb +++ b/spec/ruby/core/binding/eval_spec.rb @@ -60,10 +60,12 @@ bind.eval("#foo\n__LINE__", "(test)", 88).should == 89 end - it "uses (eval) as __FILE__ if single argument given" do - obj = BindingSpecs::Demo.new(1) - bind = obj.get_binding - bind.eval("__FILE__").should == '(eval)' + ruby_version_is ""..."3.3" do + it "uses (eval) as __FILE__ if single argument given" do + obj = BindingSpecs::Demo.new(1) + bind = obj.get_binding + bind.eval("__FILE__").should == '(eval)' + end end it "uses 1 as __LINE__" do @@ -104,4 +106,10 @@ bind.eval("'bar'.foo").should == "foo" end + + ruby_version_is "3.3" do + it "uses the caller location as default filename" do + binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] + end + end end diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb index 802d8e7cb1d..ab34ebf33fe 100644 --- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb +++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb @@ -14,6 +14,10 @@ -> { @ec.primitive_convert("","") }.should_not raise_error end + it "raises FrozenError when the destination buffer is a frozen String" do + -> { @ec.primitive_convert("", "".freeze) }.should raise_error(FrozenError) + end + it "accepts nil for the destination byte offset" do -> { @ec.primitive_convert("","", nil) }.should_not raise_error end diff --git a/spec/ruby/core/exception/case_compare_spec.rb b/spec/ruby/core/exception/case_compare_spec.rb index 87b9dee3caf..5fd11ae741c 100644 --- a/spec/ruby/core/exception/case_compare_spec.rb +++ b/spec/ruby/core/exception/case_compare_spec.rb @@ -26,13 +26,11 @@ end it "returns true if receiver is generic and arg is kind of SystemCallError" do - unknown_error_number = Errno.constants.size e = SystemCallError.new('foo', @example_errno) SystemCallError.===(e).should == true end it "returns false if receiver is generic and arg is not kind of SystemCallError" do - unknown_error_number = Errno.constants.size e = Object.new SystemCallError.===(e).should == false end diff --git a/spec/ruby/core/false/singleton_method_spec.rb b/spec/ruby/core/false/singleton_method_spec.rb new file mode 100644 index 00000000000..6cf29af411b --- /dev/null +++ b/spec/ruby/core/false/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "FalseClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether FalseClass defines the method" do + proc{false.singleton_method(:foo)}.should raise_error(NameError) + begin + def false.foo; end + proc{false.singleton_method(:foo)}.should raise_error(NameError) + ensure + FalseClass.send(:remove_method, :foo) + end + end + end +end diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb index e6761ab789d..3dfc8633688 100644 --- a/spec/ruby/core/kernel/eval_spec.rb +++ b/spec/ruby/core/kernel/eval_spec.rb @@ -159,20 +159,37 @@ class Object end end - it "uses (eval) filename if none is provided" do - eval("__FILE__").should == "(eval)" - eval("__FILE__", binding).should == "(eval)" - eval("__FILE__", binding, "success").should == "success" - eval("eval '__FILE__', binding").should == "(eval)" - eval("eval '__FILE__', binding", binding).should == "(eval)" - eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' - eval("eval '__FILE__', binding, 'success'", binding).should == 'success' - end + ruby_version_is ""..."3.3" do + it "uses (eval) filename if none is provided" do + eval("__FILE__").should == "(eval)" + eval("__FILE__", binding).should == "(eval)" + eval("__FILE__", binding, "success").should == "success" + eval("eval '__FILE__', binding").should == "(eval)" + eval("eval '__FILE__', binding", binding).should == "(eval)" + eval("eval '__FILE__', binding", binding, 'success').should == '(eval)' + eval("eval '__FILE__', binding, 'success'", binding).should == 'success' + end - it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do - eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] + it 'uses (eval) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval)", 1] + end end + ruby_version_is "3.3" do + it "uses (eval at __FILE__:__LINE__) if none is provided" do + eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" + eval("__FILE__", binding).should == "(eval at #{__FILE__}:#{__LINE__})" + eval("__FILE__", binding, "success").should == "success" + eval("eval '__FILE__', binding").should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" + eval("eval '__FILE__', binding", binding).should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)" + eval("eval '__FILE__', binding", binding, 'success').should == "(eval at success:1)" + eval("eval '__FILE__', binding, 'success'", binding).should == 'success' + end + + it 'uses (eval at __FILE__:__LINE__) for __FILE__ and 1 for __LINE__ with a binding argument' do + eval("[__FILE__, __LINE__]", binding).should == ["(eval at #{__FILE__}:#{__LINE__})", 1] + end + end # Found via Rubinius bug github:#149 it "does not alter the value of __FILE__ in the binding" do first_time = EvalSpecs.call_eval @@ -209,6 +226,20 @@ class Object -> { eval("return :eval") }.call.should == :eval end + it "returns from the method calling #eval when evaluating 'return'" do + def eval_return(n) + eval("return n*2") + end + -> { eval_return(3) }.call.should == 6 + end + + it "returns from the method calling #eval when evaluating 'return' in BEGIN" do + def eval_return(n) + eval("BEGIN {return n*3}") + end + -> { eval_return(4) }.call.should == 12 + end + it "unwinds through a Proc-style closure and returns from a lambda-style closure in the closure chain" do code = fixture __FILE__, "eval_return_with_lambda.rb" ruby_exe(code).chomp.should == "a,b,c,eval,f" diff --git a/spec/ruby/core/module/const_get_spec.rb b/spec/ruby/core/module/const_get_spec.rb index 69f181cf51e..0233118f4b4 100644 --- a/spec/ruby/core/module/const_get_spec.rb +++ b/spec/ruby/core/module/const_get_spec.rb @@ -105,7 +105,7 @@ -> { ConstantSpecs.const_get("CS_CONST1", false) }.should raise_error(NameError) end - it "returns a constant whose module is defined the the toplevel" do + it "returns a constant whose module is defined the toplevel" do ConstantSpecs.const_get("ConstantSpecsTwo::Foo").should == :cs_two_foo ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index ce94436bfd6..381aacadb7f 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -133,6 +133,17 @@ class << klass klass.should have_public_instance_method(:baz) end end + + it "sets the method owner for a dynamically added method with a different original owner" do + mixin_module = Module.new do + def bar; end + end + + foo = Object.new + foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar)) + + foo.method(:bar).owner.should == foo.singleton_class + end end describe "passed a block" do diff --git a/spec/ruby/core/module/module_function_spec.rb b/spec/ruby/core/module/module_function_spec.rb index 0602e95ca9c..1c3ec5471b1 100644 --- a/spec/ruby/core/module/module_function_spec.rb +++ b/spec/ruby/core/module/module_function_spec.rb @@ -155,15 +155,62 @@ def foo m.foo.should == ["m", "super_m"] end + + context "methods created with define_method" do + context "passed a block" do + it "creates duplicates of the given instance methods" do + m = Module.new do + define_method :test1 do; end + module_function :test1 + end + + m.respond_to?(:test1).should == true + end + end + + context "passed a method" do + it "creates duplicates of the given instance methods" do + module_with_method = Module.new do + def test1; end + end + + c = Class.new do + extend module_with_method + end + + m = Module.new do + define_method :test2, c.method(:test1) + module_function :test2 + end + + m.respond_to?(:test2).should == true + end + end + + context "passed an unbound method" do + it "creates duplicates of the given instance methods" do + module_with_method = Module.new do + def test1; end + end + + m = Module.new do + define_method :test2, module_with_method.instance_method(:test1) + module_function :test2 + end + + m.respond_to?(:test2).should == true + end + end + end end describe "Module#module_function as a toggle (no arguments) in a Module body" do it "makes any subsequently defined methods module functions with the normal semantics" do - m = Module.new { + m = Module.new do module_function def test1() end def test2() end - } + end m.respond_to?(:test1).should == true m.respond_to?(:test2).should == true @@ -187,13 +234,13 @@ def test2() end it "stops creating module functions if the body encounters another toggle " \ "like public/protected/private without arguments" do - m = Module.new { + m = Module.new do module_function def test1() end def test2() end public def test3() end - } + end m.respond_to?(:test1).should == true m.respond_to?(:test2).should == true @@ -202,14 +249,14 @@ def test3() end it "does not stop creating module functions if the body encounters " \ "public/protected/private WITH arguments" do - m = Module.new { + m = Module.new do def foo() end module_function def test1() end def test2() end public :foo def test3() end - } + end m.respond_to?(:test1).should == true m.respond_to?(:test2).should == true @@ -217,69 +264,116 @@ def test3() end end it "does not affect module_evaled method definitions also if outside the eval itself" do - m = Module.new { + m = Module.new do module_function module_eval { def test1() end } module_eval " def test2() end " - } + end m.respond_to?(:test1).should == false m.respond_to?(:test2).should == false end it "has no effect if inside a module_eval if the definitions are outside of it" do - m = Module.new { + m = Module.new do module_eval { module_function } def test1() end def test2() end - } + end m.respond_to?(:test1).should == false m.respond_to?(:test2).should == false end it "functions normally if both toggle and definitions inside a module_eval" do - m = Module.new { - module_eval { + m = Module.new do + module_eval do module_function def test1() end def test2() end - } - } + end + end m.respond_to?(:test1).should == true m.respond_to?(:test2).should == true end - it "affects evaled method definitions also even when outside the eval itself" do - m = Module.new { + it "affects eval'ed method definitions also even when outside the eval itself" do + m = Module.new do module_function eval "def test1() end" - } + end m.respond_to?(:test1).should == true end it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do - m = Module.new { + m = Module.new do eval "module_function" def test1() end - } + end m.respond_to?(:test1).should == false end it "functions normally if both toggle and definitions inside a eval" do - m = Module.new { + m = Module.new do eval <<-CODE module_function def test1() end def test2() end CODE - } + end m.respond_to?(:test1).should == true m.respond_to?(:test2).should == true end + + context "methods are defined with define_method" do + context "passed a block" do + it "makes any subsequently defined methods module functions with the normal semantics" do + m = Module.new do + module_function + define_method :test1 do; end + end + + m.respond_to?(:test1).should == true + end + end + + context "passed a method" do + it "makes any subsequently defined methods module functions with the normal semantics" do + module_with_method = Module.new do + def test1; end + end + + c = Class.new do + extend module_with_method + end + + m = Module.new do + module_function + define_method :test2, c.method(:test1) + end + + m.respond_to?(:test2).should == true + end + end + + context "passed an unbound method" do + it "makes any subsequently defined methods module functions with the normal semantics" do + module_with_method = Module.new do + def test1; end + end + + m = Module.new do + module_function + define_method :test2, module_with_method.instance_method(:test1) + end + + m.respond_to?(:test2).should == true + end + end + end end diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index bb7fa1761c2..0d1f4e24d58 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -6,55 +6,6 @@ Module.new.name.should be_nil end - ruby_version_is "3.3" do - it "can assign a temporary name" do - m = Module.new - m.name.should be_nil - - m.set_temporary_name("fake_name") - m.name.should == "fake_name" - - m.set_temporary_name(nil) - m.name.should be_nil - end - - it "can't assign empty string as name" do - m = Module.new - -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") - end - - it "can't assign a constant name as a temporary name" do - m = Module.new - -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "name must not be valid constant name") - end - - it "can't assign name to permanent module" do - -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") - end - - it "can assign a temporary name to a nested module" do - m = Module.new - module m::N; end - m::N.name.should =~ /\A#::N\z/ - - m::N.set_temporary_name("fake_name") - m::N.name.should == "fake_name" - - m::N.set_temporary_name(nil) - m::N.name.should be_nil - end - - it "can update the name when assigned to a constant" do - m = Module.new - m::N = Module.new - m::N.name.should =~ /\A#::N\z/ - m::N.set_temporary_name(nil) - - m::M = m::N - m::M.name.should =~ /\A#::M\z/m - end - end - it "is not nil when assigned to a constant in an anonymous module" do m = Module.new m::N = Module.new diff --git a/spec/ruby/core/module/set_temporary_name_spec.rb b/spec/ruby/core/module/set_temporary_name_spec.rb new file mode 100644 index 00000000000..f5886a33988 --- /dev/null +++ b/spec/ruby/core/module/set_temporary_name_spec.rb @@ -0,0 +1,68 @@ +require_relative '../../spec_helper' + +ruby_version_is "3.3" do + describe "Module#set_temporary_name" do + it "can assign a temporary name" do + m = Module.new + m.name.should be_nil + + m.set_temporary_name("fake_name") + m.name.should == "fake_name" + + m.set_temporary_name(nil) + m.name.should be_nil + end + + it "can assign a temporary name which is not a valid constant path" do + m = Module.new + m.set_temporary_name("a::B") + m.name.should == "a::B" + + m.set_temporary_name("Template['foo.rb']") + m.name.should == "Template['foo.rb']" + end + + it "can't assign empty string as name" do + m = Module.new + -> { m.set_temporary_name("") }.should raise_error(ArgumentError, "empty class/module name") + end + + it "can't assign a constant name as a temporary name" do + m = Module.new + -> { m.set_temporary_name("Object") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + end + + it "can't assign a constant path as a temporary name" do + m = Module.new + -> { m.set_temporary_name("A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + -> { m.set_temporary_name("::A") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + -> { m.set_temporary_name("::A::B") }.should raise_error(ArgumentError, "the temporary name must not be a constant path to avoid confusion") + end + + it "can't assign name to permanent module" do + -> { Object.set_temporary_name("fake_name") }.should raise_error(RuntimeError, "can't change permanent name") + end + + it "can assign a temporary name to a nested module" do + m = Module.new + module m::N; end + m::N.name.should =~ /\A#::N\z/ + + m::N.set_temporary_name("fake_name") + m::N.name.should == "fake_name" + + m::N.set_temporary_name(nil) + m::N.name.should be_nil + end + + it "can update the name when assigned to a constant" do + m = Module.new + m::N = Module.new + m::N.name.should =~ /\A#::N\z/ + m::N.set_temporary_name(nil) + + m::M = m::N + m::M.name.should =~ /\A#::M\z/m + end + end +end diff --git a/spec/ruby/core/module/shared/class_eval.rb b/spec/ruby/core/module/shared/class_eval.rb index 9ef7b5be44c..b1d5cb3814e 100644 --- a/spec/ruby/core/module/shared/class_eval.rb +++ b/spec/ruby/core/module/shared/class_eval.rb @@ -52,6 +52,12 @@ def foo ModuleSpecs.send(@method, "[__FILE__, __LINE__]", "test", 102).should == ["test", 102] end + ruby_version_is "3.3" do + it "uses the caller location as default filename" do + ModuleSpecs.send(@method, "[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1] + end + end + it "converts a non-string filename to a string using to_str" do (file = mock(__FILE__)).should_receive(:to_str).and_return(__FILE__) ModuleSpecs.send(@method, "1+1", file) diff --git a/spec/ruby/core/nil/singleton_method_spec.rb b/spec/ruby/core/nil/singleton_method_spec.rb new file mode 100644 index 00000000000..f9163da3f15 --- /dev/null +++ b/spec/ruby/core/nil/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "NilClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether NilClass defines the method" do + proc{nil.singleton_method(:foo)}.should raise_error(NameError) + begin + def nil.foo; end + proc{nil.singleton_method(:foo)}.should raise_error(NameError) + ensure + NilClass.send(:remove_method, :foo) + end + end + end +end diff --git a/spec/ruby/core/process/warmup_spec.rb b/spec/ruby/core/process/warmup_spec.rb new file mode 100644 index 00000000000..b562d52d226 --- /dev/null +++ b/spec/ruby/core/process/warmup_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' + +describe "Process.warmup" do + ruby_version_is "3.3" do + # The behavior is entirely implementation specific. + # Other implementations are free to just make it a noop + it "is implemented" do + Process.warmup.should == true + end + end +end diff --git a/spec/ruby/core/refinement/refined_class_spec.rb b/spec/ruby/core/refinement/refined_class_spec.rb index bcf48c4e258..00b65d08955 100644 --- a/spec/ruby/core/refinement/refined_class_spec.rb +++ b/spec/ruby/core/refinement/refined_class_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' describe "Refinement#refined_class" do - ruby_version_is "3.2" do + ruby_version_is "3.2"..."3.3" do it "returns the class refined by the receiver" do refinement_int = nil diff --git a/spec/ruby/core/sizedqueue/append_spec.rb b/spec/ruby/core/sizedqueue/append_spec.rb index ca790689303..6fffe2f2726 100644 --- a/spec/ruby/core/sizedqueue/append_spec.rb +++ b/spec/ruby/core/sizedqueue/append_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' require_relative '../../shared/queue/enque' require_relative '../../shared/sizedqueue/enque' +require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#<<" do it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) } @@ -9,3 +10,9 @@ describe "SizedQueue#<<" do it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) } end + +describe "SizedQueue operations with timeout" do + ruby_version_is "3.2" do + it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.send(:<<, 1, timeout: v) } + end +end diff --git a/spec/ruby/core/sizedqueue/enq_spec.rb b/spec/ruby/core/sizedqueue/enq_spec.rb index 3821afac956..619373e46be 100644 --- a/spec/ruby/core/sizedqueue/enq_spec.rb +++ b/spec/ruby/core/sizedqueue/enq_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' require_relative '../../shared/queue/enque' require_relative '../../shared/sizedqueue/enque' +require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#enq" do it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) } @@ -9,3 +10,9 @@ describe "SizedQueue#enq" do it_behaves_like :sizedqueue_enq, :enq, -> n { SizedQueue.new(n) } end + +describe "SizedQueue operations with timeout" do + ruby_version_is "3.2" do + it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.enq(1, timeout: v) } + end +end diff --git a/spec/ruby/core/sizedqueue/push_spec.rb b/spec/ruby/core/sizedqueue/push_spec.rb index bba9be9e3fb..ce61e89b53f 100644 --- a/spec/ruby/core/sizedqueue/push_spec.rb +++ b/spec/ruby/core/sizedqueue/push_spec.rb @@ -1,6 +1,7 @@ require_relative '../../spec_helper' require_relative '../../shared/queue/enque' require_relative '../../shared/sizedqueue/enque' +require_relative '../../shared/types/rb_num2dbl_fails' describe "SizedQueue#push" do it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) } @@ -9,3 +10,9 @@ describe "SizedQueue#push" do it_behaves_like :sizedqueue_enq, :push, -> n { SizedQueue.new(n) } end + +describe "SizedQueue operations with timeout" do + ruby_version_is "3.2" do + it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.push(1, timeout: v) } + end +end diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb index 5604ab7210a..35ed27bb40d 100644 --- a/spec/ruby/core/string/encode_spec.rb +++ b/spec/ruby/core/string/encode_spec.rb @@ -79,6 +79,10 @@ encoded.encode("UTF-8").should == "ちfoofoo" end + it "replace multiple invalid bytes at the end with a single replacement character" do + "\xE3\x81\x93\xE3\x81".encode("UTF-8", invalid: :replace).should == "\u3053\ufffd" + end + it "replaces invalid encoding in source using a specified replacement even when a fallback is given" do encoded = "ち\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo", fallback: -> c { "bar" }) encoded.should == "\u3061foofoo".encode("UTF-16LE") diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb index 2eeee9be874..b500cf6ca77 100644 --- a/spec/ruby/core/string/index_spec.rb +++ b/spec/ruby/core/string/index_spec.rb @@ -167,6 +167,13 @@ it "handles a substring in a subset encoding" do 'été'.index('t'.force_encoding(Encoding::US_ASCII)).should == 1 end + + it "raises an Encoding::CompatibilityError if the encodings are incompatible" do + str = 'abc'.force_encoding("ISO-2022-JP") + pattern = 'b'.force_encoding("EUC-JP") + + -> { str.index(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP") + end end describe "String#index with Regexp" do @@ -312,6 +319,17 @@ "われわわれ".index(/わ/, 3).should == 3 end + ruby_bug "#19763", ""..."3.3.0" do + it "raises an Encoding::CompatibilityError if the encodings are incompatible" do + re = Regexp.new "れ".encode(Encoding::EUC_JP) + -> do + "あれ".index re + end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") + end + end + + # The exception message was incorrectly "incompatible character encodings: UTF-8 and EUC-JP" before 3.3.0 + # Still test that the right exception class is used before that. it "raises an Encoding::CompatibilityError if the encodings are incompatible" do re = Regexp.new "れ".encode(Encoding::EUC_JP) -> do diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb index e795105e1da..45ff13a0060 100644 --- a/spec/ruby/core/string/rindex_spec.rb +++ b/spec/ruby/core/string/rindex_spec.rb @@ -204,6 +204,13 @@ def obj.method_missing(*args) 5 end it "handles a substring in a subset encoding" do 'été'.rindex('t'.force_encoding(Encoding::US_ASCII)).should == 1 end + + it "raises an Encoding::CompatibilityError if the encodings are incompatible" do + str = 'abc'.force_encoding("ISO-2022-JP") + pattern = 'b'.force_encoding("EUC-JP") + + -> { str.rindex(pattern) }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP") + end end describe "String#rindex with Regexp" do @@ -373,6 +380,6 @@ def obj.method_missing(*args); 5; end re = Regexp.new "れ".encode(Encoding::EUC_JP) -> do "あれ".rindex re - end.should raise_error(Encoding::CompatibilityError) + end.should raise_error(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)") end end diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb index b5c87d4e4e6..3c314730447 100644 --- a/spec/ruby/core/string/tr_s_spec.rb +++ b/spec/ruby/core/string/tr_s_spec.rb @@ -17,6 +17,15 @@ "hello ^--^".tr_s("---", "_").should == "hello ^_^" end + ruby_bug "#19769", ""..."3.3" do + it "accepts c1-c1 notation to denote range of one character" do + "hello".tr_s('e-e', 'x').should == "hxllo" + "123456789".tr_s("2-23","xy").should == "1xy456789" + "hello ^-^".tr_s("e-", "a-a_").should == "hallo ^_^" + "hello ^-^".tr_s("---o", "_a").should == "hella ^_^" + end + end + it "pads to_str with its last char if it is shorter than from_string" do "this".tr_s("this", "x").should == "x" end diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb index cf485d32a3f..d60480dc7e4 100644 --- a/spec/ruby/core/string/tr_spec.rb +++ b/spec/ruby/core/string/tr_spec.rb @@ -16,6 +16,15 @@ "hello ^-^".tr("---", "_").should == "hello ^_^" end + ruby_bug "#19769", ""..."3.3" do + it "accepts c1-c1 notation to denote range of one character" do + "hello".tr('e-e', 'x').should == "hxllo" + "123456789".tr("2-23","xy").should == "1xy456789" + "hello ^-^".tr("e-", "a-a_").should == "hallo ^_^" + "hello ^-^".tr("---o", "_a").should == "hella ^_^" + end + end + it "pads to_str with its last char if it is shorter than from_string" do "this".tr("this", "x").should == "xxxx" "hello".tr("a-z", "A-H.").should == "HE..." diff --git a/spec/ruby/core/string/upto_spec.rb b/spec/ruby/core/string/upto_spec.rb index f8529b1d2b4..3799e338e08 100644 --- a/spec/ruby/core/string/upto_spec.rb +++ b/spec/ruby/core/string/upto_spec.rb @@ -80,6 +80,12 @@ def other.to_str() "abd" end a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"] end + it "raises Encoding::CompatibilityError when incompatible characters are given" do + char1 = 'a'.force_encoding("EUC-JP") + char2 = 'b'.force_encoding("ISO-2022-JP") + -> { char1.upto(char2) {} }.should raise_error(Encoding::CompatibilityError, "incompatible character encodings: EUC-JP and ISO-2022-JP") + end + describe "on sequence of numbers" do it "calls the block as Integer#upto" do "8".upto("11").to_a.should == 8.upto(11).map(&:to_s) diff --git a/spec/ruby/core/tracepoint/path_spec.rb b/spec/ruby/core/tracepoint/path_spec.rb index 5b6c6d4cfce..dc2ca840b80 100644 --- a/spec/ruby/core/tracepoint/path_spec.rb +++ b/spec/ruby/core/tracepoint/path_spec.rb @@ -13,14 +13,29 @@ path.should == "#{__FILE__}" end - it 'equals (eval) inside an eval for :end event' do - path = nil - TracePoint.new(:end) { |tp| - next unless TracePointSpec.target_thread? - path = tp.path - }.enable do - eval("module TracePointSpec; end") + ruby_version_is ""..."3.3" do + it 'equals (eval) inside an eval for :end event' do + path = nil + TracePoint.new(:end) { |tp| + next unless TracePointSpec.target_thread? + path = tp.path + }.enable do + eval("module TracePointSpec; end") + end + path.should == '(eval)' + end + end + + ruby_version_is "3.3" do + it 'equals "(eval at __FILE__:__LINE__)" inside an eval for :end event' do + path = nil + TracePoint.new(:end) { |tp| + next unless TracePointSpec.target_thread? + path = tp.path + }.enable do + eval("module TracePointSpec; end") + end + path.should == "(eval at #{__FILE__}:#{__LINE__ - 2})" end - path.should == '(eval)' end end diff --git a/spec/ruby/core/true/singleton_method_spec.rb b/spec/ruby/core/true/singleton_method_spec.rb new file mode 100644 index 00000000000..f765054c5f3 --- /dev/null +++ b/spec/ruby/core/true/singleton_method_spec.rb @@ -0,0 +1,15 @@ +require_relative '../../spec_helper' + +describe "TrueClass#singleton_method" do + ruby_version_is '3.3' do + it "raises regardless of whether TrueClass defines the method" do + proc{true.singleton_method(:foo)}.should raise_error(NameError) + begin + def true.foo; end + proc{true.singleton_method(:foo)}.should raise_error(NameError) + ensure + TrueClass.send(:remove_method, :foo) + end + end + end +end diff --git a/spec/ruby/language/alias_spec.rb b/spec/ruby/language/alias_spec.rb index c353390679e..ee928cbfaae 100644 --- a/spec/ruby/language/alias_spec.rb +++ b/spec/ruby/language/alias_spec.rb @@ -52,6 +52,15 @@ def self.klass_method; 7; end @obj.a.should == 5 end + it "works with an interpolated symbol with non-literal embedded expression on the left-hand side" do + @meta.class_eval do + eval %Q{ + alias :"#{'a' + ''.to_s}" value + } + end + @obj.a.should == 5 + end + it "works with a simple symbol on the right-hand side" do @meta.class_eval do alias a :value @@ -80,6 +89,15 @@ def self.klass_method; 7; end @obj.a.should == 5 end + it "works with an interpolated symbol with non-literal embedded expression on the right-hand side" do + @meta.class_eval do + eval %Q{ + alias a :"#{'value' + ''.to_s}" + } + end + @obj.a.should == 5 + end + it "adds the new method to the list of methods" do original_methods = @obj.methods @meta.class_eval do diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb index 104434adfe8..b84fe9394ad 100644 --- a/spec/ruby/language/defined_spec.rb +++ b/spec/ruby/language/defined_spec.rb @@ -203,7 +203,7 @@ it "warns about the void context when parsing it" do -> { eval "defined?(DefinedSpecs.side_effects / 2); 42" - }.should complain("(eval):1: warning: possibly useless use of defined? in void context\n", verbose: true) + }.should complain(/warning: possibly useless use of defined\? in void context/, verbose: true) end end end diff --git a/spec/ruby/language/file_spec.rb b/spec/ruby/language/file_spec.rb index 136b262d07d..59563d9642e 100644 --- a/spec/ruby/language/file_spec.rb +++ b/spec/ruby/language/file_spec.rb @@ -7,8 +7,16 @@ -> { eval("__FILE__ = 1") }.should raise_error(SyntaxError) end - it "equals (eval) inside an eval" do - eval("__FILE__").should == "(eval)" + ruby_version_is ""..."3.3" do + it "equals (eval) inside an eval" do + eval("__FILE__").should == "(eval)" + end + end + + ruby_version_is "3.3" do + it "equals (eval at __FILE__:__LINE__) inside an eval" do + eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})" + end end end diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb index 94c15b697e6..a62ed1242d7 100644 --- a/spec/ruby/language/return_spec.rb +++ b/spec/ruby/language/return_spec.rb @@ -435,6 +435,21 @@ class ReturnSpecs::A end end + describe "within BEGIN" do + it "is allowed" do + File.write(@filename, <<-END_OF_CODE) + BEGIN { + ScratchPad << "before call" + return + ScratchPad << "after call" + } + END_OF_CODE + + load @filename + ScratchPad.recorded.should == ["before call"] + end + end + describe "file loading" do it "stops file loading and execution" do File.write(@filename, <<-END_OF_CODE) diff --git a/spec/ruby/language/super_spec.rb b/spec/ruby/language/super_spec.rb index 1fd7acc7270..d22c6036056 100644 --- a/spec/ruby/language/super_spec.rb +++ b/spec/ruby/language/super_spec.rb @@ -203,6 +203,25 @@ def a(arg) -> { klass.new.a(:a_called) }.should raise_error(RuntimeError) end + it "is able to navigate to super, when a method is defined dynamically on the singleton class" do + foo_class = Class.new do + def bar + "bar" + end + end + + mixin_module = Module.new do + def bar + "super_" + super + end + end + + foo = foo_class.new + foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar)) + + foo.bar.should == "super_bar" + end + # Rubinius ticket github#157 it "calls method_missing when a superclass method is not found" do SuperSpecs::MM_B.new.is_a?(Hash).should == false diff --git a/spec/ruby/language/undef_spec.rb b/spec/ruby/language/undef_spec.rb index 4e473b803f2..29dba4afb4d 100644 --- a/spec/ruby/language/undef_spec.rb +++ b/spec/ruby/language/undef_spec.rb @@ -38,12 +38,19 @@ def meth(o); o; end -> { @obj.meth(5) }.should raise_error(NoMethodError) end - it "with a interpolated symbol" do + it "with an interpolated symbol" do @undef_class.class_eval do undef :"#{'meth'}" end -> { @obj.meth(5) }.should raise_error(NoMethodError) end + + it "with an interpolated symbol when interpolated expression is not a String literal" do + @undef_class.class_eval do + undef :"#{'meth'.to_sym}" + end + -> { @obj.meth(5) }.should raise_error(NoMethodError) + end end it "allows undefining multiple methods at a time" do diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb index 35e131a0dc0..bac5f37ba96 100644 --- a/spec/ruby/library/bigdecimal/remainder_spec.rb +++ b/spec/ruby/library/bigdecimal/remainder_spec.rb @@ -54,7 +54,7 @@ @nan.remainder(@infinity).should.nan? end - version_is BigDecimal::VERSION, ""..."3.1.4" do + version_is BigDecimal::VERSION, ""..."3.1.4" do #ruby_version_is ""..."3.3" do it "returns NaN if Infinity is involved" do @infinity.remainder(@infinity).should.nan? @infinity.remainder(@one).should.nan? diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb index bfc6dbc763b..fba52df65d3 100644 --- a/spec/ruby/library/bigdecimal/round_spec.rb +++ b/spec/ruby/library/bigdecimal/round_spec.rb @@ -228,13 +228,13 @@ -> { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError) end - ruby_version_is ''...'3.2' do + version_is BigDecimal::VERSION, ''...'3.1.3' do #ruby_version_is ''...'3.2' do it 'raise for a non-existent round mode' do -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode") end end - ruby_version_is '3.2' do + version_is BigDecimal::VERSION, '3.1.3' do #ruby_version_is '3.2' do it 'raise for a non-existent round mode' do -> { @p1_50.round(0, :nonsense) }.should raise_error(ArgumentError, "invalid rounding mode (nonsense)") end diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb index 042c7779f4a..63dfaf5e7c3 100644 --- a/spec/ruby/library/bigdecimal/to_s_spec.rb +++ b/spec/ruby/library/bigdecimal/to_s_spec.rb @@ -39,18 +39,25 @@ @bigneg.to_s("+").should_not =~ /^\+.*/ end - it "inserts a space every n chars, if integer n is supplied" do - re =\ - /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i - @bigdec.to_s(3).should =~ re - - str1 = '-123.45678 90123 45678 9' - BigDecimal("-123.45678901234567890").to_s('5F').should == str1 - BigDecimal('1000010').to_s('5F').should == "10000 10.0" - # trailing zeroes removed - BigDecimal("1.00000000000").to_s('1F').should == "1.0" - # 0 is treated as no spaces - BigDecimal("1.2345").to_s('0F').should == "1.2345" + ruby_version_is ""..."3.3" do + it "inserts a space every n chars to fraction part, if integer n is supplied" do + re =\ + /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i + @bigdec.to_s(3).should =~ re + + str1 = '-123.45678 90123 45678 9' + BigDecimal("-123.45678901234567890").to_s('5F').should == str1 + # trailing zeroes removed + BigDecimal("1.00000000000").to_s('1F').should == "1.0" + # 0 is treated as no spaces + BigDecimal("1.2345").to_s('0F').should == "1.2345" + end + end + + version_is BigDecimal::VERSION, "3.1.5" do #ruby_version_is '3.3' do + it "inserts a space every n chars to integer part, if integer n is supplied" do + BigDecimal('1000010').to_s('5F').should == "10 00010.0" + end end it "can return a leading space for values > 0" do diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb index fc9caaf3323..94b528099fd 100644 --- a/spec/ruby/library/date/deconstruct_keys_spec.rb +++ b/spec/ruby/library/date/deconstruct_keys_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require 'date' -ruby_version_is "3.2" do +version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do describe "Date#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = Date.new(2022, 10, 5) diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb index 33ecc4ce9d0..fc6c1dae8d6 100644 --- a/spec/ruby/library/date/strftime_spec.rb +++ b/spec/ruby/library/date/strftime_spec.rb @@ -23,14 +23,14 @@ end # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do + version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-Apr-2000" @date.strftime("%v").should == @date.strftime('%e-%b-%Y') end end - ruby_version_is "3.1" do + version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @date.strftime("%v").should == " 9-APR-2000" @date.strftime("%v").should != @date.strftime('%e-%b-%Y') diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb index c6c0f71f55b..95a391cdd8b 100644 --- a/spec/ruby/library/datetime/deconstruct_keys_spec.rb +++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb @@ -1,7 +1,7 @@ require_relative '../../spec_helper' require 'date' -ruby_version_is "3.2" do +version_is Date::VERSION, "3.3" do #ruby_version_is "3.2" do describe "DateTime#deconstruct_keys" do it "returns whole hash for nil as an argument" do d = DateTime.new(2022, 10, 5, 13, 30) diff --git a/spec/ruby/library/datetime/strftime_spec.rb b/spec/ruby/library/datetime/strftime_spec.rb index 725bcafb0d4..847098cb502 100644 --- a/spec/ruby/library/datetime/strftime_spec.rb +++ b/spec/ruby/library/datetime/strftime_spec.rb @@ -33,14 +33,14 @@ end # %v is %e-%b-%Y for Date/DateTime - ruby_version_is ""..."3.1" do + version_is Date::VERSION, ""..."3.2" do #ruby_version_is ""..."3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-Feb-2001" @time.strftime("%v").should == @time.strftime('%e-%b-%Y') end end - ruby_version_is "3.1" do + version_is Date::VERSION, "3.2" do #ruby_version_is "3.1" do it "should be able to show the commercial week" do @time.strftime("%v").should == " 3-FEB-2001" @time.strftime("%v").should != @time.strftime('%e-%b-%Y') diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb index 95eca864dad..84990d511c7 100644 --- a/spec/ruby/library/datetime/to_time_spec.rb +++ b/spec/ruby/library/datetime/to_time_spec.rb @@ -18,8 +18,7 @@ time.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do + version_is(Date::VERSION, '3.2.3') do #ruby_version_is "3.2" do it "returns a Time representing the same instant before Gregorian" do datetime = DateTime.civil(1582, 10, 4, 23, 58, 59) time = datetime.to_time.utc diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb index 4d7f7bf36a3..a5aeeaeed10 100644 --- a/spec/ruby/library/erb/new_spec.rb +++ b/spec/ruby/library/erb/new_spec.rb @@ -140,7 +140,7 @@ end describe "warning about arguments" do - ruby_version_is "3.1" do + version_is ERB.version, "2.2.1" do #ruby_version_is "3.1" do it "warns when passed safe_level and later arguments" do -> { ERB.new(@eruby_str, nil, '%') diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb index 053928c3cfd..714c1e2f1ad 100644 --- a/spec/ruby/library/ipaddr/new_spec.rb +++ b/spec/ruby/library/ipaddr/new_spec.rb @@ -77,7 +77,13 @@ a.family.should == Socket::AF_INET6 end - ruby_version_is ""..."3.1" do + ipaddr_version = if defined?(IPAddr::VERSION) #ruby_version_is ""..."3.1" do + IPAddr::VERSION + else + "1.2.2" + end + + version_is ipaddr_version, ""..."1.2.3" do #ruby_version_is ""..."3.1" do it "raises on incorrect IPAddr strings" do [ ["fe80::1%fxp0"], @@ -93,7 +99,7 @@ end end - ruby_version_is "3.1" do + version_is ipaddr_version, "1.2.3" do #ruby_version_is "3.1" do it "raises on incorrect IPAddr strings" do [ ["::1/255.255.255.0"], diff --git a/spec/ruby/library/logger/device/close_spec.rb b/spec/ruby/library/logger/device/close_spec.rb index 7c5e118d56a..1db5d582a7e 100644 --- a/spec/ruby/library/logger/device/close_spec.rb +++ b/spec/ruby/library/logger/device/close_spec.rb @@ -15,17 +15,8 @@ rm_r @file_path end - version_is Logger::VERSION, ""..."1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "closes the LogDevice's stream" do - @device.close - -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) - end + it "closes the LogDevice's stream" do + @device.close + -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/logger/device/write_spec.rb b/spec/ruby/library/logger/device/write_spec.rb index cd2d7e27a98..87ecf2ad6aa 100644 --- a/spec/ruby/library/logger/device/write_spec.rb +++ b/spec/ruby/library/logger/device/write_spec.rb @@ -35,17 +35,8 @@ rm_r path end - version_is Logger::VERSION, ""..."1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog writing failed\./) - end - end - - version_is Logger::VERSION, "1.4.0" do - it "fails if the device is already closed" do - @device.close - -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) - end + it "fails if the device is already closed" do + @device.close + -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb index b579cb244dc..04e6df8be09 100644 --- a/spec/ruby/library/matrix/unitary_spec.rb +++ b/spec/ruby/library/matrix/unitary_spec.rb @@ -14,10 +14,8 @@ Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary? end - version_is((Matrix::const_defined?(:VERSION) ? Matrix::VERSION : "0.1.0"), "0.3.0") do - it "returns true for unitary matrices with a Complex and a negative #imag" do - Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? - end + it "returns true for unitary matrices with a Complex and a negative #imag" do + Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? end it "raises an error for rectangular matrices" do diff --git a/spec/ruby/library/openssl/config/freeze_spec.rb b/spec/ruby/library/openssl/config/freeze_spec.rb deleted file mode 100644 index c814341b860..00000000000 --- a/spec/ruby/library/openssl/config/freeze_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../../spec_helper' -require_relative '../shared/constants' - -require 'openssl' - -version_is(OpenSSL::VERSION, ""..."2.2") do - describe "OpenSSL::Config#freeze" do - it "needs to be reviewed for completeness" - - it "freezes" do - c = OpenSSL::Config.new - -> { - c['foo'] = [ ['key', 'value'] ] - }.should_not raise_error - c.freeze - c.frozen?.should be_true - -> { - c['foo'] = [ ['key', 'value'] ] - }.should raise_error(TypeError) - end - end -end diff --git a/spec/ruby/library/stringio/initialize_spec.rb b/spec/ruby/library/stringio/initialize_spec.rb index c597e328d3d..158c08488b2 100644 --- a/spec/ruby/library/stringio/initialize_spec.rb +++ b/spec/ruby/library/stringio/initialize_spec.rb @@ -294,14 +294,9 @@ io.string.encoding.should == Encoding::EUC_JP end - guard_not -> { # [Bug #16497] - stringio_version = StringIO.const_defined?(:VERSION) ? StringIO::VERSION : "0.0.2" - version_is(stringio_version, "0.0.3"..."0.1.1") - } do - it "the #external_encoding to the encoding of the String when passed a String" do - s = ''.force_encoding(Encoding::EUC_JP) - io = StringIO.new(s) - io.external_encoding.should == Encoding::EUC_JP - end + it "the #external_encoding to the encoding of the String when passed a String" do + s = ''.force_encoding(Encoding::EUC_JP) + io = StringIO.new(s) + io.external_encoding.should == Encoding::EUC_JP end end diff --git a/spec/ruby/library/stringio/shared/each.rb b/spec/ruby/library/stringio/shared/each.rb index bf3265ee465..acd8d22c141 100644 --- a/spec/ruby/library/stringio/shared/each.rb +++ b/spec/ruby/library/stringio/shared/each.rb @@ -36,7 +36,7 @@ seen.should == ["2 1 2 1 2"] end - ruby_version_is ''..."3.2" do + version_is StringIO::VERSION, ""..."3.0.4" do #ruby_version_is ""..."3.2" do it "yields each paragraph with two separation characters when passed an empty String as separator" do seen = [] io = StringIO.new("para1\n\npara2\n\n\npara3") @@ -45,7 +45,7 @@ end end - ruby_version_is "3.2" do + version_is StringIO::VERSION, "3.0.4" do #ruby_version_is "3.2" do it "yields each paragraph with all separation characters when passed an empty String as separator" do seen = [] io = StringIO.new("para1\n\npara2\n\n\npara3") diff --git a/spec/ruby/library/time/to_datetime_spec.rb b/spec/ruby/library/time/to_datetime_spec.rb index 6025950b594..6e4d67eb530 100644 --- a/spec/ruby/library/time/to_datetime_spec.rb +++ b/spec/ruby/library/time/to_datetime_spec.rb @@ -13,8 +13,7 @@ datetime.sec.should == 59 end - date_version = defined?(Date::VERSION) ? Date::VERSION : '0.0.0' - version_is(date_version, '3.2.3') do + version_is(Date::VERSION, '3.2.3') do #ruby_version_is '3.2' do it "returns a DateTime representing the same instant before Gregorian" do time = Time.utc(1582, 10, 14, 23, 58, 59) datetime = time.to_datetime diff --git a/spec/ruby/library/uri/generic/host_spec.rb b/spec/ruby/library/uri/generic/host_spec.rb index 2de0e7ec098..210124ef661 100644 --- a/spec/ruby/library/uri/generic/host_spec.rb +++ b/spec/ruby/library/uri/generic/host_spec.rb @@ -2,7 +2,7 @@ require 'uri' describe "URI::Generic#host" do - ruby_version_is "3.2" do + version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do # https://hackerone.com/reports/156615 it "returns empty string when host is empty" do URI.parse('http:////foo.com').host.should == '' diff --git a/spec/ruby/library/uri/generic/to_s_spec.rb b/spec/ruby/library/uri/generic/to_s_spec.rb index 1dd1f2d1347..8cebd374a14 100644 --- a/spec/ruby/library/uri/generic/to_s_spec.rb +++ b/spec/ruby/library/uri/generic/to_s_spec.rb @@ -2,7 +2,7 @@ require 'uri' describe "URI::Generic#to_s" do - ruby_version_is "3.2" do + version_is URI::VERSION, "0.12" do #ruby_version_is "3.2" do # https://hackerone.com/reports/156615 it "preserves / characters when host is empty" do URI('http:///foo.com').to_s.should == 'http:///foo.com' diff --git a/spec/ruby/optional/capi/exception_spec.rb b/spec/ruby/optional/capi/exception_spec.rb index b0a8a2860ee..5bb60608b22 100644 --- a/spec/ruby/optional/capi/exception_spec.rb +++ b/spec/ruby/optional/capi/exception_spec.rb @@ -100,6 +100,40 @@ end end + describe "rb_syserr_new" do + it "returns system error with default message when passed message is NULL" do + exception = @s.rb_syserr_new(Errno::ENOENT::Errno, nil) + exception.class.should == Errno::ENOENT + exception.message.should include("No such file or directory") + exception.should.is_a?(SystemCallError) + end + + it "returns system error with custom message" do + exception = @s.rb_syserr_new(Errno::ENOENT::Errno, "custom message") + + exception.message.should include("custom message") + exception.class.should == Errno::ENOENT + exception.should.is_a?(SystemCallError) + end + end + + describe "rb_syserr_new_str" do + it "returns system error with default message when passed message is nil" do + exception = @s.rb_syserr_new_str(Errno::ENOENT::Errno, nil) + + exception.message.should include("No such file or directory") + exception.class.should == Errno::ENOENT + exception.should.is_a?(SystemCallError) + end + + it "returns system error with custom message" do + exception = @s.rb_syserr_new_str(Errno::ENOENT::Errno, "custom message") + exception.message.should include("custom message") + exception.class.should == Errno::ENOENT + exception.should.is_a?(SystemCallError) + end + end + describe "rb_make_exception" do it "returns a RuntimeError when given a String argument" do e = @s.rb_make_exception(["Message"]) diff --git a/spec/ruby/optional/capi/ext/class_spec.c b/spec/ruby/optional/capi/ext/class_spec.c index 589025f6776..f376534924c 100644 --- a/spec/ruby/optional/capi/ext/class_spec.c +++ b/spec/ruby/optional/capi/ext/class_spec.c @@ -72,7 +72,7 @@ static VALUE class_spec_rb_class_new_instance_kw(VALUE self, VALUE args, VALUE k #endif static VALUE class_spec_rb_class_real(VALUE self, VALUE object) { - if(rb_type_p(object, T_FIXNUM)) { + if (rb_type_p(object, T_FIXNUM)) { return INT2FIX(rb_class_real(FIX2INT(object))); } else { return rb_class_real(CLASS_OF(object)); @@ -116,19 +116,19 @@ VALUE class_spec_define_attr(VALUE self, VALUE klass, VALUE sym, VALUE read, VAL } static VALUE class_spec_rb_define_class(VALUE self, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class(RSTRING_PTR(name), super); } static VALUE class_spec_rb_define_class_under(VALUE self, VALUE outer, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class_under(outer, RSTRING_PTR(name), super); } static VALUE class_spec_rb_define_class_id_under(VALUE self, VALUE outer, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class_id_under(outer, SYM2ID(name), super); } diff --git a/spec/ruby/optional/capi/ext/debug_spec.c b/spec/ruby/optional/capi/ext/debug_spec.c index 344dfc33fab..9131eda78b6 100644 --- a/spec/ruby/optional/capi/ext/debug_spec.c +++ b/spec/ruby/optional/capi/ext/debug_spec.c @@ -45,7 +45,7 @@ static VALUE rb_debug_inspector_frame_iseq_get_callback(const rb_debug_inspector return rb_debug_inspector_frame_iseq_get(dc, NUM2LONG((VALUE) ptr)); } -static VALUE debug_spec_callback_data(VALUE self){ +static VALUE debug_spec_callback_data(VALUE self) { return callback_data; } diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c index a0136530f28..a454ae8395f 100644 --- a/spec/ruby/optional/capi/ext/encoding_spec.c +++ b/spec/ruby/optional/capi/ext/encoding_spec.c @@ -12,7 +12,7 @@ static VALUE encoding_spec_MBCLEN_CHARFOUND_P(VALUE self, VALUE obj) { } static VALUE encoding_spec_ENC_CODERANGE_ASCIIONLY(VALUE self, VALUE obj) { - if(ENC_CODERANGE_ASCIIONLY(obj)) { + if (ENC_CODERANGE_ASCIIONLY(obj)) { return Qtrue; } else { return Qfalse; @@ -61,13 +61,13 @@ static VALUE encoding_spec_rb_filesystem_encindex(VALUE self) { static VALUE encoding_spec_rb_default_internal_encoding(VALUE self) { rb_encoding* enc = rb_default_internal_encoding(); - if(enc == 0) return Qnil; + if (enc == 0) return Qnil; return rb_str_new2(enc->name); } static VALUE encoding_spec_rb_default_external_encoding(VALUE self) { rb_encoding* enc = rb_default_external_encoding(); - if(enc == 0) return Qnil; + if (enc == 0) return Qnil; return rb_str_new2(enc->name); } @@ -86,7 +86,7 @@ static VALUE encoding_spec_rb_enc_associate_index(VALUE self, VALUE obj, VALUE i static VALUE encoding_spec_rb_enc_compatible(VALUE self, VALUE a, VALUE b) { rb_encoding* enc = rb_enc_compatible(a, b); - if(!enc) return INT2FIX(0); + if (!enc) return INT2FIX(0); return rb_enc_from_encoding(enc); } diff --git a/spec/ruby/optional/capi/ext/exception_spec.c b/spec/ruby/optional/capi/ext/exception_spec.c index e1114aabb88..0e8347ab0d6 100644 --- a/spec/ruby/optional/capi/ext/exception_spec.c +++ b/spec/ruby/optional/capi/ext/exception_spec.c @@ -27,7 +27,7 @@ VALUE exception_spec_rb_exc_new3(VALUE self, VALUE str) { } VALUE exception_spec_rb_exc_raise(VALUE self, VALUE exc) { - if (self != Qundef) rb_exc_raise(exc); + if (self != Qundef) rb_exc_raise(exc); return Qnil; } @@ -36,6 +36,21 @@ VALUE exception_spec_rb_set_errinfo(VALUE self, VALUE exc) { return Qnil; } +VALUE exception_spec_rb_syserr_new(VALUE self, VALUE num, VALUE msg) { + int n = NUM2INT(num); + char *cstr = NULL; + + if (msg != Qnil) { + cstr = StringValuePtr(msg); + } + + return rb_syserr_new(n, cstr); +} + +VALUE exception_spec_rb_syserr_new_str(VALUE self, VALUE num, VALUE msg) { + int n = NUM2INT(num); + return rb_syserr_new_str(n, msg); +} VALUE exception_spec_rb_make_exception(VALUE self, VALUE ary) { int argc = RARRAY_LENINT(ary); @@ -51,6 +66,8 @@ void Init_exception_spec(void) { rb_define_method(cls, "rb_exc_new3", exception_spec_rb_exc_new3, 1); rb_define_method(cls, "rb_exc_raise", exception_spec_rb_exc_raise, 1); rb_define_method(cls, "rb_set_errinfo", exception_spec_rb_set_errinfo, 1); + rb_define_method(cls, "rb_syserr_new", exception_spec_rb_syserr_new, 2); + rb_define_method(cls, "rb_syserr_new_str", exception_spec_rb_syserr_new_str, 2); rb_define_method(cls, "rb_make_exception", exception_spec_rb_make_exception, 1); } diff --git a/spec/ruby/optional/capi/ext/gc_spec.c b/spec/ruby/optional/capi/ext/gc_spec.c index b323c2456da..7dd0b876550 100644 --- a/spec/ruby/optional/capi/ext/gc_spec.c +++ b/spec/ruby/optional/capi/ext/gc_spec.c @@ -51,7 +51,7 @@ static VALUE gc_spec_rb_gc(VALUE self) { return Qnil; } -static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key){ +static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key) { return rb_gc_latest_gc_info(hash_or_key); } diff --git a/spec/ruby/optional/capi/ext/hash_spec.c b/spec/ruby/optional/capi/ext/hash_spec.c index 7f387089150..69ef02d5da6 100644 --- a/spec/ruby/optional/capi/ext/hash_spec.c +++ b/spec/ruby/optional/capi/ext/hash_spec.c @@ -105,6 +105,12 @@ VALUE hash_spec_rb_hash_new(VALUE self) { return rb_hash_new(); } +#ifdef RUBY_VERSION_IS_3_2 +VALUE hash_spec_rb_hash_new_capa(VALUE self, VALUE capacity) { + return rb_hash_new_capa(NUM2LONG(capacity)); +} +#endif + VALUE rb_ident_hash_new(void); /* internal.h, used in ripper */ VALUE hash_spec_rb_ident_hash_new(VALUE self) { @@ -149,6 +155,9 @@ void Init_hash_spec(void) { rb_define_method(cls, "rb_hash_lookup2", hash_spec_rb_hash_lookup2, 3); rb_define_method(cls, "rb_hash_lookup2_default_undef", hash_spec_rb_hash_lookup2_default_undef, 2); rb_define_method(cls, "rb_hash_new", hash_spec_rb_hash_new, 0); +#ifdef RUBY_VERSION_IS_3_2 + rb_define_method(cls, "rb_hash_new_capa", hash_spec_rb_hash_new_capa, 1); +#endif rb_define_method(cls, "rb_ident_hash_new", hash_spec_rb_ident_hash_new, 0); rb_define_method(cls, "rb_hash_size", hash_spec_rb_hash_size, 1); rb_define_method(cls, "rb_hash_set_ifnone", hash_spec_rb_hash_set_ifnone, 2); diff --git a/spec/ruby/optional/capi/ext/integer_spec.c b/spec/ruby/optional/capi/ext/integer_spec.c index 16cd95f111d..792fc0652a0 100644 --- a/spec/ruby/optional/capi/ext/integer_spec.c +++ b/spec/ruby/optional/capi/ext/integer_spec.c @@ -6,8 +6,7 @@ extern "C" { #endif static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value, - VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags) -{ + VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags) { int result = rb_integer_pack(value, (void*)RSTRING_PTR(words), FIX2INT(numwords), FIX2INT(wordsize), FIX2INT(nails), FIX2INT(flags)); return INT2FIX(result); @@ -15,7 +14,7 @@ static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value, RUBY_EXTERN VALUE rb_int_positive_pow(long x, unsigned long y); /* internal.h, used in ripper */ -static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b){ +static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b) { return rb_int_positive_pow(FIX2INT(a), FIX2INT(b)); } diff --git a/spec/ruby/optional/capi/ext/io_spec.c b/spec/ruby/optional/capi/ext/io_spec.c index 1c554a1a31d..ab3aef4c923 100644 --- a/spec/ruby/optional/capi/ext/io_spec.c +++ b/spec/ruby/optional/capi/ext/io_spec.c @@ -134,7 +134,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) { rb_sys_fail("set_non_blocking failed"); #ifndef SET_NON_BLOCKING_FAILS_ALWAYS - if(RTEST(read_p)) { + if (RTEST(read_p)) { if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { return Qnil; } @@ -145,7 +145,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) { ret = rb_io_wait_readable(fd); - if(RTEST(read_p)) { + if (RTEST(read_p)) { ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF); if (r != RB_IO_WAIT_READABLE_BUF) { perror("read"); @@ -185,7 +185,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE rb_sys_fail("set_non_blocking failed"); #ifndef SET_NON_BLOCKING_FAILS_ALWAYS - if(RTEST(read_p)) { + if (RTEST(read_p)) { if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { return Qnil; } @@ -197,7 +197,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE // main part ret = rb_io_maybe_wait_readable(NUM2INT(error), io, timeout); - if(RTEST(read_p)) { + if (RTEST(read_p)) { ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF); if (r != RB_IO_WAIT_READABLE_BUF) { perror("read"); diff --git a/spec/ruby/optional/capi/ext/kernel_spec.c b/spec/ruby/optional/capi/ext/kernel_spec.c index c83c49e923d..a921eb13e04 100644 --- a/spec/ruby/optional/capi/ext/kernel_spec.c +++ b/spec/ruby/optional/capi/ext/kernel_spec.c @@ -220,7 +220,7 @@ static VALUE kernel_spec_rb_eval_string_protect(VALUE self, VALUE str, VALUE ary VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) { errno = 1; - if(msg == Qnil) { + if (msg == Qnil) { rb_sys_fail(0); } else if (self != Qundef) { rb_sys_fail(StringValuePtr(msg)); @@ -229,7 +229,7 @@ VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) { } VALUE kernel_spec_rb_syserr_fail(VALUE self, VALUE err, VALUE msg) { - if(msg == Qnil) { + if (msg == Qnil) { rb_syserr_fail(NUM2INT(err), NULL); } else if (self != Qundef) { rb_syserr_fail(NUM2INT(err), StringValuePtr(msg)); @@ -292,9 +292,9 @@ static VALUE kernel_spec_rb_yield_values2(VALUE self, VALUE ary) { } static VALUE do_rec(VALUE obj, VALUE arg, int is_rec) { - if(is_rec) { + if (is_rec) { return obj; - } else if(arg == Qtrue) { + } else if (arg == Qtrue) { return rb_exec_recursive(do_rec, obj, Qnil); } else { return Qnil; diff --git a/spec/ruby/optional/capi/ext/object_spec.c b/spec/ruby/optional/capi/ext/object_spec.c index 30ac44cf1fe..fbcf6d99626 100644 --- a/spec/ruby/optional/capi/ext/object_spec.c +++ b/spec/ruby/optional/capi/ext/object_spec.c @@ -218,126 +218,126 @@ static VALUE so_check_type(VALUE self, VALUE obj, VALUE other) { } static VALUE so_is_type_nil(VALUE self, VALUE obj) { - if(TYPE(obj) == T_NIL) { + if (TYPE(obj) == T_NIL) { return Qtrue; } return Qfalse; } static VALUE so_is_type_object(VALUE self, VALUE obj) { - if(TYPE(obj) == T_OBJECT) { + if (TYPE(obj) == T_OBJECT) { return Qtrue; } return Qfalse; } static VALUE so_is_type_array(VALUE self, VALUE obj) { - if(TYPE(obj) == T_ARRAY) { + if (TYPE(obj) == T_ARRAY) { return Qtrue; } return Qfalse; } static VALUE so_is_type_module(VALUE self, VALUE obj) { - if(TYPE(obj) == T_MODULE) { + if (TYPE(obj) == T_MODULE) { return Qtrue; } return Qfalse; } static VALUE so_is_type_class(VALUE self, VALUE obj) { - if(TYPE(obj) == T_CLASS) { + if (TYPE(obj) == T_CLASS) { return Qtrue; } return Qfalse; } static VALUE so_is_type_data(VALUE self, VALUE obj) { - if(TYPE(obj) == T_DATA) { + if (TYPE(obj) == T_DATA) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_nil(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_NIL)) { + if (rb_type_p(obj, T_NIL)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_object(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_OBJECT)) { + if (rb_type_p(obj, T_OBJECT)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_array(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_ARRAY)) { + if (rb_type_p(obj, T_ARRAY)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_module(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_MODULE)) { + if (rb_type_p(obj, T_MODULE)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_class(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_CLASS)) { + if (rb_type_p(obj, T_CLASS)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_data(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_DATA)) { + if (rb_type_p(obj, T_DATA)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_file(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_FILE)) { + if (rb_type_p(obj, T_FILE)) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_object(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_OBJECT) { + if (BUILTIN_TYPE(obj) == T_OBJECT) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_array(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_ARRAY) { + if (BUILTIN_TYPE(obj) == T_ARRAY) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_module(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_MODULE) { + if (BUILTIN_TYPE(obj) == T_MODULE) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_class(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_CLASS) { + if (BUILTIN_TYPE(obj) == T_CLASS) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_data(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_DATA) { + if (BUILTIN_TYPE(obj) == T_DATA) { return Qtrue; } return Qfalse; diff --git a/spec/ruby/optional/capi/ext/range_spec.c b/spec/ruby/optional/capi/ext/range_spec.c index 7a475ec695c..b0cf1a86626 100644 --- a/spec/ruby/optional/capi/ext/range_spec.c +++ b/spec/ruby/optional/capi/ext/range_spec.c @@ -7,7 +7,7 @@ extern "C" { VALUE range_spec_rb_range_new(int argc, VALUE* argv, VALUE self) { int exclude_end = 0; - if(argc == 3) { + if (argc == 3) { exclude_end = RTEST(argv[2]); } return rb_range_new(argv[0], argv[1], exclude_end); diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 9cbb50484df..24a9b4e4ca0 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -62,7 +62,7 @@ VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) { buf = rb_str_buf_new(NUM2LONG(len)); - if(RTEST(str)) { + if (RTEST(str)) { snprintf(RSTRING_PTR(buf), NUM2LONG(len), "%s", RSTRING_PTR(str)); } @@ -129,7 +129,7 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) { from_enc = rb_to_encoding(from); - if(NIL_P(to)) { + if (NIL_P(to)) { to_enc = 0; } else { to_enc = rb_to_encoding(to); @@ -139,14 +139,13 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) { } VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE to, - VALUE ecflags, VALUE ecopts) -{ + VALUE ecflags, VALUE ecopts) { rb_encoding* from_enc; rb_encoding* to_enc; from_enc = rb_to_encoding(from); - if(NIL_P(to)) { + if (NIL_P(to)) { to_enc = 0; } else { to_enc = rb_to_encoding(to); @@ -200,7 +199,7 @@ VALUE string_spec_rb_str_new_offset(VALUE self, VALUE str, VALUE offset, VALUE l } VALUE string_spec_rb_str_new2(VALUE self, VALUE str) { - if(NIL_P(str)) { + if (NIL_P(str)) { return rb_str_new2(""); } else { return rb_str_new2(RSTRING_PTR(str)); @@ -216,7 +215,7 @@ VALUE string_spec_rb_str_export_to_enc(VALUE self, VALUE str, VALUE enc) { } VALUE string_spec_rb_str_new_cstr(VALUE self, VALUE str) { - if(NIL_P(str)) { + if (NIL_P(str)) { return rb_str_new_cstr(""); } else { return rb_str_new_cstr(RSTRING_PTR(str)); @@ -390,7 +389,7 @@ VALUE string_spec_RSTRING_PTR_set(VALUE self, VALUE str, VALUE i, VALUE chr) { VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) { /* Silence gcc 4.3.2 warning about computed value not used */ - if(RSTRING_PTR(str)) { /* force it out */ + if (RSTRING_PTR(str)) { /* force it out */ rb_funcall(cb, rb_intern("call"), 1, str); } @@ -573,7 +572,7 @@ static VALUE string_spec_rb_utf8_str_new_cstr(VALUE self) { } PRINTF_ARGS(static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...), 2, 3); -static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...){ +static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...) { va_list ap; va_start(ap, fmt); VALUE result = rb_str_vcatf(mesg, fmt, ap); diff --git a/spec/ruby/optional/capi/ext/struct_spec.c b/spec/ruby/optional/capi/ext/struct_spec.c index 0393d6937d2..9c45bd56724 100644 --- a/spec/ruby/optional/capi/ext/struct_spec.c +++ b/spec/ruby/optional/capi/ext/struct_spec.c @@ -15,13 +15,11 @@ static VALUE struct_spec_rb_struct_getmember(VALUE self, VALUE st, VALUE key) { return rb_struct_getmember(st, SYM2ID(key)); } -static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass) -{ +static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass) { return rb_ary_dup(rb_struct_s_members(klass)); } -static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st) -{ +static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st) { return rb_ary_dup(rb_struct_members(st)); } @@ -56,14 +54,11 @@ static VALUE struct_spec_struct_define_under(VALUE self, VALUE outer, } static VALUE struct_spec_rb_struct_new(VALUE self, VALUE klass, - VALUE a, VALUE b, VALUE c) -{ - + VALUE a, VALUE b, VALUE c) { return rb_struct_new(klass, a, b, c); } -static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) -{ +static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) { return rb_struct_size(st); } diff --git a/spec/ruby/optional/capi/ext/tracepoint_spec.c b/spec/ruby/optional/capi/ext/tracepoint_spec.c index 78c459d6cbe..6666c8f85c3 100644 --- a/spec/ruby/optional/capi/ext/tracepoint_spec.c +++ b/spec/ruby/optional/capi/ext/tracepoint_spec.c @@ -17,7 +17,7 @@ static VALUE tracepoint_spec_rb_tracepoint_new(VALUE self, VALUE data) { return rb_tracepoint_new(Qnil, RUBY_EVENT_LINE, callback, (void*) data); } -static VALUE tracepoint_spec_callback_called(VALUE self){ +static VALUE tracepoint_spec_callback_called(VALUE self) { return callback_called; } diff --git a/spec/ruby/optional/capi/hash_spec.rb b/spec/ruby/optional/capi/hash_spec.rb index a60467a66bc..a0e49ffc4cc 100644 --- a/spec/ruby/optional/capi/hash_spec.rb +++ b/spec/ruby/optional/capi/hash_spec.rb @@ -50,6 +50,22 @@ end end + ruby_version_is '3.2' do + describe "rb_hash_new_capa" do + it "returns a new hash" do + @s.rb_hash_new_capa(3).should == {} + end + + it "creates a hash with no default proc" do + @s.rb_hash_new_capa(3) {}.default_proc.should be_nil + end + + it "raises RuntimeError when negative index is provided" do + -> { @s.rb_hash_new_capa(-1) }.should raise_error(RuntimeError, "st_table too big") + end + end + end + describe "rb_ident_hash_new" do it "returns a new compare by identity hash" do result = @s.rb_ident_hash_new diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb index 059f1025a75..3bc8008fa4e 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -37,7 +37,7 @@ q << 1 t = Thread.new { - -> { q.send(@method, 2) }.should raise_error(ClosedQueueError) + -> { q.send(@method, 2) }.should raise_error(ClosedQueueError, "queue closed") } Thread.pass until q.num_waiting == 1 @@ -108,6 +108,28 @@ "can't set a timeout if non_block is enabled", ) end + + it "raise ClosedQueueError when closed before enqueued" do + q = @object.call(1) + q.close + -> { q.send(@method, 2, timeout: 1) }.should raise_error(ClosedQueueError, "queue closed") + end + + it "interrupts enqueuing threads with ClosedQueueError when the queue is closed" do + q = @object.call(1) + q << 1 + + t = Thread.new { + -> { q.send(@method, 1, timeout: 0.1) }.should raise_error(ClosedQueueError, "queue closed") + } + + Thread.pass until q.num_waiting == 1 + + q.close + + t.join + q.pop.should == 1 + end end end end From 0e5865eaef3329b541a933025002bea4a8bf531e Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 3 Aug 2023 19:18:19 +0200 Subject: [PATCH 2/3] Add tags for new failing specs --- spec/tags/ruby/core/string/index_tags.txt | 1 + spec/tags/ruby/core/string/tr_s_tags.txt | 1 + spec/tags/ruby/core/string/tr_tags.txt | 1 + spec/tags/ruby/library/stringio/each_line_tags.txt | 1 + 4 files changed, 4 insertions(+) create mode 100644 spec/tags/ruby/core/string/index_tags.txt create mode 100644 spec/tags/ruby/core/string/tr_s_tags.txt create mode 100644 spec/tags/ruby/core/string/tr_tags.txt create mode 100644 spec/tags/ruby/library/stringio/each_line_tags.txt diff --git a/spec/tags/ruby/core/string/index_tags.txt b/spec/tags/ruby/core/string/index_tags.txt new file mode 100644 index 00000000000..a668adbffef --- /dev/null +++ b/spec/tags/ruby/core/string/index_tags.txt @@ -0,0 +1 @@ +fails:String#index with Regexp raises an Encoding::CompatibilityError if the encodings are incompatible diff --git a/spec/tags/ruby/core/string/tr_s_tags.txt b/spec/tags/ruby/core/string/tr_s_tags.txt new file mode 100644 index 00000000000..a9517324893 --- /dev/null +++ b/spec/tags/ruby/core/string/tr_s_tags.txt @@ -0,0 +1 @@ +fails:String#tr_s accepts c1-c1 notation to denote range of one character diff --git a/spec/tags/ruby/core/string/tr_tags.txt b/spec/tags/ruby/core/string/tr_tags.txt new file mode 100644 index 00000000000..7748df2e55b --- /dev/null +++ b/spec/tags/ruby/core/string/tr_tags.txt @@ -0,0 +1 @@ +fails:String#tr accepts c1-c1 notation to denote range of one character diff --git a/spec/tags/ruby/library/stringio/each_line_tags.txt b/spec/tags/ruby/library/stringio/each_line_tags.txt new file mode 100644 index 00000000000..f116e8a505e --- /dev/null +++ b/spec/tags/ruby/library/stringio/each_line_tags.txt @@ -0,0 +1 @@ +fails:An exception occurred during: stringio_each_separator From 96f9c3655a488efa6bc99a1f8141d9a94670a16d Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 7 Aug 2023 17:28:26 -0500 Subject: [PATCH 3/3] Remove rogue logging --- lib/pom.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/pom.rb b/lib/pom.rb index 62de720f323..0eebec772ae 100644 --- a/lib/pom.rb +++ b/lib/pom.rb @@ -376,7 +376,6 @@ def installer.ensure_required_ruby_version_met; end # maintainers like OpenBSD (see #1989). hack = File.join jruby_gems, 'gems', 'axiom-types-*' (Dir[File.join(hack, '**/*')] + Dir[File.join(hack, '**/.*' )]).each do |f| - puts "F: #{f}" FileUtils.chmod 'u+rw,go+r' rescue nil if File.file?(f) end end