From 258661409e9e3fd470f006975ded872778aad4f4 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Tue, 7 Sep 2021 19:01:07 +0200 Subject: Update to ruby/spec@b1e93a2 --- spec/ruby/README.md | 1 + spec/ruby/core/array/intersect_spec.rb | 17 ++++++++++ spec/ruby/core/dir/fixtures/common.rb | 1 + spec/ruby/core/dir/glob_spec.rb | 2 ++ spec/ruby/core/dir/shared/glob.rb | 5 +++ spec/ruby/core/enumerable/tally_spec.rb | 2 +- spec/ruby/core/float/comparison_spec.rb | 3 ++ spec/ruby/core/kernel/nil_spec.rb | 10 ++++-- spec/ruby/core/module/define_method_spec.rb | 51 +++++++++++++++++++++++++++++ spec/ruby/core/process/spawn_spec.rb | 20 +++++++++++ spec/ruby/core/rational/rational_spec.rb | 4 +++ spec/ruby/core/tracepoint/inspect_spec.rb | 5 ++- spec/ruby/language/regexp/grouping_spec.rb | 28 ++++++++++++++++ spec/ruby/library/base64/decode64_spec.rb | 4 +++ spec/ruby/library/rbconfig/rbconfig_spec.rb | 2 +- spec/ruby/optional/capi/ext/string_spec.c | 5 +++ spec/ruby/optional/capi/string_spec.rb | 10 ++++++ 17 files changed, 163 insertions(+), 7 deletions(-) create mode 100644 spec/ruby/core/array/intersect_spec.rb (limited to 'spec') diff --git a/spec/ruby/README.md b/spec/ruby/README.md index a12cc3f7d8..e62ddc7dce 100644 --- a/spec/ruby/README.md +++ b/spec/ruby/README.md @@ -28,6 +28,7 @@ ruby/spec is known to be tested in these implementations for every commit: * [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x * [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby) * [Opal](https://github.com/opal/opal/tree/master/spec) +* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor) ruby/spec describes the behavior of Ruby 2.6 and more recent Ruby versions. More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (2.6.x, 2.7.x, 3.0.x, etc), and those are tested in CI. diff --git a/spec/ruby/core/array/intersect_spec.rb b/spec/ruby/core/array/intersect_spec.rb new file mode 100644 index 0000000000..b8c5b1e69a --- /dev/null +++ b/spec/ruby/core/array/intersect_spec.rb @@ -0,0 +1,17 @@ +require_relative '../../spec_helper' + +describe 'Array#intersect?' do + ruby_version_is '3.1' do # https://bugs.ruby-lang.org/issues/15198 + describe 'when at least one element in two Arrays is the same' do + it 'returns true' do + [1, 2].intersect?([2, 3]).should == true + end + end + + describe 'when there are no elements in common between two Arrays' do + it 'returns false' do + [1, 2].intersect?([3, 4]).should == false + end + end + end +end diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb index a1ea3db215..1a197d7a97 100644 --- a/spec/ruby/core/dir/fixtures/common.rb +++ b/spec/ruby/core/dir/fixtures/common.rb @@ -81,6 +81,7 @@ module DirSpecs special/} special/test{1}/file[1] + special/{}/special ] platform_is_not :windows do diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb index 6533c9b65a..295a7ab920 100644 --- a/spec/ruby/core/dir/glob_spec.rb +++ b/spec/ruby/core/dir/glob_spec.rb @@ -80,6 +80,7 @@ describe "Dir.glob" do nested/.dotsubir/ special/ special/test{1}/ + special/{}/ subdir_one/ subdir_two/ ] @@ -130,6 +131,7 @@ describe "Dir.glob" do ./nested/.dotsubir/ ./special/ ./special/test{1}/ + ./special/{}/ ./subdir_one/ ./subdir_two/ ] diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index ae5c2a114b..89d6b90283 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -64,6 +64,10 @@ describe :dir_glob, shared: true do Dir.send(@method, 'special/+').should == ['special/+'] end + it "matches directories with special characters when escaped" do + Dir.send(@method, 'special/\{}/special').should == ["special/{}/special"] + end + platform_is_not :windows do it "matches regexp special *" do Dir.send(@method, 'special/\*').should == ['special/*'] @@ -191,6 +195,7 @@ describe :dir_glob, shared: true do nested/ special/ special/test{1}/ + special/{}/ subdir_one/ subdir_two/ ] diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb index c23ea11697..92aac507ff 100644 --- a/spec/ruby/core/enumerable/tally_spec.rb +++ b/spec/ruby/core/enumerable/tally_spec.rb @@ -51,7 +51,7 @@ ruby_version_is "3.1" do enum.tally(hash).should equal(hash) end - it "raises a FrozenError and does not udpate the given hash when the hash is frozen" do + it "raises a FrozenError and does not update the given hash when the hash is frozen" do enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') hash = { 'foo' => 1 }.freeze -> { enum.tally(hash) }.should raise_error(FrozenError) diff --git a/spec/ruby/core/float/comparison_spec.rb b/spec/ruby/core/float/comparison_spec.rb index e367198903..a46841ffbf 100644 --- a/spec/ruby/core/float/comparison_spec.rb +++ b/spec/ruby/core/float/comparison_spec.rb @@ -14,6 +14,9 @@ describe "Float#<=>" do it "returns nil when the given argument is not a Float" do (1.0 <=> "1").should be_nil + (1.0 <=> "1".freeze).should be_nil + (1.0 <=> :one).should be_nil + (1.0 <=> true).should be_nil end it "compares using #coerce when argument is not a Float" do diff --git a/spec/ruby/core/kernel/nil_spec.rb b/spec/ruby/core/kernel/nil_spec.rb index b63705f7bc..7418245f26 100644 --- a/spec/ruby/core/kernel/nil_spec.rb +++ b/spec/ruby/core/kernel/nil_spec.rb @@ -1,6 +1,12 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' -describe "Kernel#nil?" do - it "needs to be reviewed for spec completeness" +describe 'Kernel#nil?' do + it 'returns false' do + Object.should_not.nil? + Object.new.should_not.nil? + ''.should_not.nil? + [].should_not.nil? + {}.should_not.nil? + end end diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 0cb2ab140c..c65b30de24 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -350,6 +350,14 @@ describe "Module#define_method" do object2.other_cool_method.should == "data is foo" end + it "accepts a proc from a Symbol" do + symbol_proc = :+.to_proc + klass = Class.new do + define_method :foo, &symbol_proc + end + klass.new.foo(1, 2).should == 3 + end + it "maintains the Proc's scope" do class DefineMethodByProcClass in_scope = true @@ -715,3 +723,46 @@ describe "Method#define_method when passed a Proc object" do end end end + +describe "Method#define_method when passed a block" do + describe "behaves exactly like a lambda" do + it "for return" do + Class.new do + define_method(:foo) do + return 42 + end + end.new.foo.should == 42 + end + + it "for break" do + Class.new do + define_method(:foo) do + break 42 + end + end.new.foo.should == 42 + end + + it "for next" do + Class.new do + define_method(:foo) do + next 42 + end + end.new.foo.should == 42 + end + + it "for redo" do + Class.new do + result = [] + define_method(:foo) do + if result.empty? + result << :first + redo + else + result << :second + result + end + end + end.new.foo.should == [:first, :second] + end + end +end diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb index 56e02ff38a..6be3f41a87 100644 --- a/spec/ruby/core/process/spawn_spec.rb +++ b/spec/ruby/core/process/spawn_spec.rb @@ -212,6 +212,26 @@ describe "Process.spawn" do end.should output_to_fd("nil\n") end + platform_is_not :windows do + it "uses the passed env['PATH'] to search the executable" do + dir = tmp("spawn_path_dir") + mkdir_p dir + begin + exe = 'process-spawn-executable-in-path' + path = "#{dir}/#{exe}" + File.write(path, "#!/bin/sh\necho $1") + File.chmod(0755, path) + + env = { "PATH" => "#{dir}#{File::PATH_SEPARATOR}#{ENV['PATH']}" } + Process.wait Process.spawn(env, exe, 'OK', out: @name) + $?.should.success? + File.read(@name).should == "OK\n" + ensure + rm_r dir + end + end + end + it "calls #to_hash to convert the environment" do o = mock("to_hash") o.should_receive(:to_hash).and_return({"FOO" => "BAR"}) diff --git a/spec/ruby/core/rational/rational_spec.rb b/spec/ruby/core/rational/rational_spec.rb index 704e49354e..482deab38d 100644 --- a/spec/ruby/core/rational/rational_spec.rb +++ b/spec/ruby/core/rational/rational_spec.rb @@ -4,4 +4,8 @@ describe "Rational" do it "includes Comparable" do Rational.include?(Comparable).should == true end + + it "does not respond to new" do + -> { Rational.new(1) }.should raise_error(NoMethodError) + end end diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb index 67e2ad1494..b9d7f35c32 100644 --- a/spec/ruby/core/tracepoint/inspect_spec.rb +++ b/spec/ruby/core/tracepoint/inspect_spec.rb @@ -64,13 +64,12 @@ describe 'TracePoint#inspect' do it 'returns a String showing the event, method, path and line for a :c_call event' do inspect = nil - line = nil - tp = TracePoint.new(:c_call) { |tp| + tracepoint = TracePoint.new(:c_call) { |tp| next unless TracePointSpec.target_thread? inspect ||= tp.inspect } line = __LINE__ + 2 - tp.enable do + tracepoint.enable do [0, 1].max end diff --git a/spec/ruby/language/regexp/grouping_spec.rb b/spec/ruby/language/regexp/grouping_spec.rb index e2abe71d0d..2f04a04018 100644 --- a/spec/ruby/language/regexp/grouping_spec.rb +++ b/spec/ruby/language/regexp/grouping_spec.rb @@ -32,4 +32,32 @@ describe "Regexps with grouping" do b # there is no capture group on this line (not even here) $/x.match("ab").to_a.should == [ "ab", "a" ] end + + it "does not consider # inside a character class as a comment" do + # From https://github.com/rubocop/rubocop/blob/39fcf1c568/lib/rubocop/cop/utils/format_string.rb#L18 + regexp = / + % (?%) # line comment + | % (?(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?#group comment) + (?: + (?: (?-mix:(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?\w+)>)? + | (?-mix:(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?\w+)>) (?-mix:\.(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? + | (?-mix:<(?\w+)>) (?(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?-mix:(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? + ) (?-mix:(?[bBdiouxXeEfgGaAcps])) + | (?-mix:(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\{(?\w+)\}) + ) + /x + regexp.named_captures.should == { + "type" => [1, 13], + "flags" => [2], + "width" => [3, 6, 11, 14], + "precision" => [4, 8, 12, 15], + "name" => [5, 7, 9, 16], + "more_flags" => [10] + } + match = regexp.match("%6.3f") + match[:width].should == '6' + match[:precision].should == '3' + match[:type].should == 'f' + match.to_a.should == [ "%6.3f", nil, "", "6", "3"] + [nil] * 8 + ["f"] + [nil] * 3 + end end diff --git a/spec/ruby/library/base64/decode64_spec.rb b/spec/ruby/library/base64/decode64_spec.rb index f6cd26d788..6dd33dddfe 100644 --- a/spec/ruby/library/base64/decode64_spec.rb +++ b/spec/ruby/library/base64/decode64_spec.rb @@ -22,4 +22,8 @@ describe "Base64#decode64" do it "returns a binary encoded string" do Base64.decode64("SEk=").encoding.should == Encoding::BINARY end + + it "decodes without padding suffix ==" do + Base64.decode64("eyJrZXkiOnsibiI6InR0dCJ9fQ").should == "{\"key\":{\"n\":\"ttt\"}}" + end end diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb index 99b9da71e4..e1fd84de91 100644 --- a/spec/ruby/library/rbconfig/rbconfig_spec.rb +++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb @@ -26,7 +26,7 @@ describe 'RbConfig::CONFIG' do it "['sitelibdir'] is set and is part of $LOAD_PATH" do sitelibdir = RbConfig::CONFIG['sitelibdir'] sitelibdir.should be_kind_of String - $LOAD_PATH.should.include? sitelibdir + $LOAD_PATH.map{|path| File.realpath(path) rescue path }.should.include? sitelibdir end end diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index feacbbdbb7..fb9af83c99 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -527,6 +527,10 @@ static VALUE string_spec_rb_str_vcatf(VALUE self, VALUE mesg) { return call_rb_str_vcatf(mesg, "fmt %d %d number", 42, 7); } +static VALUE string_spec_rb_str_catf(VALUE self, VALUE mesg) { + return rb_str_catf(mesg, "fmt %d %d number", 41, 6); +} + void Init_string_spec(void) { VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject); rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2); @@ -617,6 +621,7 @@ void Init_string_spec(void) { rb_define_method(cls, "rb_utf8_str_new", string_spec_rb_utf8_str_new, 0); rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0); rb_define_method(cls, "rb_str_vcatf", string_spec_rb_str_vcatf, 1); + rb_define_method(cls, "rb_str_catf", string_spec_rb_str_catf, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index c6ab1ca0fe..3c5b7fe4e0 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -1154,4 +1154,14 @@ end str.should == "test fmt 42 7 number" end end + + describe "rb_str_catf" do + it "appends the message to the string" do + @s.rb_str_catf("").should == "fmt 41 6 number" + + str = "test " + @s.rb_str_catf(str) + str.should == "test fmt 41 6 number" + end + end end -- cgit v1.2.3