Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh some specs after upstream update #2297

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/core/array/each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Mutating the array while it is being iterated is discouraged as it can result in confusing behavior.
# Yet a Ruby implementation must not crash in such a case, and following the simple CRuby behavior makes sense.
# CRuby simply reads the array storage and checks the size for every iteration;
# like `i = 0; while i < size; yield self[i]; end`
# like `i = 0; while i < size; yield self[i]; i += 1; end`

describe "Array#each" do
it "yields each element to the block" do
Expand Down
2 changes: 1 addition & 1 deletion spec/core/array/plus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
end

it "raises a Typeerror if the given argument can't be converted to an array" do
it "raises a TypeError if the given argument can't be converted to an array" do
-> { [1, 2, 3] + nil }.should raise_error(TypeError)
-> { [1, 2, 3] + "abc" }.should raise_error(TypeError)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/core/float/ceil_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require_relative '../../spec_helper'
require_relative '../integer/shared/integer_ceil_precision'

describe "Float#ceil" do
context "with precision" do
it_behaves_like :integer_ceil_precision, :Float
end

it "returns the smallest Integer greater than or equal to self" do
-1.2.ceil.should eql( -1)
-1.0.ceil.should eql( -1)
Expand Down
5 changes: 5 additions & 0 deletions spec/core/float/floor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
require_relative '../../spec_helper'
require_relative '../integer/shared/integer_floor_precision'

describe "Float#floor" do
context "with precision" do
it_behaves_like :integer_floor_precision, :Float
end

it "returns the largest Integer less than or equal to self" do
-1.2.floor.should eql( -2)
-1.0.floor.should eql( -1)
Expand Down
5 changes: 5 additions & 0 deletions spec/core/integer/ceil_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
require_relative '../../spec_helper'
require_relative 'shared/to_i'
require_relative 'shared/integer_rounding'
require_relative 'shared/integer_ceil_precision'

describe "Integer#ceil" do
it_behaves_like :integer_to_i, :ceil
it_behaves_like :integer_rounding_positive_precision, :ceil

context "with precision" do
it_behaves_like :integer_ceil_precision, :Integer
end

context "precision argument specified as part of the ceil method is negative" do
it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
18.ceil(-1).should eql(20)
Expand Down
12 changes: 3 additions & 9 deletions spec/core/integer/floor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
require_relative '../../spec_helper'
require_relative 'shared/to_i'
require_relative 'shared/integer_rounding'
require_relative 'shared/integer_floor_precision'

describe "Integer#floor" do
it_behaves_like :integer_to_i, :floor
it_behaves_like :integer_rounding_positive_precision, :floor

context "precision argument specified as part of the floor method is negative" do
it "returns the largest integer less than self with at least precision.abs trailing zeros" do
1832.floor(-1).should eql(1830)
1832.floor(-2).should eql(1800)
1832.floor(-3).should eql(1000)
-1832.floor(-1).should eql(-1840)
-1832.floor(-2).should eql(-1900)
-1832.floor(-3).should eql(-2000)
end
context "with precision" do
it_behaves_like :integer_floor_precision, :Integer
end
end
6 changes: 2 additions & 4 deletions spec/core/integer/round_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
(-25 * 10**70).round(-71).should eql(-30 * 10**70)
end

platform_is_not wordsize: 32 do
it "raises a RangeError when passed a big negative value" do
-> { 42.round(fixnum_min) }.should raise_error(RangeError)
end
it "raises a RangeError when passed a big negative value" do
-> { 42.round(min_long - 1) }.should raise_error(RangeError)
end

it "raises a RangeError when passed Float::INFINITY" do
Expand Down
43 changes: 43 additions & 0 deletions spec/core/integer/shared/integer_ceil_precision.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe :integer_ceil_precision, shared: true do
context "precision is zero" do
it "returns integer self" do
send(@method, 0).ceil(0).should.eql?(0)
send(@method, 123).ceil(0).should.eql?(123)
send(@method, -123).ceil(0).should.eql?(-123)
end
end

context "precision is positive" do
it "returns self" do
send(@method, 0).ceil(1).should.eql?(send(@method, 0))
send(@method, 0).ceil(10).should.eql?(send(@method, 0))

send(@method, 123).ceil(10).should.eql?(send(@method, 123))
send(@method, -123).ceil(10).should.eql?(send(@method, -123))
end
end

