Skip to content

Commit

Permalink
[GR-14806] Update specs
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4423
  • Loading branch information
andrykonchin committed Dec 10, 2024
2 parents fcb982c + f94d69f commit c14418a
Show file tree
Hide file tree
Showing 40 changed files with 764 additions and 260 deletions.
1 change: 1 addition & 0 deletions spec/mspec/lib/mspec/commands/mspec-run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def options(argv = ARGV)
options.chdir
options.prefix
options.configure { |f| load f }
options.env
options.randomize
options.repeat
options.pretend
Expand Down
8 changes: 8 additions & 0 deletions spec/mspec/lib/mspec/utils/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def configure(&block)
"Load FILE containing configuration options", &block)
end

def env
on("--env", "KEY=VALUE", "Set environment variable") do |env|
key, value = env.split('=', 2)
ENV[key] = value
end
end

def targets
on("-t", "--target", "TARGET",
"Implementation to run the specs, where TARGET is:") do |t|
Expand Down Expand Up @@ -484,6 +491,7 @@ def debug

def all
configure {}
env
targets
formatters
filters
Expand Down
22 changes: 13 additions & 9 deletions spec/mspec/tool/sync/sync-rubyspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
CHECK_LAST_MERGE = !MSPEC && ENV['CHECK_LAST_MERGE'] != 'false'
TEST_MASTER = ENV['TEST_MASTER'] != 'false'

ONLY_FILTER = ENV['ONLY_FILTER'] == 'true'

MSPEC_REPO = File.expand_path("../../..", __FILE__)
raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git")

Expand Down Expand Up @@ -230,15 +232,17 @@ def main(impls)
impl = RubyImplementation.new(impl, data)
update_repo(impl)
filter_commits(impl)
rebase_commits(impl)
if new_commits?(impl)
test_new_specs
verify_commits(impl)
fast_forward_master(impl)
check_ci
else
STDERR.puts "#{BRIGHT_YELLOW}No new commits#{RESET}"
fast_forward_master(impl)
unless ONLY_FILTER
rebase_commits(impl)
if new_commits?(impl)
test_new_specs
verify_commits(impl)
fast_forward_master(impl)
check_ci
else
STDERR.puts "#{BRIGHT_YELLOW}No new commits#{RESET}"
fast_forward_master(impl)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/ruby/command_line/dash_v_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ruby_exe(nil, args: '-v').sub("+PRISM ", "").should include(RUBY_DESCRIPTION.sub("+PRISM ", ""))
end unless (defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?) ||
(defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?) ||
(ENV['RUBY_GC_LIBRARY'] && ENV['RUBY_GC_LIBRARY'].length > 0) ||
(ENV['RUBY_MN_THREADS'] == '1')
end
end
4 changes: 2 additions & 2 deletions spec/ruby/command_line/rubyopt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
guard -> { RbConfig::CONFIG["CROSS_COMPILING"] != "yes" } do
it "prints the version number for '-v'" do
ENV["RUBYOPT"] = '-v'
ruby_exe("").sub("+PRISM ", "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "")
ruby_exe("").sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")
end

it "ignores whitespace around the option" do
ENV["RUBYOPT"] = ' -v '
ruby_exe("").sub("+PRISM ", "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "")
ruby_exe("").sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "").sub(/\+GC(\[\w+\]\s|\s)?/, "")
end
end

Expand Down
6 changes: 4 additions & 2 deletions spec/ruby/core/basicobject/equal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
it "is unaffected by overriding __id__" do
o1 = mock("object")
o2 = mock("object")
def o1.__id__; 10; end
def o2.__id__; 10; end
suppress_warning {
def o1.__id__; 10; end
def o2.__id__; 10; end
}
o1.equal?(o2).should be_false
end

Expand Down
16 changes: 14 additions & 2 deletions spec/ruby/core/exception/system_call_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,23 @@ def initialize
end

it "sets an 'unknown error' message when an unknown error number" do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
platform_is_not :windows do
SystemCallError.new(-1).message.should =~ /Unknown error(:)? -1/
end

platform_is :windows do
SystemCallError.new(-1).message.should == "The operation completed successfully."
end
end

it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
platform_is_not :windows do
SystemCallError.new("custom message", -1).message.should =~ /Unknown error(:)? -1 - custom message/
end

platform_is :windows do
SystemCallError.new("custom message", -1).message.should == "The operation completed successfully. - custom message"
end
end

it "converts to Integer if errno is a Complex convertible to Integer" do
Expand Down
40 changes: 29 additions & 11 deletions spec/ruby/core/integer/shared/exponent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,18 @@
(-1).send(@method, 4611686018427387905).should eql(-1)
end

it "returns Float::INFINITY when the number is too big" do
-> {
2.send(@method, 427387904).should == Float::INFINITY
}.should complain(/warning: in a\*\*b, b may be too big/)
ruby_version_is ""..."3.4" do
it "returns Float::INFINITY when the number is too big" do
-> {
2.send(@method, 427387904).should == Float::INFINITY
}.should complain(/warning: in a\*\*b, b may be too big/)
end
end

ruby_version_is "3.4" do
it "raises an ArgumentError when the number is too big" do
-> { 100000000.send(@method, 1000000000) }.should raise_error(ArgumentError)
end
end

it "raises a ZeroDivisionError for 0 ** -1" do
Expand Down Expand Up @@ -108,13 +116,23 @@
-> { @bignum.send(@method, :symbol) }.should raise_error(TypeError)
end

it "switch to a Float when the values is too big" do
flt = nil
-> {
flt = @bignum.send(@method, @bignum)
}.should complain(/warning: in a\*\*b, b may be too big/)
flt.should be_kind_of(Float)
flt.infinite?.should == 1
ruby_version_is ""..."3.4" do
it "switch to a Float when the values is too big" do
flt = nil
-> {
flt = @bignum.send(@method, @bignum)
}.should complain(/warning: in a\*\*b, b may be too big/)
flt.should be_kind_of(Float)
flt.infinite?.should == 1
end
end

ruby_version_is "3.4" do
it "does not switch to a Float when the values is too big" do
-> {
@bignum.send(@method, @bignum)
}.should raise_error(ArgumentError)
end
end

it "returns a complex number when negative and raised to a fractional power" do
Expand Down
19 changes: 8 additions & 11 deletions spec/ruby/core/kernel/sleep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,15 @@ def o.divmod(*); [0, 0.001]; end
t.value.should == 5
end

quarantine! do # fails transiently on at least linux & darwin
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
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.should > 0.01 # 100 * 0.0001 => 0.01
end

ruby_version_is ""..."3.3" do
Expand Down
9 changes: 9 additions & 0 deletions spec/ruby/core/module/deprecate_constant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
end
end

ruby_bug '#20900', ''...'3.4' do
describe "when removing the deprecated module" do
it "warns with a message" do
@module.deprecate_constant :PUBLIC1
-> { @module.module_eval {remove_const :PUBLIC1} }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
end
end
end

it "accepts multiple symbols and strings as constant names" do
@module.deprecate_constant "PUBLIC1", :PUBLIC2

Expand Down
32 changes: 31 additions & 1 deletion spec/ruby/core/process/status/bit_and_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
require_relative '../../../spec_helper'

describe "Process::Status#&" do
it "needs to be reviewed for spec completeness"
it "returns a bitwise and of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? & 0).should == 0
($? & $?.to_i).should == $?.to_i

# Actual value is implementation specific
platform_is :linux do
# 29 == 0b11101
($? & 0b1011100000000).should == 0b1010100000000
end
end
end

ruby_version_is "3.3" do
it "raises an ArgumentError if mask is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? & -1
}.should raise_error(ArgumentError, 'negative mask value: -1')
end
end

