Skip to content

Commit

Permalink
Merge pull request jruby#8120 from eregon/update-specs
Browse files Browse the repository at this point in the history
Update specs
  • Loading branch information
eregon authored Feb 26, 2024
2 parents f95b430 + 75d9c74 commit 9a951a2
Show file tree
Hide file tree
Showing 614 changed files with 9,398 additions and 9,843 deletions.
2 changes: 1 addition & 1 deletion spec/jruby.mspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MSpecScript
SPEC_DIR + '/core/kernel/at_exit_spec.rb',
SPEC_DIR + '/language/predefined_spec.rb',
SPEC_DIR + '/language/predefined/data_spec.rb',
SPEC_DIR + '/library/net/http',
SPEC_DIR + '/library/net-http',
*get(:command_line),
*get(:security),
]
Expand Down
8 changes: 7 additions & 1 deletion spec/mspec/lib/mspec/runner/formatters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

if ENV['CHECK_LEAKS']
require 'mspec/runner/actions/leakchecker'
end

if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']
require 'mspec/runner/actions/constants_leak_checker'
end

Expand Down Expand Up @@ -40,8 +43,11 @@ def register
@counter = @tally.counter

if ENV['CHECK_LEAKS']
save = ENV['CHECK_LEAKS'] == 'save'
LeakCheckerAction.new.register
end

if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']
save = ENV['CHECK_LEAKS'] == 'save' || ENV['CHECK_CONSTANT_LEAKS'] == 'save'
ConstantsLeakCheckerAction.new(save).register
end

Expand Down
9 changes: 5 additions & 4 deletions spec/mspec/spec/integration/run_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
require 'spec_helper'

RSpec.describe "Running mspec" do
q = BACKTRACE_QUOTE
a_spec_output = <<EOS
1)
Foo#bar errors FAILED
Expected 1 == 2
to be truthy but was false
CWD/spec/fixtures/a_spec.rb:8:in `block (2 levels) in <top (required)>'
CWD/spec/fixtures/a_spec.rb:2:in `<top (required)>'
CWD/spec/fixtures/a_spec.rb:8:in #{q}block (2 levels) in <top (required)>'
CWD/spec/fixtures/a_spec.rb:2:in #{q}<top (required)>'
2)
Foo#bar fails ERROR
RuntimeError: failure
CWD/spec/fixtures/a_spec.rb:12:in `block (2 levels) in <top (required)>'
CWD/spec/fixtures/a_spec.rb:2:in `<top (required)>'
CWD/spec/fixtures/a_spec.rb:12:in #{q}block (2 levels) in <top (required)>'
CWD/spec/fixtures/a_spec.rb:2:in #{q}<top (required)>'
Finished in D.DDDDDD seconds
EOS
Expand Down
9 changes: 5 additions & 4 deletions spec/mspec/spec/integration/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
it "tags the failing specs" do
fixtures = "spec/fixtures"
out, ret = run_mspec("tag", "--add fails --fail #{fixtures}/tagging_spec.rb")
q = BACKTRACE_QUOTE
expect(out).to eq <<EOS
RUBY_DESCRIPTION
.FF
Expand All @@ -26,15 +27,15 @@
Tag#me errors FAILED
Expected 1 == 2
to be truthy but was false
CWD/spec/fixtures/tagging_spec.rb:9:in `block (2 levels) in <top (required)>'
CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>'
CWD/spec/fixtures/tagging_spec.rb:9:in #{q}block (2 levels) in <top (required)>'
CWD/spec/fixtures/tagging_spec.rb:3:in #{q}<top (required)>'
2)
Tag#me érròrs in unicode FAILED
Expected 1 == 2
to be truthy but was false
CWD/spec/fixtures/tagging_spec.rb:13:in `block (2 levels) in <top (required)>'
CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>'
CWD/spec/fixtures/tagging_spec.rb:13:in #{q}block (2 levels) in <top (required)>'
CWD/spec/fixtures/tagging_spec.rb:3:in #{q}<top (required)>'
Finished in D.DDDDDD seconds
Expand Down
2 changes: 2 additions & 0 deletions spec/mspec/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ def ensure_mspec_method(method)
include MSpecMatchers
public :raise_error
}.new