context "precision is negative" do
it "always returns 0 when self is 0" do
send(@method, 0).ceil(-1).should.eql?(0)
send(@method, 0).ceil(-10).should.eql?(0)
end

it "returns largest integer less than self with at least precision.abs trailing zeros" do
send(@method, 123).ceil(-1).should.eql?(130)
send(@method, 123).ceil(-2).should.eql?(200)
send(@method, 123).ceil(-3).should.eql?(1000)

send(@method, -123).ceil(-1).should.eql?(-120)
send(@method, -123).ceil(-2).should.eql?(-100)
send(@method, -123).ceil(-3).should.eql?(0)
end

ruby_bug "#20654", ""..."3.4" do
it "returns 10**precision.abs when precision.abs is larger than the number digits of self" do
send(@method, 123).ceil(-20).should.eql?(100000000000000000000)
send(@method, 123).ceil(-50).should.eql?(100000000000000000000000000000000000000000000000000)
end
end
end
end
43 changes: 43 additions & 0 deletions spec/core/integer/shared/integer_floor_precision.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe :integer_floor_precision, shared: true do
context "precision is zero" do
it "returns integer self" do
send(@method, 0).floor(0).should.eql?(0)
send(@method, 123).floor(0).should.eql?(123)
send(@method, -123).floor(0).should.eql?(-123)
end
end

context "precision is positive" do
it "returns self" do
send(@method, 0).floor(1).should.eql?(send(@method, 0))
send(@method, 0).floor(10).should.eql?(send(@method, 0))

send(@method, 123).floor(10).should.eql?(send(@method, 123))
send(@method, -123).floor(10).should.eql?(send(@method, -123))
end
end

context "precision is negative" do
it "always returns 0 when self is 0" do
send(@method, 0).floor(-1).should.eql?(0)
send(@method, 0).floor(-10).should.eql?(0)
end

it "returns largest integer less than self with at least precision.abs trailing zeros" do
send(@method, 123).floor(-1).should.eql?(120)
send(@method, 123).floor(-2).should.eql?(100)
send(@method, 123).floor(-3).should.eql?(0)

send(@method, -123).floor(-1).should.eql?(-130)
send(@method, -123).floor(-2).should.eql?(-200)
send(@method, -123).floor(-3).should.eql?(-1000)
end

ruby_bug "#20654", ""..."3.4" do
it "returns -(10**precision.abs) when self is negative and precision.abs is larger than the number digits of self" do
send(@method, -123).floor(-20).should.eql?(-100000000000000000000)
send(@method, -123).floor(-50).should.eql?(-100000000000000000000000000000000000000000000000000)
end
end
end
end
4 changes: 2 additions & 2 deletions spec/core/integer/size_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative '../../spec_helper'

describe "Integer#size" do
platform_is wordsize: 32 do
platform_is c_long_size: 32 do
it "returns the number of bytes in the machine representation of self" do
-1.size.should == 4
0.size.should == 4
4091.size.should == 4
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
it "returns the number of bytes in the machine representation of self" do
-1.size.should == 8
0.size.should == 8
Expand Down
16 changes: 16 additions & 0 deletions spec/core/kernel/raise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@
cause = StandardError.new
-> { raise(cause: cause) }.should raise_error(ArgumentError)
end

it "re-raises a rescued exception" do
-> do
begin
raise StandardError, "aaa"
rescue Exception
begin
raise ArgumentError
rescue ArgumentError
end

# should raise StandardError "aaa"
raise
end
end.should raise_error(StandardError, "aaa")
end
end

describe "Kernel#raise" do
Expand Down
14 changes: 14 additions & 0 deletions spec/core/kernel/sleep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ def o.divmod(*); [0, 0.001]; end
t.value.should == 5
end

platform_is_not :darwin do
it "sleeps with nanosecond precision" do
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
100.times do
sleep(0.0001)
end
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)

actual_duration = end_time - start_time
(actual_duration > 0.01).should == true # 100 * 0.0001 => 0.01
(actual_duration < 0.03).should == true
end
end

ruby_version_is ""..."3.3" do
it "raises a TypeError when passed nil" do
-> { sleep(nil) }.should raise_error(TypeError)
Expand Down
116 changes: 69 additions & 47 deletions spec/core/process/constants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,91 @@

