Skip to content

Commit

Permalink
[GR-20446] Fix recently imported specs
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4398
  • Loading branch information
andrykonchin committed Jan 17, 2025
2 parents 9c3cae2 + 13a6542 commit 3a18932
Show file tree
Hide file tree
Showing 28 changed files with 416 additions and 119 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Bug fixes:
* Fix `Module#name` called inside the `Module#const_added` callback when the module is defined in the top-level scope (#3683, @andrykonchin).
* Fix duplicated calls of a `Module#const_added` callback when a module with nested modules is assigned to a constant (@andrykonchin).
* Support OpenSSL 1.1-3.4 and prefer in order OpenSSL 3.0.x, 3.x and 1.1 (EOL). There was a compilation issue with OpenSSL 3.4 (#3724, @eregon).
* Fix `Time{.at,.new,.now,#getlocal,#localtime}` methods and validation of seconds in utc offset in String format (@andrykonchin).
* Fix `ObjectSpace.undefine_finalizer` and raise `FrozenError` when called for a frozen object (@andrykonchin).
* Fix `Integer#/` when called with a bignum argument (@andrykonchin).

Compatibility:

Expand Down Expand Up @@ -53,6 +56,9 @@ Compatibility:
* Update `NoMethodError#message` to not use `#inspect` on receiver (#3681, @rwstauner).
* Socket `#recv*` methods (`{BasicSocket,IPSocket,TCPSocket,UDPSocket,Socket}#{recv,recv_nonblock,recvmsg,recvmsg_nonblock,recvfrom,recvfrom_nonblock}`) return `nil` instead of an empty String on closed connections (#3681, @andrykonchyn).
* Fix `Marshal.dump` when a Float value is dumped repeatedly (#3747, @andrykochin).
* Emit warning when `Kernel#format` called with excessive arguments (@andrykonchin).
* Fix `Integer#ceil` when self is 0 (@andrykonchin).
* Fix `Module#remove_const` and emit warning when constant is deprecated (@andrykonchin).

Performance:

Expand Down
20 changes: 20 additions & 0 deletions spec/ruby/core/integer/divide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

it "supports dividing negative numbers" do
(-1 / 10).should == -1
(-1 / 10**10).should == -1
(-1 / 10**20).should == -1
end

it "preservers sign correctly" do
(4 / 3).should == 1
(4 / -3).should == -2
(-4 / 3).should == -2
(-4 / -3).should == 1
(0 / -3).should == 0
(0 / 3).should == 0
end

it "returns result the same class as the argument" do
Expand Down Expand Up @@ -58,6 +69,15 @@
((10**50) / -(10**40 + 1)).should == -10000000000
end

it "preservers sign correctly" do
(4 / bignum_value).should == 0
(4 / -bignum_value).should == -1
(-4 / bignum_value).should == -1
(-4 / -bignum_value).should == 0
(0 / bignum_value).should == 0
(0 / -bignum_value).should == 0
end

it "returns self divided by Float" do
not_supported_on :opal do
(bignum_value(88) / 4294967295.0).should be_close(4294967297.0, TOLERANCE)
Expand Down
20 changes: 19 additions & 1 deletion spec/ruby/core/kernel/Float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ def to_f() 1.2 end
@object.send(:Float, "1\t\n").should == 1.0
end

ruby_version_is ""..."3.4" do
it "raises ArgumentError if a fractional part is missing" do
-> { @object.send(:Float, "1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "+1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "-1.") }.should raise_error(ArgumentError)
-> { @object.send(:Float, "1.e+0") }.should raise_error(ArgumentError)
end
end

ruby_version_is "3.4" do
it "allows String representation without a fractional part" do
@object.send(:Float, "1.").should == 1.0
@object.send(:Float, "+1.").should == 1.0
@object.send(:Float, "-1.").should == -1.0
@object.send(:Float, "1.e+0").should == 1.0
end
end

%w(e E).each do |e|
it "raises an ArgumentError if #{e} is the trailing character" do
-> { @object.send(:Float, "2#{e}") }.should raise_error(ArgumentError)
Expand Down Expand Up @@ -280,7 +298,7 @@ def to_f() 1.2 end
nan2.should equal(nan)
end

it "returns the identical Infinity if to_f is called and it returns Infinity" do
it "returns the identical Infinity if #to_f is called and it returns Infinity" do
infinity = infinity_value
(infinity_to_f = mock('Infinity')).should_receive(:to_f).once.and_return(infinity)
infinity2 = @object.send(:Float, infinity_to_f)
Expand Down
4 changes: 3 additions & 1 deletion spec/ruby/core/string/modulo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,11 @@ def obj.to_s() "obj" end
(format % "-10.4e-20").should == (format % -10.4e-20)
(format % ".5").should == (format % 0.5)
(format % "-.5").should == (format % -0.5)
ruby_bug("#20705", ""..."3.4") do

ruby_version_is "3.4" do
(format % "10.").should == (format % 10)
end

# Something's strange with this spec:
# it works just fine in individual mode, but not when run as part of a group
(format % "10_1_0.5_5_5").should == (format % 1010.555)
Expand Down
52 changes: 52 additions & 0 deletions spec/ruby/core/time/at_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@
time.utc_offset.should == -9*60*60
time.zone.should == nil
time.to_i.should == @epoch_time

time = Time.at(@epoch_time, in: "-09:00:01")

time.utc_offset.should == -(9*60*60 + 1)
time.zone.should == nil
time.to_i.should == @epoch_time
end

it "could be UTC offset as a number of seconds" do
Expand Down Expand Up @@ -280,5 +286,51 @@
-> { Time.at(@epoch_time, in: "+09:99") }.should raise_error(ArgumentError)
-> { Time.at(@epoch_time, in: "ABC") }.should raise_error(ArgumentError)
end

it "raises ArgumentError if hours greater than 23" do # TODO
ruby_version_is ""..."3.1" do
-> { Time.at(@epoch_time, in: "+24:00") }.should raise_error(ArgumentError, 'utc_offset out of range')
-> { Time.at(@epoch_time, in: "+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.at(@epoch_time, in: "+99:00") }.should raise_error(ArgumentError, 'utc_offset out of range')
-> { Time.at(@epoch_time, in: "+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.at(@epoch_time, in: "+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.at(@epoch_time, in: "+2400") }.should raise_error(ArgumentError, "utc_offset out of range")

-> { Time.at(@epoch_time, in: "+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.at(@epoch_time, in: "+9900") }.should raise_error(ArgumentError, "utc_offset out of range")
end
end

it "raises ArgumentError if minutes greater than 59" do # TODO
ruby_version_is ""..."3.1" do
-> { Time.at(@epoch_time, in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.at(@epoch_time, in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.at(@epoch_time, in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.at(@epoch_time, in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.at(@epoch_time, in: "+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
-> { Time.at(@epoch_time, in: "+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')

-> { Time.at(@epoch_time, in: "+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
-> { Time.at(@epoch_time, in: "+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
end
end

ruby_bug '#20797', ''...'3.4' do
it "raises ArgumentError if seconds greater than 59" do
-> { Time.at(@epoch_time, in: "+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
-> { Time.at(@epoch_time, in: "+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')

-> { Time.at(@epoch_time, in: "+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
-> { Time.at(@epoch_time, in: "+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
end
end
end
58 changes: 58 additions & 0 deletions spec/ruby/core/time/getlocal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@
t.utc_offset.should == 3600
end

it "returns a Time with a UTC offset specified as +HH:MM:SS" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("+01:00:01")
t.should == Time.new(2007, 1, 9, 13, 0, 1, 3601)
t.utc_offset.should == 3601
end

it "returns a Time with a UTC offset specified as -HH:MM" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("-01:00")
t.should == Time.new(2007, 1, 9, 11, 0, 0, -3600)
t.utc_offset.should == -3600
end

it "returns a Time with a UTC offset specified as -HH:MM:SS" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("-01:00:01")
t.should == Time.new(2007, 1, 9, 10, 59, 59, -3601)
t.utc_offset.should == -3601
end

describe "with an argument that responds to #to_str" do
it "coerces using #to_str" do
o = mock('string')
Expand Down Expand Up @@ -97,6 +109,52 @@
-> { t.getlocal(86400) }.should raise_error(ArgumentError)
end

it "raises ArgumentError if String argument and hours greater than 23" do
ruby_version_is ""..."3.1" do
-> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.now.getlocal("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.getlocal("+2400") }.should raise_error(ArgumentError, "utc_offset out of range")

-> { Time.now.getlocal("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.getlocal("+9900") }.should raise_error(ArgumentError, "utc_offset out of range")
end
end

it "raises ArgumentError if String argument and minutes greater than 59" do
ruby_version_is ""..."3.1" do
-> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.now.getlocal("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
-> { Time.now.getlocal("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')

-> { Time.now.getlocal("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
-> { Time.now.getlocal("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
end
end

ruby_bug '#20797', ''...'3.4' do
it "raises ArgumentError if String argument and seconds greater than 59" do
-> { Time.now.getlocal("+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
-> { Time.now.getlocal("+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')

-> { Time.now.getlocal("+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
-> { Time.now.getlocal("+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
end

describe "with a timezone argument" do
it "returns a Time in the timezone" do
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
Expand Down
60 changes: 60 additions & 0 deletions spec/ruby/core/time/localtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,27 @@
t.utc_offset.should == 3600
end

it "returns a Time with a UTC offset specified as +HH:MM:SS" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime("+01:00:01")
t.should == Time.new(2007, 1, 9, 13, 0, 1, 3601)
t.utc_offset.should == 3601
end

it "returns a Time with a UTC offset specified as -HH:MM" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime("-01:00")
t.should == Time.new(2007, 1, 9, 11, 0, 0, -3600)
t.utc_offset.should == -3600
end

it "returns a Time with a UTC offset specified as -HH:MM:SS" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime("-01:00:01")
t.should == Time.new(2007, 1, 9, 10, 59, 59, -3601)
t.utc_offset.should == -3601
end

it "returns a Time with a UTC offset specified as UTC" do
t = Time.new(2007, 1, 9, 12, 0, 0, 3600)
t.localtime("UTC")
Expand All @@ -91,6 +105,52 @@
t.utc_offset.should == 3600 * 2
end

it "raises ArgumentError if String argument and hours greater than 23" do
ruby_version_is ""..."3.1" do
-> { Time.now.localtime("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.localtime("+2400") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.now.localtime("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.localtime("+9900") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.now.localtime("+24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.localtime("+2400") }.should raise_error(ArgumentError, "utc_offset out of range")

-> { Time.now.localtime("+99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.now.localtime("+9900") }.should raise_error(ArgumentError, "utc_offset out of range")
end
end

it "raises ArgumentError if String argument and minutes greater than 59" do
ruby_version_is ""..."3.1" do
-> { Time.now.localtime("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.now.localtime("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')

-> { Time.now.localtime("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
-> { Time.now.localtime("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset')
end

ruby_version_is "3.1" do
-> { Time.now.localtime("+00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
-> { Time.now.localtime("+0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')

-> { Time.now.localtime("+00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
-> { Time.now.localtime("+0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
end
end

ruby_bug '#20797', ''...'3.4' do
it "raises ArgumentError if String argument and seconds greater than 59" do
-> { Time.now.localtime("+00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
-> { Time.now.localtime("+000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')

-> { Time.now.localtime("+00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
-> { Time.now.localtime("+000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
end

platform_is_not :windows do
it "changes the timezone according to the set one" do
t = Time.new(2005, 2, 27, 22, 50, 0, -3600)
Expand Down
29 changes: 28 additions & 1 deletion spec/ruby/core/time/new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ def zone.local_to_utc(t)

time.utc_offset.should == -9*60*60
time.zone.should == nil

time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00:01")

time.utc_offset.should == -(9*60*60 + 1)
time.zone.should == nil
end

it "could be UTC offset as a number of seconds" do
Expand Down Expand Up @@ -659,7 +664,7 @@ def obj.to_int; 3; end

-> {
Time.new("2020-12-25 00:56:17 +23:61")
}.should raise_error(ArgumentError, /utc_offset|can't parse:/)
}.should raise_error(ArgumentError, /utc_offset/)

ruby_bug '#20797', ''...'3.4' do
-> {
Expand All @@ -668,6 +673,28 @@ def obj.to_int; 3; end
end
end

it "raises ArgumentError if utc offset parts are not valid" do
-> { Time.new("2020-12-25 00:56:17 +24:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.new("2020-12-25 00:56:17 +2400") }.should raise_error(ArgumentError, "utc_offset out of range")

-> { Time.new("2020-12-25 00:56:17 +99:00") }.should raise_error(ArgumentError, "utc_offset out of range")
-> { Time.new("2020-12-25 00:56:17 +9900") }.should raise_error(ArgumentError, "utc_offset out of range")

-> { Time.new("2020-12-25 00:56:17 +00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
-> { Time.new("2020-12-25 00:56:17 +0060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')

-> { Time.new("2020-12-25 00:56:17 +00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
-> { Time.new("2020-12-25 00:56:17 +0099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')

ruby_bug '#20797', ''...'3.4' do
-> { Time.new("2020-12-25 00:56:17 +00:00:60") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
-> { Time.new("2020-12-25 00:56:17 +000060") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')

-> { Time.new("2020-12-25 00:56:17 +00:00:99") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
-> { Time.new("2020-12-25 00:56:17 +000099") }.should raise_error(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
end
end

it "raises ArgumentError if string has not ascii-compatible encoding" do
-> {
Time.new("2021-11-31 00:00:60 +09:00".encode("utf-32le"))
Expand Down
Loading

0 comments on commit 3a18932

Please sign in to comment.