Skip to content

Commit 945b165

Browse files
committed
[GR-14806] Update specs
PullRequest: truffleruby/4190
2 parents 5337682 + 6b00a27 commit 945b165

File tree

687 files changed

+9096
-10138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

687 files changed

+9096
-10138
lines changed

spec/mspec/lib/mspec/runner/formatters/base.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
if ENV['CHECK_LEAKS']
77
require 'mspec/runner/actions/leakchecker'
8+
end
9+
10+
if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']
811
require 'mspec/runner/actions/constants_leak_checker'
912
end
1013

@@ -40,8 +43,11 @@ def register
4043
@counter = @tally.counter
4144

4245
if ENV['CHECK_LEAKS']
43-
save = ENV['CHECK_LEAKS'] == 'save'
4446
LeakCheckerAction.new.register
47+
end
48+
49+
if ENV['CHECK_LEAKS'] || ENV['CHECK_CONSTANT_LEAKS']
50+
save = ENV['CHECK_LEAKS'] == 'save' || ENV['CHECK_CONSTANT_LEAKS'] == 'save'
4551
ConstantsLeakCheckerAction.new(save).register
4652
end
4753

spec/mspec/spec/integration/run_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
require 'spec_helper'
22

33
RSpec.describe "Running mspec" do
4+
q = BACKTRACE_QUOTE
45
a_spec_output = <<EOS
56
67
1)
78
Foo#bar errors FAILED
89
Expected 1 == 2
910
to be truthy but was false
10-
CWD/spec/fixtures/a_spec.rb:8:in `block (2 levels) in <top (required)>'
11-
CWD/spec/fixtures/a_spec.rb:2:in `<top (required)>'
11+
CWD/spec/fixtures/a_spec.rb:8:in #{q}block (2 levels) in <top (required)>'
12+
CWD/spec/fixtures/a_spec.rb:2:in #{q}<top (required)>'
1213
1314
2)
1415
Foo#bar fails ERROR
1516
RuntimeError: failure
16-
CWD/spec/fixtures/a_spec.rb:12:in `block (2 levels) in <top (required)>'
17-
CWD/spec/fixtures/a_spec.rb:2:in `<top (required)>'
17+
CWD/spec/fixtures/a_spec.rb:12:in #{q}block (2 levels) in <top (required)>'
18+
CWD/spec/fixtures/a_spec.rb:2:in #{q}<top (required)>'
1819
1920
Finished in D.DDDDDD seconds
2021
EOS

spec/mspec/spec/integration/tag_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
it "tags the failing specs" do
1414
fixtures = "spec/fixtures"
1515
out, ret = run_mspec("tag", "--add fails --fail #{fixtures}/tagging_spec.rb")
16+
q = BACKTRACE_QUOTE
1617
expect(out).to eq <<EOS
1718
RUBY_DESCRIPTION
1819
.FF
@@ -26,15 +27,15 @@
2627
Tag#me errors FAILED
2728
Expected 1 == 2
2829
to be truthy but was false
29-
CWD/spec/fixtures/tagging_spec.rb:9:in `block (2 levels) in <top (required)>'
30-
CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>'
30+
CWD/spec/fixtures/tagging_spec.rb:9:in #{q}block (2 levels) in <top (required)>'
31+
CWD/spec/fixtures/tagging_spec.rb:3:in #{q}<top (required)>'
3132
3233
2)
3334
Tag#me érròrs in unicode FAILED
3435
Expected 1 == 2
3536
to be truthy but was false
36-
CWD/spec/fixtures/tagging_spec.rb:13:in `block (2 levels) in <top (required)>'
37-
CWD/spec/fixtures/tagging_spec.rb:3:in `<top (required)>'
37+
CWD/spec/fixtures/tagging_spec.rb:13:in #{q}block (2 levels) in <top (required)>'
38+
CWD/spec/fixtures/tagging_spec.rb:3:in #{q}<top (required)>'
3839
3940
Finished in D.DDDDDD seconds
4041

spec/mspec/spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ def ensure_mspec_method(method)
6666
include MSpecMatchers
6767
public :raise_error
6868
}.new
69+
70+
BACKTRACE_QUOTE = RUBY_VERSION >= "3.4" ? "'" : "`"

spec/ruby/.rubocop_todo.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ Lint/LiteralInInterpolation:
6363
- 'language/string_spec.rb'
6464
- 'language/symbol_spec.rb'
6565
- 'language/undef_spec.rb'
66-
- 'library/net/ftp/connect_spec.rb'
6766

6867
# Offense count: 8
6968
# Cop supports --auto-correct.
Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,93 @@
11
require_relative '../spec_helper'
22

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