describe "Process::Constants" do
platform_is :darwin, :netbsd, :freebsd do
it "has the correct constant values on BSD-like systems" do
Process::WNOHANG.should == 1
Process::WUNTRACED.should == 2
Process::PRIO_PROCESS.should == 0
Process::PRIO_PGRP.should == 1
Process::PRIO_USER.should == 2
Process::RLIM_INFINITY.should == 9223372036854775807
Process::RLIMIT_CPU.should == 0
Process::RLIMIT_FSIZE.should == 1
Process::RLIMIT_DATA.should == 2
Process::RLIMIT_STACK.should == 3
Process::RLIMIT_CORE.should == 4
Process::RLIMIT_RSS.should == 5
Process::RLIMIT_MEMLOCK.should == 6
Process::RLIMIT_NPROC.should == 7
Process::RLIMIT_NOFILE.should == 8
it "are all present on BSD-like systems" do
%i[
WNOHANG
WUNTRACED
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
RLIM_INFINITY
RLIMIT_CPU
RLIMIT_FSIZE
RLIMIT_DATA
RLIMIT_STACK
RLIMIT_CORE
RLIMIT_RSS
RLIMIT_MEMLOCK
RLIMIT_NPROC
RLIMIT_NOFILE
].each do |const|
Process.const_defined?(const).should be_true
Process.const_get(const).should be_an_instance_of(Integer)
end
end
end

platform_is :darwin do
it "has the correct constant values on Darwin" do
Process::RLIM_SAVED_MAX.should == 9223372036854775807
Process::RLIM_SAVED_CUR.should == 9223372036854775807
Process::RLIMIT_AS.should == 5
it "are all present on Darwin" do
%i[
RLIM_SAVED_MAX
RLIM_SAVED_CUR
RLIMIT_AS
].each do |const|
Process.const_defined?(const).should be_true
Process.const_get(const).should be_an_instance_of(Integer)
end
end
end

platform_is :linux do
it "has the correct constant values on Linux" do
Process::WNOHANG.should == 1
Process::WUNTRACED.should == 2
Process::PRIO_PROCESS.should == 0
Process::PRIO_PGRP.should == 1
Process::PRIO_USER.should == 2
Process::RLIMIT_CPU.should == 0
Process::RLIMIT_FSIZE.should == 1
Process::RLIMIT_DATA.should == 2
Process::RLIMIT_STACK.should == 3
Process::RLIMIT_CORE.should == 4
Process::RLIMIT_RSS.should == 5
Process::RLIMIT_NPROC.should == 6
Process::RLIMIT_NOFILE.should == 7
Process::RLIMIT_MEMLOCK.should == 8
Process::RLIMIT_AS.should == 9

# These values appear to change according to the platform.
values = [4294967295, 9223372036854775807, 18446744073709551615]
values.include?(Process::RLIM_INFINITY).should be_true
values.include?(Process::RLIM_SAVED_MAX).should be_true
values.include?(Process::RLIM_SAVED_CUR).should be_true
it "are all present on Linux" do
%i[
WNOHANG
WUNTRACED
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
RLIMIT_CPU
RLIMIT_FSIZE
RLIMIT_DATA
RLIMIT_STACK
RLIMIT_CORE
RLIMIT_RSS
RLIMIT_NPROC
RLIMIT_NOFILE
RLIMIT_MEMLOCK
RLIMIT_AS
RLIM_INFINITY
RLIM_SAVED_MAX
RLIM_SAVED_CUR
].each do |const|
Process.const_defined?(const).should be_true
Process.const_get(const).should be_an_instance_of(Integer)
end
end
end

platform_is :netbsd, :freebsd do
it "has the correct constant values on NetBSD and FreeBSD" do
Process::RLIMIT_SBSIZE.should == 9 # FIXME: what's it equal?
Process::RLIMIT_AS.should == 10
it "are all present on NetBSD and FreeBSD" do
%i[
RLIMIT_SBSIZE
RLIMIT_AS
].each do |const|
Process.const_defined?(const).should be_true
Process.const_get(const).should be_an_instance_of(Integer)
end
end
end

platform_is :freebsd do
it "has the correct constant values on FreeBSD" do
Process::RLIMIT_NPTS.should == 11
it "are all present on FreeBSD" do
%i[
RLIMIT_NPTS
].each do |const|
Process.const_defined?(const).should be_true
Process.const_get(const).should be_an_instance_of(Integer)
end
end
end

Expand Down
Loading
Loading