Skip to content
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
4 changes: 2 additions & 2 deletions .github/actions/capiext/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ runs:
eval $(grep -e '^arch *=' -e '^ruby_version *=' -e '^DLEXT *=' Makefile |
sed 's/ *= */=/')
case "${ruby_version}" in
*+*) key=capiexts-${arch}-${ruby_version};;
*+*) key=capiexts-${arch}-${ruby_version}-${{ hashFiles('src/spec/ruby/optional/capi/ext/*.[ch]') }};;
*) key=;;
esac
echo version=$ruby_version >> $GITHUB_OUTPUT
echo key=$key >> $GITHUB_OUTPUT
echo key="$key" >> $GITHUB_OUTPUT
echo DLEXT=$DLEXT >> $GITHUB_OUTPUT
working-directory: ${{ inputs.builddir }}

Expand Down
2 changes: 1 addition & 1 deletion internal/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ ntz_int64(uint64_t x)
{
#if defined(__x86_64__) && defined(__BMI__)
return (unsigned)_tzcnt_u64(x);
`

#elif defined(_WIN64) && defined(_MSC_VER)
unsigned long r;
return _BitScanForward64(&r, x) ? (int)r : 64;
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/rubygems_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def ensure_writable_dir(dir)
end

def generate_plugins
return unless Gem::Installer.method_defined?(:generate_plugins)
return unless Gem::Installer.method_defined?(:generate_plugins, false)

latest = Gem::Specification.stubs_for(spec.name).first
return if latest && latest.version > spec.version
Expand Down
13 changes: 10 additions & 3 deletions spec/mspec/lib/mspec/utils/name_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,17 @@ def exception?(name)
end

def class_or_module(c)
const = Object.const_get(c, false)
begin
const = Object.const_get(c, false)
rescue NameError, RuntimeError
# Either the constant doesn't exist or it is
# explicitly raising an error, like `SortedSet`.
return nil
end
return nil unless Module === const

filtered = @filter && EXCLUDED.include?(const.name)
return const if Module === const and !filtered
rescue NameError
return const unless filtered
end

def namespace(mod, const)
Expand Down
1 change: 1 addition & 0 deletions spec/mspec/spec/utils/fixtures/this_file_raises.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise "This is a BAD file"
1 change: 1 addition & 0 deletions spec/mspec/spec/utils/fixtures/this_file_raises2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise "This is a BAD file 2"
12 changes: 12 additions & 0 deletions spec/mspec/spec/utils/name_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Fixnum
def f; end
end

autoload :BadFile, "#{__dir__}/fixtures/this_file_raises.rb"
autoload :BadFile2, "#{__dir__}/fixtures/this_file_raises2.rb"

def self.n; end
def n; end
end
Expand Down Expand Up @@ -84,6 +87,15 @@ def n; end
expect(@map.class_or_module("Hell")).to eq(nil)
expect(@map.class_or_module("Bush::Brain")).to eq(nil)
end

it "returns nil if accessing the constant raises RuntimeError" do
expect { NameMapSpecs::BadFile }.to raise_error(RuntimeError)
expect(@map.class_or_module("NameMapSpecs::BadFile")).to eq(nil)
end

it "returns nil if accessing the constant raises RuntimeError when not triggering the autoload before" do
expect(@map.class_or_module("NameMapSpecs::BadFile2")).to eq(nil)
end
end

RSpec.describe NameMap, "#dir_name" do
Expand Down
70 changes: 68 additions & 2 deletions spec/ruby/core/comparable/clamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
c.clamp(two, three).should equal(c)
end

it 'returns the min parameter if smaller than it' do
it 'returns the min parameter if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(0)
Expand Down Expand Up @@ -52,7 +52,7 @@
c.clamp(two..three).should equal(c)
end

it 'returns the minimum value of the range parameters if smaller than it' do
it 'returns the minimum value of the range parameters if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(0)
Expand All @@ -75,4 +75,70 @@

-> { c.clamp(one...two) }.should raise_error(ArgumentError)
end

context 'with endless range' do
it 'returns minimum value of the range parameters if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
c = ComparableSpecs::Weird.new(0)

c.clamp(one..).should equal(one)
c.clamp(zero..).should equal(c)
end

it 'always returns self if greater than minimum value of the range parameters' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
c = ComparableSpecs::Weird.new(2)

c.clamp(one..).should equal(c)
c.clamp(two..).should equal(c)
end

it 'works with exclusive range' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
c = ComparableSpecs::Weird.new(2)

c.clamp(one...).should equal(c)
end
end

context 'with beginless range' do
it 'returns maximum value of the range parameters if greater than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
c = ComparableSpecs::Weird.new(2)

c.clamp(..one).should equal(one)
end

it 'always returns self if less than maximum value of the range parameters' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
c = ComparableSpecs::Weird.new(0)

c.clamp(..one).should equal(c)
c.clamp(..zero).should equal(c)
end

it 'raises an Argument error if the range parameter is exclusive' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
c = ComparableSpecs::Weird.new(0)

-> { c.clamp(...one) }.should raise_error(ArgumentError)
end
end

context 'with beginless-and-endless range' do
it 'always returns self' do
c = ComparableSpecs::Weird.new(1)

c.clamp(nil..nil).should equal(c)
end

it 'works with exclusive range' do
c = ComparableSpecs::Weird.new(2)

c.clamp(nil...nil).should equal(c)
end
end
end
2 changes: 1 addition & 1 deletion spec/ruby/core/enumerable/shared/inject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def name.to_str; "-"; end

it "without inject arguments(legacy rubycon)" do
# no inject argument
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| 999 } .should == 2
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| 999 }.should == 2
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| acc }.should == 2
EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| x }.should == 2

Expand Down
2 changes: 1 addition & 1 deletion spec/ruby/core/hash/compact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
hash.compact.default_proc.should == pr
end

it "retains compare_by_identity_flag" do
it "retains compare_by_identity flag" do
hash = {}.compare_by_identity
hash.compact.compare_by_identity?.should == true
hash[:a] = 1
Expand Down
11 changes: 6 additions & 5 deletions spec/ruby/core/hash/constructor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,26 @@ def obj.to_hash() { 1 => 2, 3 => 4 } end
HashSpecs::MyInitializerHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyInitializerHash)
end

it "removes the default value" do
it "does not retain the default value" do
hash = Hash.new(1)
Hash[hash].default.should be_nil
hash[:a] = 1
Hash[hash].default.should be_nil
end

it "removes the default_proc" do
it "does not retain the default_proc" do
hash = Hash.new { |h, k| h[k] = [] }
Hash[hash].default_proc.should be_nil
hash[:a] = 1
Hash[hash].default_proc.should be_nil
end

ruby_version_is '3.3' do
it "does not retain compare_by_identity_flag" do
hash = {}.compare_by_identity
it "does not retain compare_by_identity flag" do
hash = { a: 1 }.compare_by_identity
Hash[hash].compare_by_identity?.should == false
hash[:a] = 1

hash = {}.compare_by_identity
Hash[hash].compare_by_identity?.should == false
end
end
Expand Down
28 changes: 19 additions & 9 deletions spec/ruby/core/hash/except_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@
@hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
end

it "always returns a Hash without a default" do
klass = Class.new(Hash)
h = klass.new(:default)
h[:bar] = 12
h[:foo] = 42
r = h.except(:foo)
r.should == {bar: 12}
r.class.should == Hash
r.default.should == nil
it "does not retain the default value" do
h = Hash.new(1)
h.except(:a).default.should be_nil
h[:a] = 1
h.except(:a).default.should be_nil
end

it "does not retain the default_proc" do
pr = proc { |h, k| h[k] = [] }
h = Hash.new(&pr)
h.except(:a).default_proc.should be_nil
h[:a] = 1
h.except(:a).default_proc.should be_nil
end

it "retains compare_by_identity flag" do
h = { a: 9, c: 4 }.compare_by_identity
h2 = h.except(:a)
h2.compare_by_identity?.should == true
end
end
21 changes: 21 additions & 0 deletions spec/ruby/core/hash/invert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@
HashSpecs::MyHash[1 => 2, 3 => 4].invert.class.should == Hash
HashSpecs::MyHash[].invert.class.should == Hash
end

it "does not retain the default value" do
h = Hash.new(1)
h.invert.default.should be_nil
h[:a] = 1
h.invert.default.should be_nil
end

it "does not retain the default_proc" do
pr = proc { |h, k| h[k] = [] }
h = Hash.new(&pr)
h.invert.default_proc.should be_nil
h[:a] = 1
h.invert.default_proc.should be_nil
end

it "does not retain compare_by_identity flag" do
h = { a: 9, c: 4 }.compare_by_identity
h2 = h.invert
h2.compare_by_identity?.should == false
end
end
23 changes: 23 additions & 0 deletions spec/ruby/core/hash/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@
merged.should eql(hash)
merged.should_not equal(hash)
end

it "retains the default value" do
h = Hash.new(1)
h.merge(b: 1, d: 2).default.should == 1
end

it "retains the default_proc" do
pr = proc { |h, k| h[k] = [] }
h = Hash.new(&pr)
h.merge(b: 1, d: 2).default_proc.should == pr
end

it "retains compare_by_identity flag" do
h = { a: 9, c: 4 }.compare_by_identity
h2 = h.merge(b: 1, d: 2)
h2.compare_by_identity?.should == true
end

it "ignores compare_by_identity flag of an argument" do
h = { a: 9, c: 4 }.compare_by_identity
h2 = { b: 1, d: 2 }.merge(h)
h2.compare_by_identity?.should == false
end
end

describe "Hash#merge!" do
Expand Down
21 changes: 21 additions & 0 deletions spec/ruby/core/hash/reject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ def h.to_a() end
reject_pairs.should == reject_bang_pairs
end

it "does not retain the default value" do
h = Hash.new(1)
h.reject { false }.default.should be_nil
h[:a] = 1
h.reject { false }.default.should be_nil
end

it "does not retain the default_proc" do
pr = proc { |h, k| h[k] = [] }
h = Hash.new(&pr)
h.reject { false }.default_proc.should be_nil
h[:a] = 1
h.reject { false }.default_proc.should be_nil
end

it "retains compare_by_identity flag" do
h = { a: 9, c: 4 }.compare_by_identity
h2 = h.reject { |k, _| k == :a }
h2.compare_by_identity?.should == true
end

it_behaves_like :hash_iteration_no_block, :reject
it_behaves_like :enumeratorized_with_origin_size, :reject, { 1 => 2, 3 => 4, 5 => 6 }
end
Expand Down
Loading