it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? & 0
}.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/)
end
end
end
31 changes: 30 additions & 1 deletion spec/ruby/core/process/status/right_shift_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
require_relative '../../../spec_helper'

describe "Process::Status#>>" do
it "needs to be reviewed for spec completeness"
it "returns a right shift of the integer status of an exited child" do
suppress_warning do
ruby_exe("exit(29)", exit_status: 29)
($? >> 0).should == $?.to_i
($? >> 1).should == $?.to_i >> 1

# Actual value is implementation specific
platform_is :linux do
($? >> 8).should == 29
end
end
end

ruby_version_is "3.3" do
it "raises an ArgumentError if shift value is negative" do
suppress_warning do
ruby_exe("exit(0)")
-> {
$? >> -1
}.should raise_error(ArgumentError, 'negative shift value: -1')
end
end

it "shows a deprecation warning" do
ruby_exe("exit(0)")
-> {
$? >> 0
}.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/)
end
end
end
10 changes: 6 additions & 4 deletions spec/ruby/core/range/reverse_each_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ruby_version_is "3.3" do
describe "Range#reverse_each" do
it "traverses the Range in reverse order and pass each element to block" do
it "traverses the Range in reverse order and passes each element to block" do
a = []
(1..3).reverse_each { |i| a << i }
a.should == [3, 2, 1]
Expand Down Expand Up @@ -88,8 +88,10 @@
(1..3).reverse_each.size.should == 3
end

it "returns Infinity when Range size is infinite" do
(..3).reverse_each.size.should == Float::INFINITY
ruby_bug "#20936", "3.4"..."3.5" do
it "returns Infinity when Range size is infinite" do
(..3).reverse_each.size.should == Float::INFINITY
end
end

it "returns nil when Range size is unknown" do
Expand All @@ -98,4 +100,4 @@
end
end
end
end
end
27 changes: 24 additions & 3 deletions spec/ruby/core/refinement/refined_class_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
require_relative '../../spec_helper'
require_relative "../../spec_helper"
require_relative 'shared/target'

describe "Refinement#refined_class" do
ruby_version_is "3.2"..."3.3" do
it "returns the class refined by the receiver" do
it_behaves_like :refinement_target, :refined_class
end

ruby_version_is "3.3"..."3.4" do
it "has been deprecated in favour of Refinement#target" do
refinement_int = nil

Module.new do
refine Integer do
refinement_int = self
end
end

-> {
refinement_int.refined_class
}.should complain(/warning: Refinement#refined_class is deprecated and will be removed in Ruby 3.4; use Refinement#target instead/)
end
end

ruby_version_is "3.4" do
it "has been removed" do
refinement_int = nil

Module.new do
Expand All @@ -11,7 +32,7 @@
end
end

refinement_int.refined_class.should == Integer
refinement_int.should_not.respond_to?(:refined_class)
end
end
end
13 changes: 13 additions & 0 deletions spec/ruby/core/refinement/shared/target.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe :refinement_target, shared: true do
it "returns the class refined by the receiver" do
refinement_int = nil

Module.new do
refine Integer do
refinement_int = self
end
end

refinement_int.send(@method).should == Integer
end
end
8 changes: 8 additions & 0 deletions spec/ruby/core/refinement/target_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require_relative "../../spec_helper"
require_relative 'shared/target'

describe "Refinement#target" do
ruby_version_is "3.3" do
it_behaves_like :refinement_target, :target
end
end
Loading

0 comments on commit c14418a

Please sign in to comment.