Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to ruby/spec@07164da
  • Loading branch information
eregon committed Jul 27, 2020
1 parent 7429841 commit 126fd5f
Show file tree
Hide file tree
Showing 38 changed files with 733 additions and 44 deletions.
1 change: 1 addition & 0 deletions spec/ruby/.mspec.constants
Expand Up @@ -152,6 +152,7 @@ RegexpSpecsSubclassTwo
Reline
RescueInClassExample
Resolv
Ripper
SHA1Constants
SHA256Constants
SHA384Constants
Expand Down
1 change: 1 addition & 0 deletions spec/ruby/.rubocop.yml
Expand Up @@ -92,6 +92,7 @@ Lint/UnreachableCode:
Exclude:
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/kernel/catch_spec.rb'
- 'core/kernel/raise_spec.rb'
- 'core/kernel/throw_spec.rb'
- 'language/break_spec.rb'
- 'language/fixtures/break.rb'
Expand Down
2 changes: 2 additions & 0 deletions spec/ruby/.rubocop_todo.yml
Expand Up @@ -59,6 +59,7 @@ Lint/InheritException:
- 'core/enumerator/lazy/fixtures/classes.rb'
- 'core/exception/fixtures/common.rb'
- 'core/module/fixtures/autoload_ex1.rb'
- 'shared/kernel/raise.rb'

# Offense count: 72
# Cop supports --auto-correct.
Expand Down Expand Up @@ -115,6 +116,7 @@ Lint/RescueException:
- 'core/exception/cause_spec.rb'
- 'core/exception/no_method_error_spec.rb'
- 'core/kernel/fixtures/autoload_frozen.rb'
- 'core/kernel/raise_spec.rb'
- 'core/module/autoload_spec.rb'
- 'core/mutex/sleep_spec.rb'
- 'core/thread/abort_on_exception_spec.rb'
Expand Down
4 changes: 2 additions & 2 deletions spec/ruby/CONTRIBUTING.md
Expand Up @@ -136,11 +136,11 @@ Here is a list of the most commonly-used guards:
#### Version guards

```ruby
ruby_version_is ""..."2.6 do
ruby_version_is ""..."2.6" do
# Specs for RUBY_VERSION < 2.6
end

ruby_version_is "2.6 do
ruby_version_is "2.6" do
# Specs for RUBY_VERSION >= 2.6
end
```
Expand Down
19 changes: 17 additions & 2 deletions spec/ruby/command_line/dash_r_spec.rb
Expand Up @@ -7,7 +7,22 @@
end

it "requires the specified file" do
result = ruby_exe(@script, options: "-r #{@test_file}")
result.should include(@test_file + ".rb")
out = ruby_exe(@script, options: "-r #{@test_file}")
out.should include("REQUIRED")
out.should include(@test_file + ".rb")
end

it "requires the file before parsing the main script" do
out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), options: "-r #{@test_file}", args: "2>&1")
$?.should_not.success?
out.should include("REQUIRED")
out.should include("syntax error")
end

it "does not require the file if the main script file does not exist" do
out = `#{ruby_exe.to_a.join(' ')} -r #{@test_file} #{fixture(__FILE__, "does_not_exist.rb")} 2>&1`
$?.should_not.success?
out.should_not.include?("REQUIRED")
out.should.include?("No such file or directory")
end
end
2 changes: 1 addition & 1 deletion spec/ruby/command_line/fixtures/test_file.rb
@@ -1 +1 @@
"test file"
puts "REQUIRED"
3 changes: 2 additions & 1 deletion spec/ruby/core/array/fill_spec.rb
Expand Up @@ -207,8 +207,9 @@

not_supported_on :opal do
it "raises an ArgumentError or RangeError for too-large sizes" do
error_types = [RangeError, ArgumentError]
arr = [1, 2, 3]
-> { arr.fill(10, 1, fixnum_max) }.should raise_error(ArgumentError)
-> { arr.fill(10, 1, fixnum_max) }.should raise_error { |err| error_types.should include(err.class) }
-> { arr.fill(10, 1, bignum_value) }.should raise_error(RangeError)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/exception/backtrace_spec.rb
Expand Up @@ -43,7 +43,7 @@
# This regexp is deliberately imprecise to account for the need to abstract out
# the paths of the included mspec files and the desire to avoid specifying in any
# detail what the in `...' portion looks like.
line.should =~ /^[^ ]+\:\d+(:in `[^`]+')?$/
line.should =~ /^.+:\d+:in `[^`]+'$/
end
end

Expand Down
7 changes: 7 additions & 0 deletions spec/ruby/core/kernel/__dir___spec.rb
Expand Up @@ -5,6 +5,13 @@
__dir__.should == File.realpath(File.dirname(__FILE__))
end

it "returns the expanded path of the directory when used in the main script" do
fixtures_dir = File.dirname(fixture(__FILE__, '__dir__.rb'))
Dir.chdir(fixtures_dir) do
ruby_exe("__dir__.rb").should == "__dir__.rb\n#{fixtures_dir}\n"
end
end

