Skip to content

Commit

Permalink
Merge pull request #470 in G/truffleruby from update-specs to master
Browse files Browse the repository at this point in the history
* commit 'b28603dbf30e5649279eb282693b7a12486c5056':
  Add tags for new failing specs
  Update to ruby/spec@cdd6ff7
  • Loading branch information
nirvdrum committed Nov 27, 2018
2 parents 9309ff6 + b28603d commit c4cda96
Show file tree
Hide file tree
Showing 61 changed files with 423 additions and 315 deletions.
4 changes: 2 additions & 2 deletions spec/ruby/README.md
Expand Up @@ -88,9 +88,9 @@ In similar fashion, the following commands run the respective specs:
$ ../mspec/bin/mspec :library
$ ../mspec/bin/mspec :capi

### Contributing
### Contributing and Writing Specs

See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md).
See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) for documentation about contributing and writing specs (guards, matchers, etc).

### Socket specs from rubysl-socket

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/appveyor.yml
@@ -1,6 +1,6 @@
---
version: "{build}"
clone_depth: 5
clone_depth: 100
init:
# To avoid duplicated executables in PATH, see https://github.com/ruby/spec/pull/468
- set PATH=C:\Ruby%ruby_version%\bin;C:\Program Files\7-Zip;C:\Program Files\AppVeyor\BuildAgent;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Program Files;C:\Windows
Expand Down
15 changes: 15 additions & 0 deletions spec/ruby/core/hash/shift_spec.rb
Expand Up @@ -61,4 +61,19 @@ def h.default(key)
lambda { HashSpecs.frozen_hash.shift }.should raise_error(frozen_error_class)
lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(frozen_error_class)
end

it "works when the hash is at capacity" do
# We try a wide range of sizes in hopes that this will cover all implementationss base Hash size.
results = []
1.upto(100) do |n|
h = {}
n.times do |i|
h[i] = i
end
h.shift
results << h.size
end

results.should == 0.upto(99).to_a
end
end
11 changes: 11 additions & 0 deletions spec/ruby/core/integer/gcd_spec.rb
Expand Up @@ -43,6 +43,17 @@
bignum.gcd(99).should == 99
end

it "doesn't cause an integer overflow" do
[2 ** (1.size * 8 - 2), 0x8000000000000000].each do |max|
[max - 1, max, max + 1].each do |num|
num.gcd(num).should == num
(-num).gcd(num).should == num
(-num).gcd(-num).should == num
num.gcd(-num).should == num
end
end
end

it "raises an ArgumentError if not given an argument" do
lambda { 12.gcd }.should raise_error(ArgumentError)
end
Expand Down
16 changes: 10 additions & 6 deletions spec/ruby/core/io/initialize_spec.rb
Expand Up @@ -13,12 +13,16 @@
rm_r @name
end

it "reassociates the IO instance with the new descriptor when passed a Fixnum" do
fd = new_fd @name, "r:utf-8"
@io.send :initialize, fd, 'r'
@io.fileno.should == fd
# initialize has closed the old descriptor
lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
# http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1469621
# http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1454818
without_feature :mjit do # with RubyVM::MJIT.enabled?, this randomly fails for now
it "reassociates the IO instance with the new descriptor when passed a Fixnum" do
fd = new_fd @name, "r:utf-8"
@io.send :initialize, fd, 'r'
@io.fileno.should == fd
# initialize has closed the old descriptor
lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
end
end

it "calls #to_int to coerce the object passed as an fd" do
Expand Down
1 change: 0 additions & 1 deletion spec/ruby/core/io/read_nonblock_spec.rb
Expand Up @@ -44,7 +44,6 @@
platform_is_not :windows do
it 'sets the IO in nonblock mode' do
require 'io/nonblock'
@read.nonblock?.should == false
@write.write "abc"
@read.read_nonblock(1).should == "a"
@read.nonblock?.should == true
Expand Down
20 changes: 12 additions & 8 deletions spec/ruby/core/io/reopen_spec.rb
Expand Up @@ -145,17 +145,21 @@
File.read(@other_name).should == "new data"
end

it "closes the file descriptor obtained by opening the new file" do
@io = new_io @name, "w"
# http://ci.rvm.jp/results/trunk-mjit@silicon-docker/1461550
# http://ci.rvm.jp/results/trunk-mjit-wait@silicon-docker/1448152
without_feature :mjit do # with RubyVM::MJIT.enabled?, this randomly fails for now
it "closes the file descriptor obtained by opening the new file" do
@io = new_io @name, "w"

@other_io = File.open @other_name, "w"
max = @other_io.fileno
@other_io.close
@other_io = File.open @other_name, "w"
max = @other_io.fileno
@other_io.close