BACKTRACE_QUOTE = RUBY_VERSION >= "3.4" ? "'" : "`"
1 change: 0 additions & 1 deletion spec/ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Lint/LiteralInInterpolation:
- 'language/string_spec.rb'
- 'language/symbol_spec.rb'
- 'language/undef_spec.rb'
- 'library/net/ftp/connect_spec.rb'

# Offense count: 8
# Cop supports --auto-correct.
Expand Down
87 changes: 67 additions & 20 deletions spec/ruby/command_line/backtrace_limit_spec.rb
Original file line number Diff line number Diff line change
@@ -1,46 +1,93 @@
require_relative '../spec_helper'

describe "The --backtrace-limit command line option" do
it "limits top-level backtraces to a given number of entries" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
out = out.gsub(__dir__, '')
ruby_version_is ""..."3.4" do
it "limits top-level backtraces to a given number of entries" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
out = out.gsub(__dir__, '')

out.should == <<-MSG
out.should == <<-MSG
top
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in `b'
\tfrom /fixtures/backtrace.rb:10:in `c'
\t ... 2 levels...
MSG
end
MSG
end

it "affects Exception#full_message" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
out = out.gsub(__dir__, '')
it "affects Exception#full_message" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
out = out.gsub(__dir__, '')

out.should == <<-MSG
out.should == <<-MSG
full_message
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in `b'
\tfrom /fixtures/backtrace.rb:10:in `c'
\t ... 2 levels...
MSG
end
MSG
end

it "does not affect Exception#backtrace" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
out = out.gsub(__dir__, '')
it "does not affect Exception#backtrace" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
out = out.gsub(__dir__, '')

out.should == <<-MSG
out.should == <<-MSG
backtrace
/fixtures/backtrace.rb:2:in `a'
/fixtures/backtrace.rb:6:in `b'
/fixtures/backtrace.rb:10:in `c'
/fixtures/backtrace.rb:14:in `d'
/fixtures/backtrace.rb:29:in `<main>'
MSG
MSG
end
end

ruby_version_is "3.4" do
it "limits top-level backtraces to a given number of entries" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
out = out.gsub(__dir__, '')

out.should == <<-MSG
top
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
\t ... 2 levels...
MSG
end

it "affects Exception#full_message" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
out = out.gsub(__dir__, '')

out.should == <<-MSG
full_message
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
\t ... 2 levels...
MSG
end

it "does not affect Exception#backtrace" do
file = fixture(__FILE__ , "backtrace.rb")
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
out = out.gsub(__dir__, '')

out.should == <<-MSG
backtrace
/fixtures/backtrace.rb:2:in 'Object#a'
/fixtures/backtrace.rb:6:in 'Object#b'
/fixtures/backtrace.rb:10:in 'Object#c'
/fixtures/backtrace.rb:14:in 'Object#d'
/fixtures/backtrace.rb:29:in '<main>'
MSG
end
end
end
8 changes: 4 additions & 4 deletions spec/ruby/core/basicobject/singleton_method_added_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class << self
-> {
def self.foo
end
}.should raise_error(NoMethodError, /undefined method `singleton_method_added' for/)
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for/)
end
end

Expand All @@ -106,16 +106,16 @@ class << object
-> {
def foo
end
}.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)

-> {
define_method(:bar) {}
}.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)
end

