From 8916178085e0615ee93eee15adb40a9bcf8356f1 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 27 Nov 2023 18:23:20 +0100 Subject: [PATCH 1/3] Update to ruby/spec@c3206f6 --- spec/ruby/core/array/assoc_spec.rb | 12 ++++++ spec/ruby/core/array/rassoc_spec.rb | 12 ++++++ spec/ruby/core/file/new_spec.rb | 2 +- spec/ruby/core/file/open_spec.rb | 6 +-- spec/ruby/core/io/read_spec.rb | 26 ++++++++++++ spec/ruby/core/kernel/Integer_spec.rb | 15 +++++++ spec/ruby/language/singleton_class_spec.rb | 7 ++++ spec/ruby/library/English/English_spec.rb | 16 +++---- spec/ruby/library/date/iso8601_spec.rb | 21 ++++++++++ spec/ruby/library/date/shared/parse.rb | 4 +- spec/ruby/library/date/shared/parse_eu.rb | 8 ++-- spec/ruby/library/date/shared/parse_us.rb | 8 ++-- .../library/digest/instance/shared/update.rb | 2 +- spec/ruby/library/etc/uname_spec.rb | 14 +++++++ .../fixed_length_secure_compare_spec.rb | 42 +++++++++++++++++++ .../library/openssl/kdf/pbkdf2_hmac_spec.rb | 16 ------- spec/ruby/library/openssl/kdf/scrypt_spec.rb | 2 +- .../library/openssl/secure_compare_spec.rb | 38 +++++++++++++++++ .../x509/{name => store}/verify_spec.rb | 2 +- spec/ruby/library/yaml/dump_spec.rb | 14 ++++--- spec/ruby/library/yaml/dump_stream_spec.rb | 3 +- spec/ruby/library/yaml/fixtures/common.rb | 4 -- spec/ruby/library/yaml/load_file_spec.rb | 13 ++++-- spec/ruby/library/yaml/load_stream_spec.rb | 3 +- spec/ruby/library/yaml/parse_file_spec.rb | 8 ++-- spec/ruby/library/yaml/parse_spec.rb | 7 ++-- .../ruby/library/yaml/shared/each_document.rb | 3 +- spec/ruby/library/yaml/shared/load.rb | 10 +++-- spec/ruby/library/yaml/to_yaml_spec.rb | 20 +++++++-- spec/ruby/optional/capi/ext/encoding_spec.c | 2 +- spec/ruby/shared/sizedqueue/enque.rb | 2 +- 31 files changed, 271 insertions(+), 71 deletions(-) create mode 100644 spec/ruby/library/etc/uname_spec.rb create mode 100644 spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb create mode 100644 spec/ruby/library/openssl/secure_compare_spec.rb rename spec/ruby/library/openssl/x509/{name => store}/verify_spec.rb (98%) delete mode 100644 spec/ruby/library/yaml/fixtures/common.rb diff --git a/spec/ruby/core/array/assoc_spec.rb b/spec/ruby/core/array/assoc_spec.rb index af9552828187..f0be3de79578 100644 --- a/spec/ruby/core/array/assoc_spec.rb +++ b/spec/ruby/core/array/assoc_spec.rb @@ -37,4 +37,16 @@ a.assoc(s1.first).should equal(s1) a.assoc(s2.first).should equal(s2) end + + it "calls to_ary on non-array elements" do + s1 = [1, 2] + s2 = ArraySpecs::ArrayConvertible.new(2, 3) + a = [s1, s2] + + s1.should_not_receive(:to_ary) + a.assoc(s1.first).should equal(s1) + + a.assoc(2).should == [2, 3] + s2.called.should equal(:to_ary) + end end diff --git a/spec/ruby/core/array/rassoc_spec.rb b/spec/ruby/core/array/rassoc_spec.rb index 62fbd40611fe..ed2851f1952c 100644 --- a/spec/ruby/core/array/rassoc_spec.rb +++ b/spec/ruby/core/array/rassoc_spec.rb @@ -35,4 +35,16 @@ def o.==(other); other == 'foobar'; end [[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1] end + + it "does not call to_ary on non-array elements" do + s1 = [1, 2] + s2 = ArraySpecs::ArrayConvertible.new(2, 3) + a = [s1, s2] + + s1.should_not_receive(:to_ary) + a.rassoc(2).should equal(s1) + + s2.should_not_receive(:to_ary) + a.rassoc(3).should equal(nil) + end end diff --git a/spec/ruby/core/file/new_spec.rb b/spec/ruby/core/file/new_spec.rb index 3e2641aed3e1..1e82a070b10d 100644 --- a/spec/ruby/core/file/new_spec.rb +++ b/spec/ruby/core/file/new_spec.rb @@ -100,7 +100,7 @@ File.should.exist?(@file) end - it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do + it "raises an Errno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do -> { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST) end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 4c41f70e12b3..6bfc16bbf977 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -354,7 +354,7 @@ end end - it "raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do + it "raises an Errno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do -> { File.open(@file, File::CREAT|File::EXCL) do |f| f.puts("writing") @@ -423,7 +423,7 @@ }.should raise_error(IOError) end - it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do + it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do -> { File.open(@file, File::RDONLY|File::TRUNC) do |f| f.puts("writing").should == nil @@ -441,7 +441,7 @@ }.should raise_error(Errno::EINVAL) end - it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do + it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do -> { File.open(@file, File::RDONLY|File::TRUNC) do |f| f.puts("writing").should == nil diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index 996f70bf2090..db11468ea4b0 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -299,6 +299,32 @@ @io.read(10, buf).should == nil buf.should == '' + + buf = 'non-empty string' + + @io.read(nil, buf).should == "" + + buf.should == '' + + buf = 'non-empty string' + + @io.read(0, buf).should == "" + + buf.should == '' + end + + it "raise FrozenError if the output buffer is frozen" do + @io.read + -> { @io.read(0, 'frozen-string'.freeze) }.should raise_error(FrozenError) + -> { @io.read(1, 'frozen-string'.freeze) }.should raise_error(FrozenError) + -> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError) + end + + ruby_bug "", ""..."3.3" do + it "raise FrozenError if the output buffer is frozen (2)" do + @io.read + -> { @io.read(1, ''.freeze) }.should raise_error(FrozenError) + end end it "consumes zero bytes when reading zero bytes" do diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb index c37733e88d21..74dd3e0dd2ef 100644 --- a/spec/ruby/core/kernel/Integer_spec.rb +++ b/spec/ruby/core/kernel/Integer_spec.rb @@ -586,6 +586,21 @@ Integer("777", obj).should == 0777 end + # https://bugs.ruby-lang.org/issues/19349 + ruby_version_is ''...'3.3' do + it "ignores the base if it is not an integer and does not respond to #to_i" do + Integer("777", "8").should == 777 + end + end + + ruby_version_is '3.3' do + it "raises a TypeError if it is not an integer and does not respond to #to_i" do + -> { + Integer("777", "8") + }.should raise_error(TypeError, "no implicit conversion of String into Integer") + end + end + describe "when passed exception: false" do describe "and valid argument" do it "returns an Integer number" do diff --git a/spec/ruby/language/singleton_class_spec.rb b/spec/ruby/language/singleton_class_spec.rb index 7512f0eb398f..9d037717b24c 100644 --- a/spec/ruby/language/singleton_class_spec.rb +++ b/spec/ruby/language/singleton_class_spec.rb @@ -307,4 +307,11 @@ def singleton_method; 1 end o.freeze klass.frozen?.should == true end + + it "will be unfrozen if the frozen object is cloned with freeze set to false" do + o = Object.new + o.freeze + o2 = o.clone(freeze: false) + o2.singleton_class.frozen?.should == false + end end diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb index 480602d5e593..4d615d1e2506 100644 --- a/spec/ruby/library/English/English_spec.rb +++ b/spec/ruby/library/English/English_spec.rb @@ -130,13 +130,15 @@ $LAST_MATCH_INFO.should == $~ end - it "aliases $IGNORECASE to $=" do - $VERBOSE, verbose = nil, $VERBOSE - begin - $IGNORECASE.should_not be_nil - $IGNORECASE.should == $= - ensure - $VERBOSE = verbose + ruby_version_is ""..."3.3" do + it "aliases $IGNORECASE to $=" do + $VERBOSE, verbose = nil, $VERBOSE + begin + $IGNORECASE.should_not be_nil + $IGNORECASE.should == $= + ensure + $VERBOSE = verbose + end end end diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb index a29652014ec2..af66845a6b4f 100644 --- a/spec/ruby/library/date/iso8601_spec.rb +++ b/spec/ruby/library/date/iso8601_spec.rb @@ -22,6 +22,18 @@ d.should == Date.civil(-4712, 1, 1) end + it "raises a Date::Error if the argument is a invalid Date" do + -> { + Date.iso8601('invalid') + }.should raise_error(Date::Error, "invalid date") + end + + it "raises a Date::Error when passed a nil" do + -> { + Date.iso8601(nil) + }.should raise_error(Date::Error, "invalid date") + end + it "raises a TypeError when passed an Object" do -> { Date.iso8601(Object.new) }.should raise_error(TypeError) end @@ -32,4 +44,13 @@ h = Date._iso8601('invalid') h.should == {} end + + it "returns an empty hash if the argument is nil" do + h = Date._iso8601(nil) + h.should == {} + end + + it "raises a TypeError when passed an Object" do + -> { Date._iso8601(Object.new) }.should raise_error(TypeError) + end end diff --git a/spec/ruby/library/date/shared/parse.rb b/spec/ruby/library/date/shared/parse.rb index 1015285e048c..40af908386c9 100644 --- a/spec/ruby/library/date/shared/parse.rb +++ b/spec/ruby/library/date/shared/parse.rb @@ -13,7 +13,7 @@ d.day.should == 23 end - it "can parse a 'mmm DD YYYY' string into a Date object" do + it "can parse a 'DD mmm YYYY' string into a Date object" do d = Date.parse("23#{@sep}feb#{@sep}2008") d.year.should == 2008 d.month.should == 2 @@ -42,7 +42,7 @@ d.should == Date.civil(2005, 11, 5) end - it "can parse a year, day and month name into a Date object" do + it "can parse a day, month name and year into a Date object" do d = Date.parse("5th#{@sep}november#{@sep}2005") d.should == Date.civil(2005, 11, 5) end diff --git a/spec/ruby/library/date/shared/parse_eu.rb b/spec/ruby/library/date/shared/parse_eu.rb index ecb15e3c0e4f..3819524a571e 100644 --- a/spec/ruby/library/date/shared/parse_eu.rb +++ b/spec/ruby/library/date/shared/parse_eu.rb @@ -7,28 +7,28 @@ d.day.should == 1 end - it "can parse a MM-DD-YYYY string into a Date object" do + it "can parse a DD-MM-YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "can parse a MM-DD-YY string into a Date object" do + it "can parse a YY-MM-DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do + it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/date/shared/parse_us.rb b/spec/ruby/library/date/shared/parse_us.rb index 7be62b1af1fc..17e2fc96c18a 100644 --- a/spec/ruby/library/date/shared/parse_us.rb +++ b/spec/ruby/library/date/shared/parse_us.rb @@ -6,28 +6,28 @@ d.day.should == 1 end - it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do + it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}2007") d.year.should == 2007 d.month.should == 1 d.day.should == 10 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do d = Date.parse("10#{@sep}01#{@sep}07") d.year.should == 2010 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", false) d.year.should == 10 d.month.should == 1 d.day.should == 7 end - it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do + it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do d = Date.parse("10#{@sep}01#{@sep}07", true) d.year.should == 2010 d.month.should == 1 diff --git a/spec/ruby/library/digest/instance/shared/update.rb b/spec/ruby/library/digest/instance/shared/update.rb index dccc8f80dfd6..17779e54a48f 100644 --- a/spec/ruby/library/digest/instance/shared/update.rb +++ b/spec/ruby/library/digest/instance/shared/update.rb @@ -3,6 +3,6 @@ c = Class.new do include Digest::Instance end - -> { c.new.update("test") }.should raise_error(RuntimeError) + -> { c.new.send(@method, "test") }.should raise_error(RuntimeError) end end diff --git a/spec/ruby/library/etc/uname_spec.rb b/spec/ruby/library/etc/uname_spec.rb new file mode 100644 index 000000000000..a42558f5932b --- /dev/null +++ b/spec/ruby/library/etc/uname_spec.rb @@ -0,0 +1,14 @@ +require_relative '../../spec_helper' +require 'etc' + +describe "Etc.uname" do + it "returns a Hash with the documented keys" do + uname = Etc.uname + uname.should be_kind_of(Hash) + uname.should.key?(:sysname) + uname.should.key?(:nodename) + uname.should.key?(:release) + uname.should.key?(:version) + uname.should.key?(:machine) + end +end diff --git a/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb new file mode 100644 index 000000000000..5a2ca168b536 --- /dev/null +++ b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb @@ -0,0 +1,42 @@ +require_relative '../../spec_helper' +require 'openssl' + +describe "OpenSSL.fixed_length_secure_compare" do + it "returns true for two strings with the same content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox jumps over the lazy dog" + OpenSSL.fixed_length_secure_compare(input1, input2).should be_true + end + + it "returns false for two strings of equal size with different content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the lazy dog jumps over the quick brown fox" + OpenSSL.fixed_length_secure_compare(input1, input2).should be_false + end + + it "converts both arguments to strings using #to_str" do + input1 = mock("input1") + input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + input2 = mock("input2") + input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.fixed_length_secure_compare(input1, input2).should be_true + end + + it "does not accept arguments that are not string and cannot be coerced into strings" do + -> { + OpenSSL.fixed_length_secure_compare("input1", :input2) + }.should raise_error(TypeError, 'no implicit conversion of Symbol into String') + + -> { + OpenSSL.fixed_length_secure_compare(Object.new, "input2") + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end + + it "raises an ArgumentError for two strings of different size" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox" + -> { + OpenSSL.fixed_length_secure_compare(input1, input2) + }.should raise_error(ArgumentError, 'inputs must be of equal length') + end +end diff --git a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb index ebf71482de19..40f85972759a 100644 --- a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb +++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb @@ -154,22 +154,6 @@ }.should raise_error(ArgumentError, 'missing keywords: :salt, :iterations, :length, :hash') end - - guard -> { OpenSSL::OPENSSL_VERSION_NUMBER < 0x30000000 } do - it "treats 0 or less iterations as a single iteration" do - salt = "\x00".b * 16 - length = 16 - hash = "sha1" - - # "Any iter less than 1 is treated as a single iteration." - key0 = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 0) - key_negative = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: -1) - key1 = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 1) - key0.should == key1 - key_negative.should == key1 - end - end - guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 } do it "raises an OpenSSL::KDF::KDFError for 0 or less iterations" do -> { diff --git a/spec/ruby/library/openssl/kdf/scrypt_spec.rb b/spec/ruby/library/openssl/kdf/scrypt_spec.rb index 12ccf04f6ffa..5dc9f2f281e6 100644 --- a/spec/ruby/library/openssl/kdf/scrypt_spec.rb +++ b/spec/ruby/library/openssl/kdf/scrypt_spec.rb @@ -1,7 +1,7 @@ require_relative '../../../spec_helper' require 'openssl' -guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000 } do +guard -> { OpenSSL::KDF.respond_to?(:scrypt) } do describe "OpenSSL::KDF.scrypt" do before :each do @defaults = { diff --git a/spec/ruby/library/openssl/secure_compare_spec.rb b/spec/ruby/library/openssl/secure_compare_spec.rb new file mode 100644 index 000000000000..cec48e01e7b7 --- /dev/null +++ b/spec/ruby/library/openssl/secure_compare_spec.rb @@ -0,0 +1,38 @@ +require_relative '../../spec_helper' +require 'openssl' + +describe "OpenSSL.secure_compare" do + it "returns true for two strings with the same content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the quick brown fox jumps over the lazy dog" + OpenSSL.secure_compare(input1, input2).should be_true + end + + it "returns false for two strings with different content" do + input1 = "the quick brown fox jumps over the lazy dog" + input2 = "the lazy dog jumps over the quick brown fox" + OpenSSL.secure_compare(input1, input2).should be_false + end + + it "converts both arguments to strings using #to_str, but adds equality check for the original objects" do + input1 = mock("input1") + input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + input2 = mock("input2") + input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.secure_compare(input1, input2).should be_false + + input = mock("input") + input.should_receive(:to_str).twice.and_return("the quick brown fox jumps over the lazy dog") + OpenSSL.secure_compare(input, input).should be_true + end + + it "does not accept arguments that are not string and cannot be coerced into strings" do + -> { + OpenSSL.secure_compare("input1", :input2) + }.should raise_error(TypeError, 'no implicit conversion of Symbol into String') + + -> { + OpenSSL.secure_compare(Object.new, "input2") + }.should raise_error(TypeError, 'no implicit conversion of Object into String') + end +end diff --git a/spec/ruby/library/openssl/x509/name/verify_spec.rb b/spec/ruby/library/openssl/x509/store/verify_spec.rb similarity index 98% rename from spec/ruby/library/openssl/x509/name/verify_spec.rb rename to spec/ruby/library/openssl/x509/store/verify_spec.rb index 6dcfc994663a..6a6a53d992b1 100644 --- a/spec/ruby/library/openssl/x509/name/verify_spec.rb +++ b/spec/ruby/library/openssl/x509/store/verify_spec.rb @@ -1,7 +1,7 @@ require_relative '../../../../spec_helper' require 'openssl' -describe "OpenSSL::X509::Name.verify" do +describe "OpenSSL::X509::Store#verify" do it "returns true for valid certificate" do key = OpenSSL::PKey::RSA.new 2048 cert = OpenSSL::X509::Certificate.new diff --git a/spec/ruby/library/yaml/dump_spec.rb b/spec/ruby/library/yaml/dump_spec.rb index 3107a8f51d32..ea94b2f8565b 100644 --- a/spec/ruby/library/yaml/dump_spec.rb +++ b/spec/ruby/library/yaml/dump_spec.rb @@ -1,17 +1,21 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -# TODO: WTF is this using a global? +require 'yaml' + describe "YAML.dump" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + rm_r @test_file end it "converts an object to YAML and write result to io when io provided" do - File.open($test_file, 'w' ) do |io| + File.open(@test_file, 'w' ) do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - YAML.load_file($test_file).should == ['badger', 'elephant', 'tiger'] + YAML.load_file(@test_file).should == ['badger', 'elephant', 'tiger'] end it "returns a string containing dumped YAML when no io provided" do diff --git a/spec/ruby/library/yaml/dump_stream_spec.rb b/spec/ruby/library/yaml/dump_stream_spec.rb index 9d30fef819e5..f0578fa800e8 100644 --- a/spec/ruby/library/yaml/dump_stream_spec.rb +++ b/spec/ruby/library/yaml/dump_stream_spec.rb @@ -1,5 +1,6 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.dump_stream" do it "returns a YAML stream containing the objects passed" do diff --git a/spec/ruby/library/yaml/fixtures/common.rb b/spec/ruby/library/yaml/fixtures/common.rb deleted file mode 100644 index 895213b844f0..000000000000 --- a/spec/ruby/library/yaml/fixtures/common.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'yaml' - -$test_file = tmp("yaml_test_file") -$test_parse_file = __dir__ + "/test_yaml.yml" diff --git a/spec/ruby/library/yaml/load_file_spec.rb b/spec/ruby/library/yaml/load_file_spec.rb index 2363c0812086..4941d0485b3c 100644 --- a/spec/ruby/library/yaml/load_file_spec.rb +++ b/spec/ruby/library/yaml/load_file_spec.rb @@ -1,13 +1,18 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' + +require 'yaml' describe "YAML.load_file" do + before :each do + @test_file = tmp("yaml_test_file") + end + after :each do - rm_r $test_file + rm_r @test_file end it "returns a hash" do - File.open($test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } - YAML.load_file($test_file).should == {"bar"=>2, "car"=>1} + File.open(@test_file,'w' ){|io| YAML.dump( {"bar"=>2, "car"=>1}, io ) } + YAML.load_file(@test_file).should == {"bar"=>2, "car"=>1} end end diff --git a/spec/ruby/library/yaml/load_stream_spec.rb b/spec/ruby/library/yaml/load_stream_spec.rb index 689653c8cd64..31bc862f5e74 100644 --- a/spec/ruby/library/yaml/load_stream_spec.rb +++ b/spec/ruby/library/yaml/load_stream_spec.rb @@ -1,8 +1,9 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/strings' require_relative 'shared/each_document' +require 'yaml' + describe "YAML.load_stream" do it_behaves_like :yaml_each_document, :load_stream end diff --git a/spec/ruby/library/yaml/parse_file_spec.rb b/spec/ruby/library/yaml/parse_file_spec.rb index 8c59a2d7ef8b..7bffcdc62f9b 100644 --- a/spec/ruby/library/yaml/parse_file_spec.rb +++ b/spec/ruby/library/yaml/parse_file_spec.rb @@ -1,8 +1,10 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse_file" do +require 'yaml' + +describe "YAML.parse_file" do it "returns a YAML::Syck::Map object after parsing a YAML file" do - YAML.parse_file($test_parse_file).should be_kind_of(Psych::Nodes::Document) + test_parse_file = fixture __FILE__, "test_yaml.yml" + YAML.parse_file(test_parse_file).should be_kind_of(Psych::Nodes::Document) end end diff --git a/spec/ruby/library/yaml/parse_spec.rb b/spec/ruby/library/yaml/parse_spec.rb index d5dbfdcee25e..37e2b7fa0a54 100644 --- a/spec/ruby/library/yaml/parse_spec.rb +++ b/spec/ruby/library/yaml/parse_spec.rb @@ -1,13 +1,14 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' -describe "YAML#parse with an empty string" do +require 'yaml' + +describe "YAML.parse with an empty string" do it "returns false" do YAML.parse('').should be_false end end -describe "YAML#parse" do +describe "YAML.parse" do before :each do @string_yaml = "foo".to_yaml end diff --git a/spec/ruby/library/yaml/shared/each_document.rb b/spec/ruby/library/yaml/shared/each_document.rb index 999123dc2a4d..7d32c6001fc6 100644 --- a/spec/ruby/library/yaml/shared/each_document.rb +++ b/spec/ruby/library/yaml/shared/each_document.rb @@ -9,7 +9,8 @@ end it "works on files" do - File.open($test_parse_file, "r") do |file| + test_parse_file = fixture __FILE__, "test_yaml.yml" + File.open(test_parse_file, "r") do |file| YAML.send(@method, file) do |doc| doc.should == {"project"=>{"name"=>"RubySpec"}} end diff --git a/spec/ruby/library/yaml/shared/load.rb b/spec/ruby/library/yaml/shared/load.rb index 185a5a60cd9d..1ebe08be2c2c 100644 --- a/spec/ruby/library/yaml/shared/load.rb +++ b/spec/ruby/library/yaml/shared/load.rb @@ -1,14 +1,16 @@ -require_relative '../fixtures/common' require_relative '../fixtures/strings' +require 'yaml' + describe :yaml_load_safe, shared: true do it "returns a document from current io stream when io provided" do - File.open($test_file, 'w') do |io| + @test_file = tmp("yaml_test_file") + File.open(@test_file, 'w') do |io| YAML.dump( ['badger', 'elephant', 'tiger'], io ) end - File.open($test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] + File.open(@test_file) { |yf| YAML.send(@method, yf ) }.should == ['badger', 'elephant', 'tiger'] ensure - rm_r $test_file + rm_r @test_file end it "loads strings" do diff --git a/spec/ruby/library/yaml/to_yaml_spec.rb b/spec/ruby/library/yaml/to_yaml_spec.rb index 8e80b02cb453..547009c94233 100644 --- a/spec/ruby/library/yaml/to_yaml_spec.rb +++ b/spec/ruby/library/yaml/to_yaml_spec.rb @@ -1,7 +1,8 @@ require_relative '../../spec_helper' -require_relative 'fixtures/common' require_relative 'fixtures/example_class' +require 'yaml' + describe "Object#to_yaml" do it "returns the YAML representation of an Array object" do @@ -12,13 +13,21 @@ { "a" => "b"}.to_yaml.should match_yaml("--- \na: b\n") end - it "returns the YAML representation of a Class object" do + it "returns the YAML representation of an object" do YAMLSpecs::Example.new("baz").to_yaml.should match_yaml("--- !ruby/object:YAMLSpecs::Example\nname: baz\n") end + it "returns the YAML representation of a Class object" do + YAMLSpecs::Example.to_yaml.should match_yaml("--- !ruby/class 'YAMLSpecs::Example'\n") + end + + it "returns the YAML representation of a Module object" do + Enumerable.to_yaml.should match_yaml("--- !ruby/module 'Enumerable'\n") + end + it "returns the YAML representation of a Date object" do require 'date' - Date.parse('1997/12/30').to_yaml.should match_yaml("--- 1997-12-30\n") + Date.new(1997, 12, 30).to_yaml.should match_yaml("--- 1997-12-30\n") end it "returns the YAML representation of a FalseClass" do @@ -58,6 +67,11 @@ Person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct:Person\nname: Jane\ngender: female\n") end + it "returns the YAML representation of an unnamed Struct object" do + person = Struct.new(:name, :gender) + person.new("Jane", "female").to_yaml.should match_yaml("--- !ruby/struct\nname: Jane\ngender: female\n") + end + it "returns the YAML representation of a Symbol object" do :symbol.to_yaml.should match_yaml("--- :symbol\n") end diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c index 67594fce81ce..4d2ff52ef397 100644 --- a/spec/ruby/optional/capi/ext/encoding_spec.c +++ b/spec/ruby/optional/capi/ext/encoding_spec.c @@ -277,7 +277,7 @@ static VALUE encoding_spec_rb_enc_raise(VALUE self, VALUE encoding, VALUE except rb_encoding *e = rb_to_encoding(encoding); const char *f = RSTRING_PTR(format); - rb_enc_raise(e, exception_class, f); + rb_enc_raise(e, exception_class, "%s", f); } RBIMPL_WARNING_POP() diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb index 3bc8008fa4e9..7b6b1df7302f 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -120,7 +120,7 @@ q << 1 t = Thread.new { - -> { q.send(@method, 1, timeout: 0.1) }.should raise_error(ClosedQueueError, "queue closed") + -> { q.send(@method, 1, timeout: 10) }.should raise_error(ClosedQueueError, "queue closed") } Thread.pass until q.num_waiting == 1 From 4fc45b19b859aa1ddef0eb68188dc2c6c4924b7a Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Mon, 27 Nov 2023 18:24:59 +0100 Subject: [PATCH 2/3] Add tags for new failing specs --- spec/tags/core/array/assoc_tags.txt | 1 + spec/tags/core/io/read_tags.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 spec/tags/core/array/assoc_tags.txt diff --git a/spec/tags/core/array/assoc_tags.txt b/spec/tags/core/array/assoc_tags.txt new file mode 100644 index 000000000000..7efc3b807be2 --- /dev/null +++ b/spec/tags/core/array/assoc_tags.txt @@ -0,0 +1 @@ +fails:Array#assoc calls to_ary on non-array elements diff --git a/spec/tags/core/io/read_tags.txt b/spec/tags/core/io/read_tags.txt index 15eadf1edc93..4e1be00f5749 100644 --- a/spec/tags/core/io/read_tags.txt +++ b/spec/tags/core/io/read_tags.txt @@ -1,2 +1,3 @@ fails:IO.read from a pipe opens a pipe to a fork if the rest is - -fails(hangs):IO#read raises IOError when stream is closed by another thread \ No newline at end of file +fails(hangs):IO#read raises IOError when stream is closed by another thread +fails:IO#read clears the output buffer if there is nothing to read From 4e3a3f623ff18d20571282fe0c1bc51b115aa432 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 28 Nov 2023 16:07:41 +0100 Subject: [PATCH 3/3] Move tag as the spec moved --- spec/tags/library/openssl/x509/name/verify_tags.txt | 1 - spec/tags/library/openssl/x509/store/verify_tags.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 spec/tags/library/openssl/x509/name/verify_tags.txt create mode 100644 spec/tags/library/openssl/x509/store/verify_tags.txt diff --git a/spec/tags/library/openssl/x509/name/verify_tags.txt b/spec/tags/library/openssl/x509/name/verify_tags.txt deleted file mode 100644 index 5fdea058a88b..000000000000 --- a/spec/tags/library/openssl/x509/name/verify_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails(transient):OpenSSL::X509::Name.verify returns false for an expired root certificate diff --git a/spec/tags/library/openssl/x509/store/verify_tags.txt b/spec/tags/library/openssl/x509/store/verify_tags.txt new file mode 100644 index 000000000000..d1bdb10a04ff --- /dev/null +++ b/spec/tags/library/openssl/x509/store/verify_tags.txt @@ -0,0 +1 @@ +fails(transient):OpenSSL::X509::Store#verify returns false for an expired root certificate