@io.reopen @other_name
@io.reopen @other_name

@other_io = File.open @other_name, "w"
@other_io.fileno.should == max
@other_io = File.open @other_name, "w"
@other_io.fileno.should == max
end
end

it "creates the file if it doesn't exist if the IO is opened in write mode" do
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/io/syswrite_spec.rb
Expand Up @@ -55,7 +55,7 @@
r, w = IO.pipe
begin
w.nonblock = true
larger_than_pipe_capacity = 100 * 1024
larger_than_pipe_capacity = 2 * 1024 * 1024
written = w.syswrite("a"*larger_than_pipe_capacity)
written.should > 0
written.should < larger_than_pipe_capacity
Expand Down
22 changes: 19 additions & 3 deletions spec/ruby/core/io/ungetbyte_spec.rb
Expand Up @@ -36,9 +36,25 @@
@io.getbyte.should == 97
end

it "puts back one byte for an Integer argument" do
@io.ungetbyte(4095).should be_nil
@io.getbyte.should == 255
ruby_version_is ''...'2.6' do
it "puts back one byte for a Fixnum argument..." do
@io.ungetbyte(4095).should be_nil
@io.getbyte.should == 255
end

it "... but not for Bignum argument (eh?)" do
lambda {
@io.ungetbyte(0x4f7574206f6620636861722072616e6765)
}.should raise_error(TypeError)
end
end

ruby_version_is '2.6' do
it "is an RangeError if the integer is not in 8bit" do
for i in [4095, 0x4f7574206f6620636861722072616e6765] do
lambda { @io.ungetbyte(i) }.should raise_error(RangeError)
end
end
end

it "raises an IOError if the IO is closed" do
Expand Down
1 change: 0 additions & 1 deletion spec/ruby/core/io/write_nonblock_spec.rb
Expand Up @@ -76,7 +76,6 @@
platform_is_not :windows do
it 'sets the IO in nonblock mode' do
require 'io/nonblock'
@write.nonblock?.should == false
@write.write_nonblock('a')
@write.nonblock?.should == true
end
Expand Down
61 changes: 50 additions & 11 deletions spec/ruby/core/module/refine_spec.rb
Expand Up @@ -425,6 +425,24 @@ def to_s
end
end

ruby_version_is "2.6" do
it "is honored by Kernel#public_send" do
refinement = Module.new do
refine ModuleSpecs::ClassWithFoo do
def foo; "foo from refinement"; end
end
end

result = nil
Module.new do
using refinement
result = ModuleSpecs::ClassWithFoo.new.public_send :foo
end

result.should == "foo from refinement"
end
end