-> {
object.define_singleton_method(:baz) {}
}.should raise_error(NoMethodError, /undefined method `singleton_method_added' for #<Object:/)
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)
end

it "calls #method_missing" do
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/binding/clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

describe "Binding#clone" do
it_behaves_like :binding_clone, :clone

it "preserves frozen status" do
bind = binding.freeze
bind.frozen?.should == true
bind.clone.frozen?.should == true
end
end
6 changes: 6 additions & 0 deletions spec/ruby/core/binding/dup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@

describe "Binding#dup" do
it_behaves_like :binding_clone, :dup

it "resets frozen status" do
bind = binding.freeze
bind.frozen?.should == true
bind.dup.frozen?.should == false
end
end
22 changes: 22 additions & 0 deletions spec/ruby/core/binding/shared/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,26 @@
b2.local_variable_defined?(:x).should == false
end
end

ruby_version_is "3.4" do
it "copies instance variables" do
@b1.instance_variable_set(:@ivar, 1)
cl = @b1.send(@method)
cl.instance_variables.should == [:@ivar]
end

it "copies the finalizer" do
code = <<-RUBY
obj = binding
ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
obj.clone
exit 0
RUBY

ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
end
end
end
6 changes: 3 additions & 3 deletions spec/ruby/core/class/attached_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
end

it "raises TypeError for special singleton classes" do
-> { nil.singleton_class.attached_object }.should raise_error(TypeError, /`NilClass' is not a singleton class/)
-> { true.singleton_class.attached_object }.should raise_error(TypeError, /`TrueClass' is not a singleton class/)
-> { false.singleton_class.attached_object }.should raise_error(TypeError, /`FalseClass' is not a singleton class/)
-> { nil.singleton_class.attached_object }.should raise_error(TypeError, /[`']NilClass' is not a singleton class/)
-> { true.singleton_class.attached_object }.should raise_error(TypeError, /[`']TrueClass' is not a singleton class/)
-> { false.singleton_class.attached_object }.should raise_error(TypeError, /[`']FalseClass' is not a singleton class/)
end
end
end
5 changes: 5 additions & 0 deletions spec/ruby/core/encoding/replicate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
Encoding::US_ASCII.replicate('MY-US-ASCII')
}.should complain(/warning: Encoding#replicate is deprecated and will be removed in Ruby 3.3; use the original encoding instead/)
end

it "raises EncodingError if too many encodings" do
code = '1_000.times {|i| Encoding::US_ASCII.replicate("R_#{i}") }'
ruby_exe(code, args: "2>&1", exit_status: 1).should.include?('too many encoding (> 256) (EncodingError)')
end
end

ruby_version_is "3.3" do
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/enumerable/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,10 @@ def ===(*args)
@block.call(*args)
end
end

# Set is a core class since Ruby 3.2
ruby_version_is '3.2' do
class SetSubclass < Set
end
end
end # EnumerableSpecs utility classes
29 changes: 29 additions & 0 deletions spec/ruby/core/enumerable/to_set_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative '../../spec_helper'
require_relative 'fixtures/classes'

ruby_version_is "3.2" do
describe "Enumerable#to_set" do
it "returns a new Set created from self" do
[1, 2, 3].to_set.should == Set[1, 2, 3]
{a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]]
end

it "passes down passed blocks" do
[1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
end

it "instantiates an object of provided as the first argument set class" do
set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)
set.should be_kind_of(EnumerableSpecs::SetSubclass)
set.to_a.sort.should == [1, 2, 3]
end

it "does not need explicit `require 'set'`" do
output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
puts [1, 2, 3].to_set
RUBY

output.chomp.should == "#<Set: {1, 2, 3}>"
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/product/each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def object2.each_entry
it "raises a NoMethodError if the object doesn't respond to #each_entry" do
-> {
Enumerator::Product.new(Object.new).each {}
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
}.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
end

it "returns enumerator if not given a block" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerator/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def object.each_entry
it "raises NoMethodError when argument doesn't respond to #each_entry" do
-> {
Enumerator.product(Object.new).to_a
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
}.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
end

it "calls #each_entry lazily" do
Expand Down
Loading

0 comments on commit 9a951a2

Please sign in to comment.