summaryrefslogtreecommitdiff
path: root/spec/ruby/optional
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2022-04-25 14:53:54 +0200
committerBenoit Daloze <[email protected]>2022-04-25 14:53:54 +0200
commit45cf4f218728a15eb36d14a6c9912086525f5e3f (patch)
tree2aa93fadcb904c226f722dde47827098b87a9846 /spec/ruby/optional
parent6ae81d49b52563a6720d666a6118ffa6e484f398 (diff)
Update to ruby/spec@3affe1e
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb10
-rw-r--r--spec/ruby/optional/capi/object_spec.rb77
-rw-r--r--spec/ruby/optional/capi/proc_spec.rb28
-rw-r--r--spec/ruby/optional/capi/shared/rbasic.rb34
-rw-r--r--spec/ruby/optional/capi/string_spec.rb53
-rw-r--r--spec/ruby/optional/capi/util_spec.rb19
6 files changed, 13 insertions, 208 deletions
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb
index 88545265d0..d1e3e03582 100644
--- a/spec/ruby/optional/capi/kernel_spec.rb
+++ b/spec/ruby/optional/capi/kernel_spec.rb
@@ -412,12 +412,10 @@ describe "C-API Kernel function" do
}.should raise_error(Exception, 'custom error')
end
- ruby_bug "#17305", ""..."2.7" do
- it "raises TypeError if one of the passed exceptions is not a Module" do
- -> {
- @s.rb_rescue2(-> *_ { raise RuntimeError, "foo" }, :no_exc, -> x { x }, :exc, Object.new, 42)
- }.should raise_error(TypeError, /class or module required/)
- end
+ it "raises TypeError if one of the passed exceptions is not a Module" do
+ -> {
+ @s.rb_rescue2(-> *_ { raise RuntimeError, "foo" }, :no_exc, -> x { x }, :exc, Object.new, 42)
+ }.should raise_error(TypeError, /class or module required/)
end
end
diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb
index 8791a4bc76..294247910b 100644
--- a/spec/ruby/optional/capi/object_spec.rb
+++ b/spec/ruby/optional/capi/object_spec.rb
@@ -438,15 +438,6 @@ describe "CApiObject" do
end
describe "FL_TEST" do
- ruby_version_is ''...'2.7' do
- it "returns correct status for FL_TAINT" do
- obj = Object.new
- @o.FL_TEST(obj, "FL_TAINT").should == 0
- obj.taint
- @o.FL_TEST(obj, "FL_TAINT").should_not == 0
- end
- end
-
it "returns correct status for FL_FREEZE" do
obj = Object.new
@o.FL_TEST(obj, "FL_FREEZE").should == 0
@@ -636,68 +627,12 @@ describe "CApiObject" do
end
describe "OBJ_TAINT" do
- ruby_version_is ''...'2.7' do
- it "taints the object" do
- obj = mock("tainted")
- @o.OBJ_TAINT(obj)
- obj.tainted?.should be_true
- end
- end
end
describe "OBJ_TAINTED" do
- ruby_version_is ''...'2.7' do
- it "returns C true if the object is tainted" do
- obj = mock("tainted")
- obj.taint
- @o.OBJ_TAINTED(obj).should be_true
- end
-
- it "returns C false if the object is not tainted" do
- obj = mock("untainted")
- @o.OBJ_TAINTED(obj).should be_false
- end
- end
end
describe "OBJ_INFECT" do
- ruby_version_is ''...'2.7' do
- it "does not taint the first argument if the second argument is not tainted" do
- host = mock("host")
- source = mock("source")
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_false
- end
-
- it "taints the first argument if the second argument is tainted" do
- host = mock("host")
- source = mock("source").taint
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_true
- end
-
- it "does not untrust the first argument if the second argument is trusted" do
- host = mock("host")
- source = mock("source")
- @o.OBJ_INFECT(host, source)
- host.untrusted?.should be_false
- end
-
- it "untrusts the first argument if the second argument is untrusted" do
- host = mock("host")
- source = mock("source").untrust
- @o.OBJ_INFECT(host, source)
- host.untrusted?.should be_true
- end
-
- it "propagates both taint and distrust" do
- host = mock("host")
- source = mock("source").taint.untrust
- @o.OBJ_INFECT(host, source)
- host.tainted?.should be_true
- host.untrusted?.should be_true
- end
- end
end
describe "rb_obj_freeze" do
@@ -731,18 +666,6 @@ describe "CApiObject" do
end
describe "rb_obj_taint" do
- ruby_version_is ''...'2.7' do
- it "marks the object passed as tainted" do
- obj = ""
- obj.should_not.tainted?
- @o.rb_obj_taint(obj)
- obj.should.tainted?
- end
-
- it "raises a FrozenError if the object passed is frozen" do
- -> { @o.rb_obj_taint("".freeze) }.should raise_error(FrozenError)
- end
- end
end
describe "rb_check_frozen" do
diff --git a/spec/ruby/optional/capi/proc_spec.rb b/spec/ruby/optional/capi/proc_spec.rb
index dab143fbe7..c839665ae9 100644
--- a/spec/ruby/optional/capi/proc_spec.rb
+++ b/spec/ruby/optional/capi/proc_spec.rb
@@ -115,20 +115,6 @@ describe "C-API when calling Proc.new from a C function" do
# For example: C -> Ruby <- C -> Ruby means a C function called into Ruby
# code which returned to C, then C called into Ruby code again.
- ruby_version_is ""..."2.7" do
- # Ruby -> C -> rb_funcall(Proc.new)
- it "returns the Proc passed by the Ruby code calling the C function" do
- prc = @p.rb_Proc_new(0) { :called }
- prc.call.should == :called
- end
-
- # Ruby -> C -> Ruby <- C -> rb_funcall(Proc.new)
- it "returns the Proc passed to the Ruby method when the C function calls other Ruby methods before calling Proc.new" do
- prc = @p.rb_Proc_new(1) { :called }
- prc.call.should == :called
- end
- end
-
# Ruby -> C -> Ruby -> Proc.new
it "raises an ArgumentError when the C function calls a Ruby method that calls Proc.new" do
-> {
@@ -142,20 +128,6 @@ describe "C-API when calling Proc.new from a C function" do
-> { @p.rb_Proc_new(3) { :called } }.should raise_error(ArgumentError)
end
- ruby_version_is ""..."2.7" do
- # Ruby -> C -> Ruby -> C (with new block) -> rb_funcall(Proc.new)
- it "returns the most recent Proc passed when the Ruby method called the C function" do
- prc = @p.rb_Proc_new(4) { :called }
- prc.call.should == :calling_with_block
- end
-
- # Ruby -> C -> Ruby -> C (with new block) <- Ruby <- C -> # rb_funcall(Proc.new)
- it "returns the Proc passed from the original Ruby call to the C function" do
- prc = @p.rb_Proc_new(5) { :called }
- prc.call.should == :called
- end
- end
-
# Ruby -> C -> Ruby -> block_given?
it "returns false from block_given? in a Ruby method called by the C function" do
@p.rb_Proc_new(6).should be_false
diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb
index 5ef63e81e3..99c2044bd7 100644
--- a/spec/ruby/optional/capi/shared/rbasic.rb
+++ b/spec/ruby/optional/capi/shared/rbasic.rb
@@ -20,40 +20,6 @@ describe :rbasic, shared: true do
obj.should.frozen?
end
- ruby_version_is ""..."2.7" do
- it "reports the appropriate FREEZE and TAINT flags for the object when reading" do
- obj, _ = @data.call
- initial = @specs.get_flags(obj)
- obj.taint
- @specs.get_flags(obj).should == @taint | initial
- obj.untaint
- @specs.get_flags(obj).should == initial
- obj.freeze
- @specs.get_flags(obj).should == @freeze | initial
-
- obj, _ = @data.call
- obj.taint
- obj.freeze
- @specs.get_flags(obj).should == @freeze | @taint | initial
- end
-
- it "supports setting the FREEZE and TAINT flags" do
- obj, _ = @data.call
- initial = @specs.get_flags(obj)
- @specs.set_flags(obj, @taint | initial).should == @taint | initial
- obj.should.tainted?
- @specs.set_flags(obj, initial).should == initial
- obj.should_not.tainted?
- @specs.set_flags(obj, @freeze | initial).should == @freeze | initial
- obj.should.frozen?
-
- obj, _ = @data.call
- @specs.set_flags(obj, @freeze | @taint | initial).should == @freeze | @taint | initial
- obj.should.tainted?
- obj.should.frozen?
- end
- end
-
it "supports retrieving the (meta)class" do
obj, _ = @data.call
@specs.get_klass(obj).should == obj.class
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 9291630ace..7ad4d10ee4 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -181,12 +181,6 @@ describe "C-API String function" do
@s.rb_str_new("hello", 3).should == "hel"
end
- ruby_version_is ''...'2.7' do
- it "returns a non-tainted string" do
- @s.rb_str_new("hello", 5).should_not.tainted?
- end
- end
-
it "returns an empty string if len is 0" do
@s.rb_str_new("hello", 0).should == ""
end
@@ -335,24 +329,6 @@ describe "C-API String function" do
end
end
- ruby_version_is ''...'2.7' do
- describe "rb_tainted_str_new" do
- it "creates a new tainted String" do
- newstring = @s.rb_tainted_str_new("test", 4)
- newstring.should == "test"
- newstring.tainted?.should be_true
- end
- end
-
- describe "rb_tainted_str_new2" do
- it "creates a new tainted String" do
- newstring = @s.rb_tainted_str_new2("test")
- newstring.should == "test"
- newstring.tainted?.should be_true
- end
- end
- end
-
describe "rb_str_append" do
it "appends a string to another string" do
@s.rb_str_append("Hello", " Goodbye").should == "Hello Goodbye"
@@ -665,22 +641,6 @@ describe "C-API String function" do
end
describe "SafeStringValue" do
- ruby_version_is ''...'2.7' do
- it "raises for tained string when $SAFE is 1" do
- begin
- Thread.new {
- $SAFE = 1
- -> {
- @s.SafeStringValue("str".taint)
- }.should raise_error(SecurityError)
- }.join
- ensure
- $SAFE = 0
- end
- end
-
- it_behaves_like :string_value_macro, :SafeStringValue
- end
end
describe "rb_str_modify" do
@@ -810,12 +770,6 @@ describe :rb_external_str_new, shared: true do
x80 = [0x80].pack('C')
@s.send(@method, "#{x80}abc").encoding.should == Encoding::BINARY
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted String" do
- @s.send(@method, "abc").tainted?.should be_true
- end
- end
end
describe "C-API String function" do
@@ -895,13 +849,6 @@ describe "C-API String function" do
s.should == x
s.encoding.should equal(Encoding::EUC_JP)
end
-
- ruby_version_is ''...'2.7' do
- it "returns a tainted String" do
- s = @s.rb_external_str_new_with_enc("abc", 3, Encoding::US_ASCII)
- s.tainted?.should be_true
- end
- end
end
describe "rb_locale_str_new" do
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb
index a90c28a78e..64b0894087 100644
--- a/spec/ruby/optional/capi/util_spec.rb
+++ b/spec/ruby/optional/capi/util_spec.rb
@@ -11,7 +11,6 @@ describe "C-API Util function" do
before :each do
@prc = -> { 1 }
@acc = []
- @keyword_prefix = 'k' if RUBY_VERSION >= '2.7'
ScratchPad.record @acc
end
@@ -100,13 +99,13 @@ describe "C-API Util function" do
it "assigns Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0
+ @o.rb_scan_args([h], "k0:", 1, @acc).should == 0
ScratchPad.recorded.should == [h]
end
it "assigns required and Hash arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1
+ @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1
ScratchPad.recorded.should == [1, h]
end
@@ -140,7 +139,7 @@ describe "C-API Util function" do
it "assigns required, optional, splat, post-splat, Hash and block arguments" do
h = {a: 1, b: 2}
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5
ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc]
end
@@ -150,7 +149,7 @@ describe "C-API Util function" do
h = {1 => 2, 3 => 4}
-> {
suppress_warning do
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc)
+ @o.rb_scan_args([h], "k0:", 1, @acc)
end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
@@ -160,7 +159,7 @@ describe "C-API Util function" do
h = {1 => 2, 3 => 4}
-> {
suppress_warning do
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc)
+ @o.rb_scan_args([1, h], "k1:", 2, @acc)
end
}.should raise_error(ArgumentError)
ScratchPad.recorded.should == []
@@ -169,7 +168,7 @@ describe "C-API Util function" do
it "considers the hash as a post argument when there is a splat" do
h = {1 => 2, 3 => 4}
suppress_warning do
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 6
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 6
end
ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc]
end
@@ -178,19 +177,19 @@ describe "C-API Util function" do
ruby_version_is '3.0' do
it "does not reject non-symbol keys in keyword arguments" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0
+ @o.rb_scan_args([h], "k0:", 1, @acc).should == 0
ScratchPad.recorded.should == [h]
end
it "does not reject non-symbol keys in keyword arguments with required argument" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1
+ @o.rb_scan_args([1, h], "k1:", 2, @acc).should == 1
ScratchPad.recorded.should == [1, h]
end
it "considers keyword arguments with non-symbol keys as keywords when using splat and post arguments" do
h = {1 => 2, 3 => 4}
- @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5
+ @o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5
ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc]
end
end