-
-
Notifications
You must be signed in to change notification settings - Fork 396
[Ruby 3.4] Add spec for GC.config #1306
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
Merged
+83
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| require_relative '../../spec_helper' | ||
|
|
||
| ruby_version_is "3.4" do | ||
| describe "GC.config" do | ||
| context "without arguments" do | ||
| it "returns a hash of current settings" do | ||
| GC.config.should be_kind_of(Hash) | ||
| end | ||
|
|
||
| it "includes the name of currently loaded GC implementation as a global key" do | ||
| GC.config.should include(:implementation) | ||
| GC.config[:implementation].should be_kind_of(String) | ||
| end | ||
| end | ||
|
|
||
| context "with a hash of options" do | ||
| it "allows to set GC implementation's options" do | ||
| # Remove global keys which are read-only. | ||
| config = GC.config({}) | ||
| # Can't set anything if there are no options. | ||
| skip if config.empty? | ||
|
|
||
| # Try to find a boolean setting to reliably test changing it. | ||
| key, _value = config.find { |_k, v| v == true } | ||
| skip unless key | ||
|
|
||
| GC.config(key => false).should == config.merge(key => false) | ||
| GC.config[key].should == false | ||
| GC.config(key => true).should == config | ||
| GC.config[key].should == true | ||
| ensure | ||
| GC.config(config) | ||
| end | ||
|
|
||
| it "does not change settings that aren't present in the hash" do | ||
| GC.config({}).should == GC.config.except(:implementation) | ||
| end | ||
|
|
||
| it "ignores unknown keys" do | ||
| GC.config(foo: "bar").should == GC.config.except(:implementation) | ||
| end | ||
|
|
||
| it "raises an ArgumentError if options include global keys" do | ||
| -> { GC.config(implementation: "default") }.should raise_error(ArgumentError, 'Attempting to set read-only key "Implementation"') | ||
| end | ||
| end | ||
|
|
||
| context "with a non-hash argument" do | ||
| it "returns current settings if argument is nil" do | ||
| GC.config(nil).should == GC.config | ||
| end | ||
|
|
||
| it "raises ArgumentError for all other arguments" do | ||
| -> { GC.config([]) }.should raise_error(ArgumentError) | ||
| -> { GC.config("default") }.should raise_error(ArgumentError) | ||
| -> { GC.config(1) }.should raise_error(ArgumentError) | ||
| end | ||
| end | ||
|
|
||
| guard -> { PlatformGuard.standard? && GC.config[:implementation] == "default" } do | ||
| context "with default GC implementation on MRI" do | ||
| before do | ||
| @default_config = GC.config({}) | ||
| end | ||
|
|
||
| after do | ||
| GC.config(@default_config) | ||
| end | ||
|
|
||
| it "includes :rgengc_allow_full_mark option, true by default" do | ||
| GC.config.should include(:rgengc_allow_full_mark) | ||
| GC.config[:rgengc_allow_full_mark].should be_true | ||
| end | ||
|
|
||
| it "allows to set :rgengc_allow_full_mark" do | ||
| # This key maps truthy and falsey values to true and false. | ||
| GC.config(rgengc_allow_full_mark: nil).should == @default_config.merge(rgengc_allow_full_mark: false) | ||
| GC.config(rgengc_allow_full_mark: 1.23).should == @default_config | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out, the string uses Encoding::US_ASCII, not UTF-8. Should this be specified?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter much, they are interchangeable (so I think not)