9-
out.should == <<-MSG
10+
out.should == <<-MSG
1011
top
1112
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
1213
\tfrom /fixtures/backtrace.rb:6:in `b'
1314
\tfrom /fixtures/backtrace.rb:10:in `c'
1415
\t ... 2 levels...
15-
MSG
16-
end
16+
MSG
17+
end
1718

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

23-
out.should == <<-MSG
24+
out.should == <<-MSG
2425
full_message
2526
/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
2627
\tfrom /fixtures/backtrace.rb:6:in `b'
2728
\tfrom /fixtures/backtrace.rb:10:in `c'
2829
\t ... 2 levels...
29-
MSG
30-
end
30+
MSG
31+
end
3132

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

37-
out.should == <<-MSG
38+
out.should == <<-MSG
3839
backtrace
3940
/fixtures/backtrace.rb:2:in `a'
4041
/fixtures/backtrace.rb:6:in `b'
4142
/fixtures/backtrace.rb:10:in `c'
4243
/fixtures/backtrace.rb:14:in `d'
4344
/fixtures/backtrace.rb:29:in `<main>'
44-
MSG
45+
MSG
46+
end
47+
end
48+
49+
ruby_version_is "3.4" do
50+
it "limits top-level backtraces to a given number of entries" do
51+
file = fixture(__FILE__ , "backtrace.rb")
52+
out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
53+
out = out.gsub(__dir__, '')
54+
55+
out.should == <<-MSG
56+
top
57+
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
58+
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
59+
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
60+
\t ... 2 levels...
61+
MSG
62+
end
63+
64+
it "affects Exception#full_message" do
65+
file = fixture(__FILE__ , "backtrace.rb")
66+
out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
67+
out = out.gsub(__dir__, '')
68+
69+
out.should == <<-MSG
70+
full_message
71+
/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
72+
\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
73+
\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
74+
\t ... 2 levels...
75+
MSG
76+
end
77+
78+
it "does not affect Exception#backtrace" do
79+
file = fixture(__FILE__ , "backtrace.rb")
80+
out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
81+
out = out.gsub(__dir__, '')
82+
83+
out.should == <<-MSG
84+
backtrace
85+
/fixtures/backtrace.rb:2:in 'Object#a'
86+
/fixtures/backtrace.rb:6:in 'Object#b'
87+
/fixtures/backtrace.rb:10:in 'Object#c'
88+
/fixtures/backtrace.rb:14:in 'Object#d'
89+
/fixtures/backtrace.rb:29:in '<main>'
90+
MSG
91+
end
4592
end
4693
end

spec/ruby/core/basicobject/singleton_method_added_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class << self
9494
-> {
9595
def self.foo
9696
end
97-
}.should raise_error(NoMethodError, /undefined method `singleton_method_added' for/)
97+
}.should raise_error(NoMethodError, /undefined method [`']singleton_method_added' for/)
9898
end
9999
end
100100

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

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

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

121121
it "calls #method_missing" do

spec/ruby/core/binding/clone_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44

55
describe "Binding#clone" do
66
it_behaves_like :binding_clone, :clone
7+
8+
it "preserves frozen status" do
9+
bind = binding.freeze
10+
bind.frozen?.should == true
11+
bind.clone.frozen?.should == true
12+
end
713
end

spec/ruby/core/binding/dup_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@
44

55
describe "Binding#dup" do
66
it_behaves_like :binding_clone, :dup
7+
8+
it "resets frozen status" do
9+
bind = binding.freeze
10+
bind.frozen?.should == true
11+
bind.dup.frozen?.should == false
12+
end
713
end

spec/ruby/core/binding/shared/clone.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,26 @@
3131
b2.local_variable_defined?(:x).should == false
3232
end
3333
end
34+
35+
ruby_version_is "3.4" do
36+
it "copies instance variables" do
37+
@b1.instance_variable_set(:@ivar, 1)
38+
cl = @b1.send(@method)
39+
cl.instance_variables.should == [:@ivar]
40+
end
41+
42+
it "copies the finalizer" do
43+
code = <<-RUBY
44+
obj = binding
45+
46+
ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
47+
48+
obj.clone
49+
50+
exit 0
51+
RUBY
52+
53+
ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
54+
end
55+
end
3456
end

spec/ruby/core/class/attached_object_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
end
2424

2525
it "raises TypeError for special singleton classes" do
26-
-> { nil.singleton_class.attached_object }.should raise_error(TypeError, /`NilClass' is not a singleton class/)
27-
-> { true.singleton_class.attached_object }.should raise_error(TypeError, /`TrueClass' is not a singleton class/)
28-
-> { false.singleton_class.attached_object }.should raise_error(TypeError, /`FalseClass' is not a singleton class/)
26+
-> { nil.singleton_class.attached_object }.should raise_error(TypeError, /[`']NilClass' is not a singleton class/)
27+
-> { true.singleton_class.attached_object }.should raise_error(TypeError, /[`']TrueClass' is not a singleton class/)
28+
-> { false.singleton_class.attached_object }.should raise_error(TypeError, /[`']FalseClass' is not a singleton class/)
2929
end
3030
end
3131
end

spec/ruby/core/enumerator/product/each_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def object2.each_entry
3434
it "raises a NoMethodError if the object doesn't respond to #each_entry" do
3535
-> {
3636
Enumerator::Product.new(Object.new).each {}
37-
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
37+
}.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
3838
end
3939

4040
it "returns enumerator if not given a block" do

spec/ruby/core/enumerator/product_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def object.each_entry
6969
it "raises NoMethodError when argument doesn't respond to #each_entry" do
7070
-> {
7171
Enumerator.product(Object.new).to_a
72-
}.should raise_error(NoMethodError, /undefined method `each_entry' for/)
72+
}.should raise_error(NoMethodError, /undefined method [`']each_entry' for/)
7373
end
7474

7575
it "calls #each_entry lazily" do

spec/ruby/core/exception/backtrace_spec.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
end
2828

2929
it "includes the name of the method from where self raised in the first element" do
30-
@backtrace.first.should =~ /in `backtrace'/
30+
@backtrace.first.should =~ /in [`'](?:ExceptionSpecs::Backtrace\.)?backtrace'/
3131
end
3232

3333
it "includes the filename of the location immediately prior to where self raised in the second element" do
@@ -38,12 +38,25 @@
3838
@backtrace[1].should =~ /:6(:in )?/
3939
end
4040

41-
it "contains lines of the same format for each prior position in the stack" do
42-
@backtrace[2..-1].each do |line|
43-
# This regexp is deliberately imprecise to account for the need to abstract out
44-
# the paths of the included mspec files and the desire to avoid specifying in any
45-
# detail what the in `...' portion looks like.
46-
line.should =~ /^.+:\d+:in `[^`]+'$/
41+
ruby_version_is ""..."3.4" do
42+
it "contains lines of the same format for each prior position in the stack" do
43+
@backtrace[2..-1].each do |line|
44+
# This regexp is deliberately imprecise to account for the need to abstract out
45+
# the paths of the included mspec files and the desire to avoid specifying in any
46+
# detail what the in `...' portion looks like.
47+
line.should =~ /^.+:\d+:in `[^`]+'$/
48+
end
49+
end
50+
end
51+
52+
ruby_version_is "3.4" do
53+
it "contains lines of the same format for each prior position in the stack" do
54+
@backtrace[2..-1].each do |line|
55+
# This regexp is deliberately imprecise to account for the need to abstract out
56+
# the paths of the included mspec files and the desire to avoid specifying in any
57+
# detail what the in '...' portion looks like.
58+
line.should =~ /^.+:\d+:in '[^`]+'$/
59+
end
4760
end
4861
end
4962

spec/ruby/core/exception/full_message_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
e = RuntimeError.new("Some runtime error")
4343
e.backtrace.should == nil
4444
full_message = e.full_message(highlight: false, order: :top).lines
45-
full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in `")
45+
full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in ")
4646
full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n")
4747
end
4848

@@ -94,7 +94,7 @@
9494
line = __LINE__; raise "first line\nsecond line"
9595
rescue => e
9696
full_message = e.full_message(highlight: false, order: :top).lines
97-
full_message[0].should.start_with?("#{__FILE__}:#{line}:in `")
97+
full_message[0].should.start_with?("#{__FILE__}:#{line}:in ")
9898
full_message[0].should.end_with?(": first line (RuntimeError)\n")
9999
full_message[1].should == "second line\n"
100100
end
@@ -105,7 +105,7 @@
105105
line = __LINE__; raise "first line\nsecond line\nthird line"
106106
rescue => e
107107
full_message = e.full_message(highlight: true, order: :top).lines
108-
full_message[0].should.start_with?("#{__FILE__}:#{line}:in `")
108+
full_message[0].should.start_with?("#{__FILE__}:#{line}:in ")
109109
full_message[0].should.end_with?(": \e[1mfirst line (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n")
110110
full_message[1].should == "\e[1msecond line\e[m\n"
111111
full_message[2].should == "\e[1mthird line\e[m\n"

spec/ruby/core/exception/interrupt_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
err = IO.popen([*ruby_exe, '-e', 'Process.kill :INT, Process.pid; sleep'], err: [:child, :out], &:read)
5555
$?.termsig.should == Signal.list.fetch('INT')
5656
err.should.include? ': Interrupt'
57-
err.should.include? "from -e:1:in `<main>'"
57+
err.should =~ /from -e:1:in [`']<main>'/
5858
end
5959
end
6060
end

0 commit comments

Comments
 (0)