ruby-changes:47793
From: eregon <ko1@a...>
Date: Fri, 15 Sep 2017 00:56:38 +0900 (JST)
Subject: [ruby-changes:47793] eregon:r59911 (trunk): Update to ruby/spec@a4bc1d8
eregon 2017-09-15 00:56:33 +0900 (Fri, 15 Sep 2017) New Revision: 59911 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59911 Log: Update to ruby/spec@a4bc1d8 Added files: trunk/spec/rubyspec/core/random/default_spec.rb trunk/spec/rubyspec/optional/capi/ext/st_spec.c trunk/spec/rubyspec/optional/capi/st_spec.rb Removed files: trunk/spec/rubyspec/Gemfile Modified files: trunk/spec/rubyspec/README.md trunk/spec/rubyspec/command_line/dash_e_spec.rb trunk/spec/rubyspec/command_line/dash_v_spec.rb trunk/spec/rubyspec/core/kernel/exit_spec.rb trunk/spec/rubyspec/core/module/prepend_spec.rb trunk/spec/rubyspec/core/rational/to_r_spec.rb trunk/spec/rubyspec/core/struct/inspect_spec.rb trunk/spec/rubyspec/core/thread/status_spec.rb trunk/spec/rubyspec/core/thread/terminate_spec.rb trunk/spec/rubyspec/core/time/shared/time_params.rb trunk/spec/rubyspec/language/for_spec.rb trunk/spec/rubyspec/library/getoptlong/shared/get.rb trunk/spec/rubyspec/library/net/http/http/send_request_spec.rb trunk/spec/rubyspec/optional/capi/ext/fixnum_spec.c trunk/spec/rubyspec/optional/capi/ext/gc_spec.c trunk/spec/rubyspec/optional/capi/ext/hash_spec.c trunk/spec/rubyspec/optional/capi/ext/proc_spec.c trunk/spec/rubyspec/optional/capi/ext/range_spec.c trunk/spec/rubyspec/optional/capi/ext/rubyspec.h trunk/spec/rubyspec/optional/capi/ext/string_spec.c trunk/spec/rubyspec/optional/capi/fixnum_spec.rb trunk/spec/rubyspec/optional/capi/gc_spec.rb trunk/spec/rubyspec/optional/capi/hash_spec.rb trunk/spec/rubyspec/optional/capi/proc_spec.rb trunk/spec/rubyspec/optional/capi/range_spec.rb trunk/spec/rubyspec/optional/capi/string_spec.rb trunk/spec/rubyspec/shared/process/exit.rb Index: spec/rubyspec/Gemfile =================================================================== --- spec/rubyspec/Gemfile (revision 59910) +++ spec/rubyspec/Gemfile (nonexistent) @@ -1,3 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/Gemfile#L0 -source 'https://rubygems.org' - -gem 'mspec', :git => 'https://github.com/ruby/mspec' Property changes on: spec/rubyspec/Gemfile ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Index: spec/rubyspec/README.md =================================================================== --- spec/rubyspec/README.md (revision 59910) +++ spec/rubyspec/README.md (revision 59911) @@ -27,6 +27,14 @@ ruby/spec is known to be tested in these https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/README.md#L27 * [TruffleRuby](https://github.com/graalvm/truffleruby) on Travis * [Opal](https://github.com/opal/opal/tree/master/spec) on Travis +ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions. +More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec +(latest 2.2.x, 2.3.x, 2.4.x, etc). + +For older specs try these commits: +* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures) +* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed) + ### Running the specs First, clone this repository: Index: spec/rubyspec/library/getoptlong/shared/get.rb =================================================================== --- spec/rubyspec/library/getoptlong/shared/get.rb (revision 59910) +++ spec/rubyspec/library/getoptlong/shared/get.rb (revision 59911) @@ -53,9 +53,12 @@ describe :getoptlong_get, shared: true d https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/getoptlong/shared/get.rb#L53 end end - it "returns multiline argument" do - argv [ "--size=\n10k\n" ] do - @opts.send(@method).should == [ "--size", "\n10k\n" ] + ruby_version_is "2.5" do + # https://bugs.ruby-lang.org/issues/13858 + it "returns multiline argument" do + argv [ "--size=\n10k\n" ] do + @opts.send(@method).should == [ "--size", "\n10k\n" ] + end end end end Index: spec/rubyspec/library/net/http/http/send_request_spec.rb =================================================================== --- spec/rubyspec/library/net/http/http/send_request_spec.rb (revision 59910) +++ spec/rubyspec/library/net/http/http/send_request_spec.rb (revision 59911) @@ -6,6 +6,13 @@ describe "Net::HTTP#send_request" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/net/http/http/send_request_spec.rb#L6 before :each do NetHTTPSpecs.start_server @http = Net::HTTP.start("localhost", NetHTTPSpecs.port) + + # HEAD is special so handled separately + @methods = %w[ + GET POST PUT DELETE + OPTIONS + PROPFIND PROPPATCH LOCK UNLOCK + ] end after :each do @@ -16,103 +23,39 @@ describe "Net::HTTP#send_request" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/library/net/http/http/send_request_spec.rb#L23 # TODO: Does only work with GET and POST requests describe "when passed type, path" do it "sends a HTTP Request of the passed type to the passed path" do - response = @http.send_request("GET", "/request") - response.body.should == "Request type: GET" - - # response = @http.send_request("HEAD", "/request") - # response.body.should be_nil - - response = @http.send_request("POST", "/request") - response.body.should == "Request type: POST" - - # response = @http.send_request("PUT", "/request") - # response.body.should == "Request type: PUT" - - # response = @http.send_request("DELETE", "/request") - # response.body.should == "Request type: DELETE" - - # response = @http.send_request("PROPGET", "/request") - # response.body.should == "Request type: DELETE" + response = @http.send_request("HEAD", "/request") + response.body.should be_nil - # response = @http.send_request("PROPSET", "/request") - # response.body.should == "Request type: DELETE" - - # response = @http.send_request("OPTIONS", "/request") - # response.body.should be_nil - - # response = @http.send_request("LOCK", "/request") - # response.body.should == "Request type: LOCK - - # response = @http.send_request("UNLOCK", "/request") - # response.body.should == "Request type: UNLOCK + @methods.each do |method| + response = @http.send_request(method, "/request") + response.body.should == "Request type: #{method}" + end end end describe "when passed type, path, body" do it "sends a HTTP Request with the passed body" do - response = @http.send_request("GET", "/request/body", "test=test") - response.body.should == "test=test" - - # response = @http.send_request("HEAD", "/request/body", "test=test") - # response.body.should be_nil - - response = @http.send_request("POST", "/request/body", "test=test") - response.body.should == "test=test" - - # response = @http.send_request("PUT", "/request/body", "test=test") - # response.body.should == "test=test" + response = @http.send_request("HEAD", "/request/body", "test=test") + response.body.should be_nil - # response = @http.send_request("DELETE", "/request/body", "test=test") - # response.body.should == "test=test" - - # response = @http.send_request("PROPGET", "/request/body", "test=test") - # response.body.should == "test=test" - - # response = @http.send_request("PROPSET", "/request/body", "test=test") - # response.body.should == "test=test" - - # response = @http.send_request("OPTIONS", "/request/body", "test=test") - # response.body.should be_nil - - # response = @http.send_request("LOCK", "/request/body", "test=test") - # response.body.should == "test=test" - - # response = @http.send_request("UNLOCK", "/request/body", "test=test") - # response.body.should == "test=test" + @methods.each do |method| + response = @http.send_request(method, "/request/body", "test=test") + response.body.should == "test=test" + end end end describe "when passed type, path, body, headers" do it "sends a HTTP Request with the passed headers" do - response = @http.send_request("GET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should be_nil - - response = @http.send_request("POST", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("PUT", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("DELETE", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("PROPGET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("PROPSET", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') - - # response = @http.send_request("OPTIONS", "/request/body", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should be_nil + referer = 'https://www.ruby-lang.org/'.freeze - # response = @http.send_request("LOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') + response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => referer) + response.body.should be_nil - # response = @http.send_request("UNLOCK", "/request/header", "test=test", "referer" => "http://www.rubyspec.org") - # response.body.should include('"referer"=>["http://www.rubyspec.org"]') + @methods.each do |method| + response = @http.send_request(method, "/request/header", "test=test", "referer" => referer) + response.body.should include('"referer"=>["' + referer + '"]') + end end end end Index: spec/rubyspec/shared/process/exit.rb =================================================================== --- spec/rubyspec/shared/process/exit.rb (revision 59910) +++ spec/rubyspec/shared/process/exit.rb (revision 59911) @@ -74,23 +74,21 @@ describe :process_exit, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/shared/process/exit.rb#L74 end describe :process_exit!, shared: true do - with_feature :fork do - it "exits with the given status" do - pid = Process.fork { @object.exit!(1) } - pid, status = Process.waitpid2(pid) - status.exitstatus.should == 1 - end - - it "exits when called from a thread" do - pid = Process.fork do - Thread.new { @object.exit!(1) }.join + it "exits with the given status" do + out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1') + out.should == "" + $?.exitstatus.should == 21 + end - # Do not let the main thread complete - sleep - end + it "exits when called from a thread" do + out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1') + out.should == "" + $?.exitstatus.should == 21 + end - pid, status = Process.waitpid2(pid) - status.exitstatus.should == 1 - end + it "exits when called from a fiber" do + out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1') + out.should == "" + $?.exitstatus.should == 21 end end Index: spec/rubyspec/language/for_spec.rb =================================================================== --- spec/rubyspec/language/for_spec.rb (revision 59910) +++ spec/rubyspec/language/for_spec.rb (revision 59911) @@ -12,6 +12,12 @@ describe "The for expression" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/language/for_spec.rb#L12 j.should == 6 end + it "iterates over a list of arrays and destructures with empty comma" do + for i, in [[1,2]] + i.should == 1 + end + end + it "iterates over an Hash passing each key-value pair to the block" do k = 0 l = 0 Index: spec/rubyspec/optional/capi/fixnum_spec.rb =================================================================== --- spec/rubyspec/optional/capi/fixnum_spec.rb (revision 59910) +++ spec/rubyspec/optional/capi/fixnum_spec.rb (revision 59911) @@ -7,6 +7,40 @@ describe "CApiFixnumSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/fixnum_spec.rb#L7 @s = CApiFixnumSpecs.new end + describe "FIX2INT" do + it "converts a Fixnum to a native int" do + @s.FIX2INT(42).should == 42 + @s.FIX2INT(-14).should == -14 + end + + max_int = (1 << 31) - 1 + min_int = -(1 << 31) + + guard -> { fixnum_min <= min_int and max_int <= fixnum_max } do + it "converts a Fixnum representing the minimum and maximum native int" do + @s.FIX2INT(max_int).should == max_int + @s.FIX2INT(min_int).should == min_int + end + end + + end + + describe "FIX2UINT" do + it "converts a Fixnum to a native int" do + @s.FIX2UINT(42).should == 42 + @s.FIX2UINT(0).should == 0 + end + + max_uint = (1 << 32) - 1 + + guard -> { max_uint <= fixnum_max } do + it "converts a Fixnum representing the maximum native uint" do + @s.FIX2UINT(max_uint).should == max_uint + end + end + + end + platform_is wordsize: 64 do describe "rb_fix2uint" do it "raises a TypeError if passed nil" do @@ -14,6 +48,7 @@ describe "CApiFixnumSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/fixnum_spec.rb#L48 end it "converts a Fixnum" do + @s.rb_fix2uint(0).should == 0 @s.rb_fix2uint(1).should == 1 end @@ -25,6 +60,12 @@ describe "CApiFixnumSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/fixnum_spec.rb#L60 @s.rb_fix2uint(25.4567).should == 25 end + it "raises a RangeError if the value does not fit a native uint" do + # Interestingly, on MRI rb_fix2uint(-1) is allowed + lambda { @s.rb_fix2uint(0xffff_ffff+1) }.should raise_error(RangeError) + lambda { @s.rb_fix2uint(-(1 << 31) - 1) }.should raise_error(RangeError) + end + it "raises a RangeError if the value is more than 32bits" do lambda { @s.rb_fix2uint(0xffff_ffff+1) }.should raise_error(RangeError) end @@ -44,7 +85,11 @@ describe "CApiFixnumSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/fixnum_spec.rb#L85 @s.rb_fix2int(1).should == 1 end - it "converts the maximum uint value" do + it "converts the minimum int value" do + @s.rb_fix2int(-(1 << 31)).should == -(1 << 31) + end + + it "converts the maximum int value" do @s.rb_fix2int(0x7fff_ffff).should == 0x7fff_ffff end @@ -56,6 +101,11 @@ describe "CApiFixnumSpecs" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/fixnum_spec.rb#L101 @s.rb_fix2int(-2147442171).should == -2147442171 end + it "raises a RangeError if the value does not fit a native int" do + lambda { @s.rb_fix2int(0x7fff_ffff+1) }.should raise_error(RangeError) + lambda { @s.rb_fix2int(-(1 << 31) - 1) }.should raise_error(RangeError) + end + it "raises a RangeError if the value is more than 32bits" do lambda { @s.rb_fix2int(0xffff_ffff+1) }.should raise_error(RangeError) end Index: spec/rubyspec/optional/capi/string_spec.rb =================================================================== --- spec/rubyspec/optional/capi/string_spec.rb (revision 59910) +++ spec/rubyspec/optional/capi/string_spec.rb (revision 59911) @@ -228,6 +228,22 @@ describe "C-API String function" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/string_spec.rb#L228 end end + 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 + describe "rb_str_append" do it "appends a string to another string" do @s.rb_str_append("Hello", " Goodbye").should == "Hello Goodbye" Index: spec/rubyspec/optional/capi/hash_spec.rb =================================================================== --- spec/rubyspec/optional/capi/hash_spec.rb (revision 59910) +++ spec/rubyspec/optional/capi/hash_spec.rb (revision 59911) @@ -119,6 +119,25 @@ describe "C-API Hash function" do https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/hash_spec.rb#L119 end end + describe "rb_hash_fetch" do + before :each do + @hsh = {:a => 1, :b => 2} + end + + it "returns the value associated with the key" do + @s.rb_hash_fetch(@hsh, :b).should == 2 + end + + it "raises a KeyError if the key is not found and default is set" do + @hsh.default = :d + lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) + end + + it "raises a KeyError if the key is not found and no default is set" do + lambda { @s.rb_hash_fetch(@hsh, :c) }.should raise_error(KeyError) + end + end + describe "rb_hash_foreach" do it "iterates over the hash" do hsh = {name: "Evan", sign: :libra} Index: spec/rubyspec/optional/capi/ext/st_spec.c =================================================================== --- spec/rubyspec/optional/capi/ext/st_spec.c (nonexistent) +++ spec/rubyspec/optional/capi/ext/st_spec.c (revision 59911) @@ -0,0 +1,82 @@ https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/ext/st_spec.c#L1 +#include "ruby.h" +#include "rubyspec.h" + +#include <string.h> +#include <stdarg.h> + +#ifdef HAVE_RB_ST +#include <ruby/st.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_RB_ST +VALUE st_spec_st_init_numtable(VALUE self) { + st_table *tbl = st_init_numtable(); + int entries = tbl->num_entries; + st_free_table(tbl); + return INT2FIX(entries); +} + +VALUE st_spec_st_init_numtable_with_size(VALUE self) { + st_table *tbl = st_init_numtable_with_size(128); + int entries = tbl->num_entries; + st_free_table(tbl); + return INT2FIX(entries); +} + +VALUE st_spec_st_insert(VALUE self) { + int entries; + st_table *tbl = st_init_numtable_with_size(128); + st_insert(tbl, 1, 1); + entries = tbl->num_entries; + st_free_table(tbl); + return INT2FIX(entries); +} + +static int sum(st_data_t key, st_data_t value, st_data_t arg) { + *(int*)arg += value; + return ST_CONTINUE; +} + +VALUE st_spec_st_foreach(VALUE self) { + int total = 0; + st_table *tbl = st_init_numtable_with_size(128); + st_insert(tbl, 1, 3); + st_insert(tbl, 2, 4); + st_foreach(tbl, sum, (st_data_t)&total); + st_free_table(tbl); + return INT2FIX(total); +} + +VALUE st_spec_st_lookup(VALUE self) { + st_data_t result = (st_data_t)0; + st_table *tbl = st_init_numtable_with_size(128); + st_insert(tbl, 7, 42); + st_insert(tbl, 2, 4); + st_lookup(tbl, (st_data_t)7, &result); + st_free_table(tbl); + return INT2FIX(result); +} + +#endif + +void Init_st_spec(void) { + VALUE cls; + cls = rb_define_class("CApiStSpecs", rb_cObject); + +#ifdef HAVE_RB_ST + rb_define_method(cls, "st_init_numtable", st_spec_st_init_numtable, 0); + rb_define_method(cls, "st_init_numtable_with_size", st_spec_st_init_numtable_with_size, 0); + rb_define_method(cls, "st_insert", st_spec_st_insert, 0); + rb_define_method(cls, "st_foreach", st_spec_st_foreach, 0); + rb_define_method(cls, "st_lookup", st_spec_st_lookup, 0); +#endif + +} + +#ifdef __cplusplus +} +#endif Property changes on: spec/rubyspec/optional/capi/ext/st_spec.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Index: spec/rubyspec/optional/capi/ext/rubyspec.h =================================================================== --- spec/rubyspec/optional/capi/ext/rubyspec.h (revision 59910) +++ spec/rubyspec/optional/capi/ext/rubyspec.h (revision 59911) @@ -299,6 +299,7 @@ https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/ext/rubyspec.h#L299 #define HAVE_RB_HASH_CLEAR 1 #define HAVE_RB_HASH_DELETE 1 #define HAVE_RB_HASH_DELETE_IF 1 +#define HAVE_RB_HASH_FETCH 1 #define HAVE_RB_HASH_FOREACH 1 #define HAVE_RB_HASH_LOOKUP 1 #define HAVE_RB_HASH_LOOKUP2 1 @@ -372,6 +373,7 @@ https://github.com/ruby/ruby/blob/trunk/spec/rubyspec/optional/capi/ext/rubyspec.h#L373 #define HAVE_RB_GC_REGISTER_ADDRESS 1 #define HAVE_RB_GC_ENABLE (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/