diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ce2a71cddb..a89e1e122f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,8 @@ name: CI -on: [push, pull_request] +on: + push: + branches: [master] + pull_request: permissions: contents: read @@ -10,11 +13,13 @@ jobs: matrix: os: [ ubuntu, macos, windows ] ruby: [ 3.2.9, 3.3.9, 3.4.7 ] + mspecopt: [""] rubyopt: [""] exclude: - { os: windows, ruby: 3.2.9 } # 3.2.9 has some issue with file time microseconds include: - { os: windows, ruby: 3.2.8 } # 3.2.9 has some issue with file time microseconds + - { os: ubuntu, ruby: 3.4.7, mspecopt: "--repeat 2" } - { os: ubuntu, ruby: 3.4.7, rubyopt: "--enable-frozen-string-literal" } - { os: ubuntu, ruby: 3.4.7, rubyopt: "--parser=parse.y" } @@ -37,14 +42,14 @@ jobs: env: CHECK_LEAKS: true RUBYOPT: "${{ matrix.rubyopt }}" - run: ../mspec/bin/mspec -j --timeout 30 + run: ../mspec/bin/mspec -j --timeout 30 ${{ matrix.mspecopt }} - name: Run specs (macOS) if: matrix.os == 'macos' env: CHECK_LEAKS: true # Use a larger timeout on macOS since it seems to have less reliable performance - run: ../mspec/bin/mspec -j --timeout 90 + run: ../mspec/bin/mspec -j --timeout 90 ${{ matrix.mspecopt }} - name: Run specs (Windows) if: matrix.os == 'windows' @@ -54,13 +59,13 @@ jobs: # Actions uses UTF8, causes test failures, similar to normal OS setup [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("IBM437") [Console]::InputEncoding = [System.Text.Encoding]::GetEncoding("IBM437") - ../mspec/bin/mspec -j + ../mspec/bin/mspec -j ${{ matrix.mspecopt }} - name: Run C-API specs as C++ if: matrix.os != 'windows' env: SPEC_CAPI_CXX: true - run: ../mspec/bin/mspec :capi + run: ../mspec/bin/mspec :capi ${{ matrix.mspecopt }} - name: Run require_relative checker if: matrix.os == 'ubuntu' diff --git a/core/enumerable/shared/inject.rb b/core/enumerable/shared/inject.rb index aae9e06c97..8fb7e98c2b 100644 --- a/core/enumerable/shared/inject.rb +++ b/core/enumerable/shared/inject.rb @@ -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 diff --git a/core/kernel/autoload_spec.rb b/core/kernel/autoload_spec.rb index 0404caec6d..5edb70541d 100644 --- a/core/kernel/autoload_spec.rb +++ b/core/kernel/autoload_spec.rb @@ -7,7 +7,9 @@ autoload :KSAutoloadA, "autoload_a.rb" autoload :KSAutoloadB, fixture(__FILE__, "autoload_b.rb") -autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb" +define_autoload_KSAutoloadCallsRequire = -> { + autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb" +} def check_autoload(const) autoload? const @@ -43,6 +45,7 @@ def check_autoload(const) end it "calls main.require(path) to load the file" do + define_autoload_KSAutoloadCallsRequire.call main = TOPLEVEL_BINDING.eval("self") main.should_receive(:require).with("main_autoload_not_exist.rb") # The constant won't be defined since require is mocked to do nothing diff --git a/core/module/const_added_spec.rb b/core/module/const_added_spec.rb index 739be3ead8..90cd36551a 100644 --- a/core/module/const_added_spec.rb +++ b/core/module/const_added_spec.rb @@ -117,6 +117,7 @@ module self::B end ScratchPad.recorded.should == [:A, :B] + ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModule end it "is called when a new class is defined under self" do @@ -158,6 +159,7 @@ class self::B end ScratchPad.recorded.should == [:A, :B] + ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModuleB end it "is called when an autoload is defined" do diff --git a/core/module/const_source_location_spec.rb b/core/module/const_source_location_spec.rb index 06b3b215c2..d0708bc784 100644 --- a/core/module/const_source_location_spec.rb +++ b/core/module/const_source_location_spec.rb @@ -255,6 +255,17 @@ line = ConstantSpecs::CONST_LOCATION ConstantSpecs.const_source_location('CONST_LOCATION').should == [file, line] end + end + + + context 'autoload' do + before :each do + @loaded_features = $".dup + end + + after :each do + $".replace @loaded_features + end ruby_bug("#20188", ""..."3.4") do it 'returns the real constant location as soon as it is defined' do @@ -265,6 +276,8 @@ ConstantSpecs.const_source_location(:ConstSource).should == autoload_location ConstantSpecs::ConstSource::LOCATION.should == ConstantSpecs.const_source_location(:ConstSource) ConstantSpecs::BEFORE_DEFINE_LOCATION.should == autoload_location + ConstantSpecs.send :remove_const, :ConstSource + ConstantSpecs.send :remove_const, :BEFORE_DEFINE_LOCATION end end end diff --git a/core/module/name_spec.rb b/core/module/name_spec.rb index fd28ee0a33..d3318e1645 100644 --- a/core/module/name_spec.rb +++ b/core/module/name_spec.rb @@ -190,6 +190,7 @@ module self::B ScratchPad.recorded.should.one?(/#::A$/) ScratchPad.recorded.should.one?(/#::A::B$/) + ModuleSpecs::NameSpecs.send :remove_const, :NamedModule end it "returns a frozen String" do diff --git a/core/module/set_temporary_name_spec.rb b/core/module/set_temporary_name_spec.rb index 12c1c214dd..624b02c90e 100644 --- a/core/module/set_temporary_name_spec.rb +++ b/core/module/set_temporary_name_spec.rb @@ -86,6 +86,7 @@ module m::N; end ModuleSpecs::SetTemporaryNameSpec::M = m m::N.name.should == "ModuleSpecs::SetTemporaryNameSpec::M::N" + ModuleSpecs::SetTemporaryNameSpec.send :remove_const, :M end it "can update the name when assigned to a constant" do diff --git a/core/random/new_spec.rb b/core/random/new_spec.rb index 90e2a9d6f2..69210cef03 100644 --- a/core/random/new_spec.rb +++ b/core/random/new_spec.rb @@ -11,7 +11,7 @@ it "returns Random instances initialized with different seeds" do first = Random.new second = Random.new - (0..20).map { first.rand } .should_not == (0..20).map { second.rand } + (0..20).map { first.rand }.should_not == (0..20).map { second.rand } end it "accepts an Integer seed value as an argument" do diff --git a/language/regexp/encoding_spec.rb b/language/regexp/encoding_spec.rb index 898b6d4ff7..ceb9cf823a 100644 --- a/language/regexp/encoding_spec.rb +++ b/language/regexp/encoding_spec.rb @@ -39,7 +39,11 @@ end it "warns when using /n with a match string with non-ASCII characters and an encoding other than ASCII-8BIT" do - -> { /./n.match("\303\251".dup.force_encoding('utf-8')) }.should complain(%r{historical binary regexp match /.../n against UTF-8 string}) + -> { + eval <<~RUBY + /./n.match("\303\251".dup.force_encoding('utf-8')) + RUBY + }.should complain(%r{historical binary regexp match /.../n against UTF-8 string}) end it 'uses US-ASCII as /n encoding if all chars are 7-bit' do diff --git a/language/rescue_spec.rb b/language/rescue_spec.rb index 79571d689f..6be3bfd023 100644 --- a/language/rescue_spec.rb +++ b/language/rescue_spec.rb @@ -136,10 +136,14 @@ class << Object.new it 'captures successfully at the top-level' do ScratchPad.record [] + loaded_features = $".dup + begin + require_relative 'fixtures/rescue/top_level' - require_relative 'fixtures/rescue/top_level' - - ScratchPad.recorded.should == ["message"] + ScratchPad.recorded.should == ["message"] + ensure + $".replace loaded_features + end end end diff --git a/library/net-http/HTTPServerException_spec.rb b/library/net-http/HTTPServerException_spec.rb index 5e0a833fee..020d3cce85 100644 --- a/library/net-http/HTTPServerException_spec.rb +++ b/library/net-http/HTTPServerException_spec.rb @@ -3,10 +3,10 @@ describe "Net::HTTPServerException" do it "is a subclass of Net::ProtoServerError and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) + -> { eval("Net::HTTPServerException").should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) end it "includes the Net::HTTPExceptions module and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) + -> { eval("Net::HTTPServerException").should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) end end diff --git a/optional/capi/encoding_spec.rb b/optional/capi/encoding_spec.rb index 0c3c98a5c0..c14983c7ea 100644 --- a/optional/capi/encoding_spec.rb +++ b/optional/capi/encoding_spec.rb @@ -724,14 +724,16 @@ end describe "rb_define_dummy_encoding" do + run = 0 + it "defines the dummy encoding" do - @s.rb_define_dummy_encoding("FOO") - enc = Encoding.find("FOO") + @s.rb_define_dummy_encoding("FOO#{run += 1}") + enc = Encoding.find("FOO#{run}") enc.should.dummy? end it "returns the index of the dummy encoding" do - index = @s.rb_define_dummy_encoding("BAR") + index = @s.rb_define_dummy_encoding("BAR#{run += 1}") index.should == Encoding.list.size - 1 end diff --git a/optional/capi/globals_spec.rb b/optional/capi/globals_spec.rb index 48677620bc..4657293e15 100644 --- a/optional/capi/globals_spec.rb +++ b/optional/capi/globals_spec.rb @@ -41,14 +41,19 @@ @f.sb_get_global_value.should == "XYZ" end + run = 0 + it "rb_define_readonly_variable should define a new readonly global variable" do + name = "ro_gvar#{run += 1}" + eval <<~RUBY # Check the gvar doesn't exist and ensure rb_gv_get doesn't implicitly declare the gvar, # otherwise the rb_define_readonly_variable call will conflict. - suppress_warning { @f.sb_gv_get("ro_gvar") } .should == nil + suppress_warning { @f.sb_gv_get("#{name}") }.should == nil - @f.rb_define_readonly_variable("ro_gvar", 15) - $ro_gvar.should == 15 - -> { $ro_gvar = 10 }.should raise_error(NameError) + @f.rb_define_readonly_variable("#{name}", 15) + $#{name}.should == 15 + -> { $#{name} = 10 }.should raise_error(NameError) + RUBY end it "rb_define_hooked_variable should define a C hooked global variable" do diff --git a/optional/capi/module_spec.rb b/optional/capi/module_spec.rb index b7684e566b..af39ec0192 100644 --- a/optional/capi/module_spec.rb +++ b/optional/capi/module_spec.rb @@ -38,7 +38,7 @@ CApiModuleSpecs::C.const_set(:_INVALID, 1) }.should raise_error(NameError, /wrong constant name/) - @m.rb_const_set(CApiModuleSpecs::C, :_INVALID, 2) + suppress_warning { @m.rb_const_set(CApiModuleSpecs::C, :_INVALID, 2) } @m.rb_const_get(CApiModuleSpecs::C, :_INVALID).should == 2 # Ruby-level should still not allow access