context "when used in eval with a given filename" do
it "returns File.dirname(filename)" do
eval("__dir__", nil, "foo.rb").should == "."
Expand Down
31 changes: 28 additions & 3 deletions spec/ruby/core/kernel/at_exit_spec.rb
Expand Up @@ -23,7 +23,7 @@
it "gives access to the last raised exception" do
code = <<-EOC
at_exit do
puts "The exception matches: \#{$! == $exception}"
puts "The exception matches: \#{$! == $exception} (message=\#{$!.message})"
end
begin
Expand All @@ -33,10 +33,35 @@
end
EOC

result = ruby_exe(code, args: "2>&1", escape: true)
result.should =~ /The exception matches: true/
result = ruby_exe(code, args: "2>&1")
result.lines.should.include?("The exception matches: true (message=foo)\n")
end

it "both exceptions in at_exit and in the main script are printed" do
result = ruby_exe('at_exit { raise "at_exit_error" }; raise "main_script_error"', args: "2>&1")
result.should.include?('at_exit_error (RuntimeError)')
result.should.include?('main_script_error (RuntimeError)')
end

it "decides the exit status if both at_exit and the main script raise SystemExit" do
ruby_exe('at_exit { exit 43 }; exit 42', args: "2>&1")
$?.exitstatus.should == 43
end

it "runs all at_exit even if some raise exceptions" do
code = 'at_exit { STDERR.puts "last" }; at_exit { exit 43 }; at_exit { STDERR.puts "first" }; exit 42'
result = ruby_exe(code, args: "2>&1")
result.should == "first\nlast\n"
$?.exitstatus.should == 43
end

it "runs at_exit handlers even if the main script fails to parse" do
script = fixture(__FILE__, "at_exit.rb")
result = ruby_exe('{', options: "-r#{script}", args: "2>&1")
$?.should_not.success?
result.should.include?("at_exit ran\n")
result.should.include?("syntax error")
end
end

describe "Kernel#at_exit" do
Expand Down
2 changes: 2 additions & 0 deletions spec/ruby/core/kernel/fixtures/__dir__.rb
@@ -0,0 +1,2 @@
puts __FILE__
puts __dir__
3 changes: 3 additions & 0 deletions spec/ruby/core/kernel/fixtures/at_exit.rb
@@ -0,0 +1,3 @@
at_exit do
STDERR.puts "at_exit ran"
end
1 change: 1 addition & 0 deletions spec/ruby/core/kernel/fixtures/warn_require.rb
@@ -0,0 +1 @@
warn 'warn-require-warning', uplevel: 1
2 changes: 2 additions & 0 deletions spec/ruby/core/kernel/fixtures/warn_require_caller.rb
@@ -0,0 +1,2 @@
# Use a different line than just 1
require "#{__dir__}/warn_require"
21 changes: 21 additions & 0 deletions spec/ruby/core/kernel/raise_spec.rb
Expand Up @@ -6,6 +6,27 @@
it "is a private method" do
Kernel.should have_private_instance_method(:raise)
end

it "re-raises the previously rescued exception if no exception is specified" do
ScratchPad.record nil

-> do
begin
raise Exception, "outer"
ScratchPad.record :no_abort
rescue Exception
begin
raise StandardError, "inner"
rescue StandardError
end

raise
ScratchPad.record :no_reraise
end
end.should raise_error(Exception, "outer")

ScratchPad.recorded.should be_nil
end
end

describe "Kernel#raise" do
Expand Down
13 changes: 13 additions & 0 deletions spec/ruby/core/kernel/warn_spec.rb
Expand Up @@ -101,6 +101,19 @@
-> { w.f4("foo", 3) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f3_call_lineno}: warning: foo|)
end

# Test both explicitly without and with RubyGems as RubyGems overrides Kernel#warn
it "shows the caller of #require and not #require itself without RubyGems" do
file = fixture(__FILE__ , "warn_require_caller.rb")
ruby_exe(file, options: "--disable-gems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
end

ruby_version_is "2.6" do
it "shows the caller of #require and not #require itself with RubyGems loaded" do
file = fixture(__FILE__ , "warn_require_caller.rb")
ruby_exe(file, options: "-rrubygems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
end
end

it "converts first arg using to_s" do
w = KernelSpecs::WarnInNestedCall.new

Expand Down
12 changes: 10 additions & 2 deletions spec/ruby/core/module/fixtures/refine.rb
Expand Up @@ -3,6 +3,10 @@ class ClassWithFoo
def foo; "foo" end
end

class ClassWithSuperFoo
def foo; [:C] end
end

module PrependedModule
def foo; "foo from prepended module"; end
end
Expand All @@ -11,7 +15,11 @@ module IncludedModule
def foo; "foo from included module"; end
end

def self.build_refined_class
Class.new(ClassWithFoo)
def self.build_refined_class(for_super: false)
if for_super
Class.new(ClassWithSuperFoo)
else
Class.new(ClassWithFoo)
end
end
end

0 comments on commit 126fd5f

Please sign in to comment.