Skip to content

Commit 63ac861

Browse files
committed
[GR-14806] Update specs.
PullRequest: truffleruby/1728
2 parents aecb8d3 + bbeb0a4 commit 63ac861

File tree

29 files changed

+375
-71
lines changed

29 files changed

+375
-71
lines changed

lib/truffle/timeout.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
#--
23
# = timeout.rb
34
#
@@ -47,10 +48,11 @@ class Error < RuntimeError
4748
# Represents +thr+ asking for it to be timeout at in +secs+
4849
# seconds. At timeout, raise +exc+.
4950
class TimeoutRequest
50-
def initialize(secs, thr, exc)
51+
def initialize(secs, thr, exc, message)
5152
@left = secs
5253
@thread = thr
5354
@exception = exc
55+
@message = message
5456
end
5557

5658
attr_reader :thread, :left
@@ -65,7 +67,7 @@ def elapsed(time)
6567
# Raise @exception if @thread.
6668
def cancel
6769
if @thread and @thread.alive?
68-
@thread.raise @exception, 'execution expired'
70+
@thread.raise @exception, @message
6971
end
7072

7173
@left = 0
@@ -126,8 +128,8 @@ def self.ensure_timeout_thread_running
126128
end
127129
end
128130

129-
def self.add_timeout(time, exc)
130-
r = TimeoutRequest.new(time, Thread.current, exc)
131+
def self.add_timeout(time, exc, message)
132+
r = TimeoutRequest.new(time, Thread.current, exc, message)
131133
@chan << r
132134
ensure_timeout_thread_running
133135
r
@@ -136,7 +138,7 @@ def self.add_timeout(time, exc)
136138

137139
if Truffle::Boot.single_threaded?
138140

139-
def timeout(sec, exception=Error)
141+
def timeout(sec, exception = Error, message = nil)
140142
Truffle::Debug.log_warning 'threads are disabled, so timeout is being ignored'
141143
yield sec
142144
end
@@ -152,12 +154,11 @@ def timeout(sec, exception=Error)
152154
# Timeout' into your classes so they have a #timeout method, as well as a
153155
# module method, so you can call it directly as Timeout.timeout().
154156

155-
def timeout(sec, exception=Error)
157+
def timeout(sec, exception = Error, message = nil)
156158
return yield if sec == nil or sec.zero?
157-
raise ThreadError, 'timeout within critical session' if Thread.respond_to?(:critical) && Thread.critical
158-
159-
req = Timeout.add_timeout sec, exception
160159

160+
message ||= 'execution expired'
161+
req = Timeout.add_timeout sec, exception, message
161162
begin
162163
yield sec
163164
ensure

spec/mspec/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[![Build Status](https://travis-ci.org/ruby/mspec.svg?branch=master)](https://travis-ci.org/ruby/mspec)
2-
31
## Overview
42

53
MSpec is a specialized framework that is syntax-compatible with RSpec 2 for

spec/mspec/tool/sync/sync-rubyspec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
BRIGHT_YELLOW = "\e[33;1m"
3636
RESET = "\e[0m"
3737

38+
# git filter-branch --subdirectory-filter works fine for our use case
39+
ENV['FILTER_BRANCH_SQUELCH_WARNING'] = '1'
40+
3841
class RubyImplementation
3942
attr_reader :name
4043

spec/ruby/.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Layout/TrailingEmptyLines:
1515
Exclude:
1616
- library/coverage/fixtures/some_class.rb
1717

18+
Layout/SpaceInLambdaLiteral:
19+
Enabled: true
20+
EnforcedStyle: require_space
21+
1822
Lint:
1923
Enabled: true
2024

spec/ruby/core/env/delete_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
ScratchPad.recorded.should == "foo"
3131
end
3232

33+
ruby_version_is "2.8" do
34+
it "returns the result of given block if the named environment variable does not exist" do
35+
ENV.delete("foo")
36+
ENV.delete("foo") { |name| "bar" }.should == "bar"
37+
end
38+
end
39+
3340
it "does not evaluate the block if the environment variable exists" do
3441
ENV["foo"] = "bar"
3542
ENV.delete("foo") { |name| fail "Should not happen" }

spec/ruby/core/exception/no_method_error_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ def inspect
103103
message.should include test_class.inspect
104104
end
105105
end
106+
107+
ruby_version_is "2.8" do
108+
it "uses #name to display the receiver if it is a class or a module" do
109+
klass = Class.new { def self.name; "MyClass"; end }
110+
begin
111+
klass.foo
112+
rescue NoMethodError => error
113+
error.message.lines.first.should == "undefined method `foo' for MyClass:Class"
114+
end
115+
116+
mod = Module.new { def self.name; "MyModule"; end }
117+
begin
118+
mod.foo
119+
rescue NoMethodError => error
120+
error.message.lines.first.should == "undefined method `foo' for MyModule:Module"
121+
end
122+
end
123+
end
106124
end
107125

108126
describe "NoMethodError#dup" do

spec/ruby/core/io/ioctl_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
end
2121
end
2222

23-
it "raises an Errno error when ioctl fails" do
23+
it "raises a system call error when ioctl fails" do
2424
File.open(__FILE__, 'r') do |f|
2525
-> {
2626
# TIOCGWINSZ in /usr/include/asm-generic/ioctls.h
2727
f.ioctl 0x5413, nil
28-
}.should raise_error(Errno::ENOTTY)
28+
}.should raise_error(SystemCallError)
2929
end
3030
end
3131
end

spec/ruby/core/kernel/fixtures/classes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class ForwardBlockWithZSuper
350350

351351
module Ampersand
352352
def lambda(&block)
353-
super(&block)
353+
suppress_warning {super(&block)}
354354
end
355355
end
356356

spec/ruby/core/kernel/lambda_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
it "returns the passed Proc if given an existing Proc" do
3535
some_proc = proc {}
36-
l = lambda(&some_proc)
36+
l = suppress_warning {lambda(&some_proc)}
3737
l.should equal(some_proc)
3838
l.lambda?.should be_false
3939
end
@@ -55,7 +55,7 @@
5555

5656
it "does not create lambda-style Procs when captured with #method" do
5757
kernel_lambda = method(:lambda)
58-
l = kernel_lambda.call { 42 }
58+
l = suppress_warning {kernel_lambda.call { 42 }}
5959
l.lambda?.should be_false
6060
l.call(:extra).should == 42
6161
end

spec/ruby/core/kernel/proc_spec.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,31 @@ def test
3636
end
3737

3838
describe "Kernel#proc" do
39+
def some_method
40+
proc
41+
end
42+
3943
ruby_version_is ""..."2.7" do
4044
it "uses the implicit block from an enclosing method" do
41-
def some_method
42-
proc
43-
end
44-
4545
prc = some_method { "hello" }
4646

4747
prc.call.should == "hello"
4848
end
4949
end
5050

51-
ruby_version_is "2.7" do
51+
ruby_version_is "2.7"..."2.8" do
5252
it "can be created when called with no block" do
53-
def some_method
54-
proc
55-
end
56-
5753
-> {
5854
some_method { "hello" }
5955
}.should complain(/Capturing the given block using Kernel#proc is deprecated/)
6056
end
6157
end
58+
59+
ruby_version_is "2.8" do
60+
it "raises an ArgumentError when passed no block" do
61+
-> {
62+
some_method { "hello" }
63+
}.should raise_error(ArgumentError, 'tried to create Proc object without a block')
64+
end
65+
end
6266
end

0 commit comments

Comments
 (0)