ruby_version_is "" ... "2.5" do
it "is not honored by string interpolation" do
refinement = Module.new do
Expand Down Expand Up @@ -506,21 +524,42 @@ def foo; end
}.should raise_error(NameError, /undefined method `foo'/)
end

it "is not honored by Kernel#respond_to?" do
klass = Class.new
refinement = Module.new do
refine klass do
def foo; end
ruby_version_is "" ... "2.6" do
it "is not honored by Kernel#respond_to?" do
klass = Class.new
refinement = Module.new do
refine klass do
def foo; end
end
end
end

result = nil
Module.new do
using refinement
result = klass.new.respond_to?(:foo)
result = nil
Module.new do
using refinement
result = klass.new.respond_to?(:foo)
end

result.should == false
end
end

result.should == false
ruby_version_is "2.6" do
it "is honored by Kernel#respond_to?" do
klass = Class.new
refinement = Module.new do
refine klass do
def foo; end
end
end

result = nil
Module.new do
using refinement
result = klass.new.respond_to?(:foo)
end

result.should == true
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/mutex/synchronize_spec.rb
Expand Up @@ -40,7 +40,7 @@
m = Mutex.new
q1 = Queue.new
q2 = Queue.new

t = Thread.new {
m.synchronize {
q1.push :ready
Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/process/clock_gettime_spec.rb
Expand Up @@ -4,7 +4,7 @@
describe 'time units' do
it 'handles a fixed set of time units' do
[:nanosecond, :microsecond, :millisecond, :second].each do |unit|
Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should be_an_instance_of(Integer)
Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should be_kind_of(Integer)
end

[:float_microsecond, :float_millisecond, :float_second].each do |unit|
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/signal/list_spec.rb
Expand Up @@ -61,4 +61,8 @@
it "includes the EXIT key with a value of zero" do
Signal.list["EXIT"].should == 0
end

it "includes the KILL key with a value of nine" do
Signal.list["KILL"].should == 9
end
end
17 changes: 17 additions & 0 deletions spec/ruby/core/struct/new_spec.rb
Expand Up @@ -130,6 +130,17 @@ def platform
it "fails with too many arguments" do
lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
end

it "passes a hash as a normal argument" do
type = Struct.new(:args)

obj = type.new(keyword: :arg)
obj2 = type.new(*[{keyword: :arg}])

obj.should == obj2
obj.args.should == {keyword: :arg}
obj2.args.should == {keyword: :arg}
end
end

ruby_version_is "2.5" do
Expand Down Expand Up @@ -163,6 +174,12 @@ def platform
@struct_with_kwa.new("elefant", 4)
}.should raise_error(ArgumentError, /wrong number of arguments/)
end

it "raises ArgumentError when passed a single non-hash argument" do
-> {
@struct_with_kwa.new("elefant")
}.should raise_error(ArgumentError, /wrong number of arguments/)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/thread/exclusive_spec.rb
Expand Up @@ -18,7 +18,7 @@
m = Mutex.new
q1 = Queue.new
q2 = Queue.new

t = Thread.new {
Thread.exclusive {
q1.push :ready
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/thread/shared/exit.rb
Expand Up @@ -3,6 +3,10 @@
ScratchPad.clear
end

# This spec randomly kills mspec worker like: https://ci.appveyor.com/project/ruby/ruby/builds/19390874/job/wv1bsm8skd4e1pxl
# TODO: Investigate the cause or at least print helpful logs, and remove this `platform_is_not` guard.
platform_is_not :mingw do

it "kills sleeping thread" do
sleeping_thread = Thread.new do
sleep
Expand Down Expand Up @@ -173,4 +177,6 @@
t.join.should == t
end
end

end # platform_is_not :mingw
end
6 changes: 1 addition & 5 deletions spec/ruby/core/thread/terminate_spec.rb
Expand Up @@ -3,9 +3,5 @@
require_relative 'shared/exit'

describe "Thread#terminate" do
# This spec randomly kills mspec worker like: https://ci.appveyor.com/project/ruby/ruby/builds/19390874/job/wv1bsm8skd4e1pxl
# TODO: Investigate the cause or at least print helpful logs, and remove this `platform_is_not` guard.
platform_is_not :mingw do
it_behaves_like :thread_exit, :terminate
end
it_behaves_like :thread_exit, :terminate
end
14 changes: 14 additions & 0 deletions spec/ruby/core/time/fixtures/classes.rb
Expand Up @@ -9,4 +9,18 @@ class << self
end
end

Timezone = Struct.new(:name, :abbr, :offset)
class Timezone
def utc_offset(t = nil)
offset
end

def local_to_utc(t)
t - utc_offset(t)
end

def utc_to_local(t)
t + utc_offset(t)
end
end
end
3 changes: 1 addition & 2 deletions spec/ruby/core/time/new_spec.rb
Expand Up @@ -117,8 +117,7 @@
ruby_version_is "2.6" do
describe "Time.new with a timezone argument" do
it "returns a Time correspoinding to UTC time returned by local_to_utc" do
zone = mock('timezone')
zone.should_receive(:local_to_utc).and_return(Time::TM.new(2000, 1, 1, 6, 30, 0))
zone = TimeSpecs::Timezone.new("Asia/Colombo", "MMT", (5*3600+30*60))
t = Time.new(2000, 1, 1, 12, 0, 0, zone)
t.to_a[0, 6].should == [0, 0, 12, 1, 1, 2000]
t.utc_offset.should == 19800
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/time/nsec_spec.rb
Expand Up @@ -24,4 +24,8 @@
it "returns the nanoseconds part of a Time constructed with an Rational number of microseconds" do
Time.at(0, Rational(99, 10)).nsec.should == 9900
end

it "returns a positive value for dates before the epoch" do
Time.utc(1969, 11, 12, 13, 18, 57, 404240).nsec.should == 404240000
end
end
4 changes: 4 additions & 0 deletions spec/ruby/core/time/shared/time_params.rb
Expand Up @@ -230,6 +230,10 @@
t.usec.should == 123
end

it "raises an ArgumentError for out of range microsecond" do
lambda { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should raise_error(ArgumentError)
end

it "handles fractional microseconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 1.75)
t.usec.should == 1
Expand Down
4 changes: 4 additions & 0 deletions spec/ruby/core/time/usec_spec.rb
Expand Up @@ -36,4 +36,8 @@
it "returns the microseconds for time created by Time#local" do
Time.local(1,2,3,4,5,Rational(6.78)).usec.should == 780000
end

it "returns a positive value for dates before the epoch" do
Time.utc(1969, 11, 12, 13, 18, 57, 404240).usec.should == 404240
end
end

0 comments on commit c4cda96

Please sign in to comment.