ruby-changes:32893
From: nagachika <ko1@a...>
Date: Sat, 15 Feb 2014 23:39:53 +0900 (JST)
Subject: [ruby-changes:32893] nagachika:r44972 (ruby_2_0_0): merge revision(s) r43440:
nagachika 2014-02-15 23:39:47 +0900 (Sat, 15 Feb 2014) New Revision: 44972 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44972 Log: merge revision(s) r43440: * struct.c (new_struct): fix warning message, class name and encoding. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/struct.c branches/ruby_2_0_0/test/ruby/test_struct.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 44971) +++ ruby_2_0_0/ChangeLog (revision 44972) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sat Feb 15 23:26:31 2014 Nobuyoshi Nakada <nobu@r...> + + * struct.c (new_struct): fix warning message, class name and encoding. + Sat Feb 15 16:08:26 2014 Nobuyoshi Nakada <nobu@r...> * struct.c (make_struct): avoid inadvertent symbol creation. Index: ruby_2_0_0/struct.c =================================================================== --- ruby_2_0_0/struct.c (revision 44971) +++ ruby_2_0_0/struct.c (revision 44972) @@ -194,7 +194,7 @@ new_struct(VALUE name, VALUE super) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L194 } id = rb_to_id(name); if (rb_const_defined_at(super, id)) { - rb_warn("redefining constant Struct::%s", StringValuePtr(name)); + rb_warn("redefining constant %"PRIsVALUE"::%"PRIsVALUE, super, name); rb_mod_remove_const(super, ID2SYM(id)); } return rb_define_class_id_under(super, id, super); Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 44971) +++ ruby_2_0_0/version.h (revision 44972) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-02-15" -#define RUBY_PATCHLEVEL 406 +#define RUBY_PATCHLEVEL 407 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_0_0/test/ruby/test_struct.rb =================================================================== --- ruby_2_0_0/test/ruby/test_struct.rb (revision 44971) +++ ruby_2_0_0/test/ruby/test_struct.rb (revision 44972) @@ -3,10 +3,10 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L3 require 'timeout' require_relative 'envutil' -class TestStruct < Test::Unit::TestCase +module TestStruct def test_struct - struct_test = Struct.new("Test", :foo, :bar) - assert_equal(Struct::Test, struct_test) + struct_test = @Struct.new("Test", :foo, :bar) + assert_equal(@Struct::Test, struct_test) test = struct_test.new(1, 2) assert_equal(1, test.foo) @@ -29,7 +29,7 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L29 def test_morethan10members list = %w( a b c d e f g h i j k l m n o p ) until list.empty? - c = Struct.new(* list.map {|ch| ch.intern }).new + c = @Struct.new(* list.map {|ch| ch.intern }).new list.each do |ch| c.__send__(ch) end @@ -41,7 +41,7 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L41 names = [:a, :b, :c, :d] 1.upto(4) {|n| fields = names[0, n] - klass = Struct.new(*fields) + klass = @Struct.new(*fields) o = klass.new(*(0...n).to_a) fields.each_with_index {|name, i| assert_equal(i, o[name]) @@ -54,21 +54,21 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L54 end def test_inherit - klass = Struct.new(:a) + klass = @Struct.new(:a) klass2 = Class.new(klass) o = klass2.new(1) assert_equal(1, o.a) end def test_members - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal([:a], klass.members) assert_equal([:a], o.members) end def test_ref - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal(1, o[:a]) assert_raise(NameError) { o[:b] } @@ -86,7 +86,7 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L86 end def test_set - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) o[:a] = 2 assert_equal(2, o[:a]) @@ -94,28 +94,28 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L94 end def test_struct_new - assert_raise(NameError) { Struct.new("foo") } - assert_nothing_raised { Struct.new("Foo") } - Struct.instance_eval { remove_const(:Foo) } - assert_nothing_raised { Struct.new(:a) { } } - assert_raise(RuntimeError) { Struct.new(:a) { raise } } + assert_raise(NameError) { @Struct.new("foo") } + assert_nothing_raised { @Struct.new("Foo") } + @Struct.instance_eval { remove_const(:Foo) } + assert_nothing_raised { @Struct.new(:a) { } } + assert_raise(RuntimeError) { @Struct.new(:a) { raise } } assert_equal([:utime, :stime, :cutime, :cstime], Process.times.members) end def test_initialize - klass = Struct.new(:a) + klass = @Struct.new(:a) assert_raise(ArgumentError) { klass.new(1, 2) } end def test_each - klass = Struct.new(:a, :b) + klass = @Struct.new(:a, :b) o = klass.new(1, 2) assert_equal([1, 2], o.each.to_a) end def test_each_pair - klass = Struct.new(:a, :b) + klass = @Struct.new(:a, :b) o = klass.new(1, 2) assert_equal([[:a, 1], [:b, 2]], o.each_pair.to_a) bug7382 = '[ruby-dev:46533]' @@ -125,22 +125,22 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L125 end def test_inspect - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal("#<struct a=1>", o.inspect) o.a = o assert_match(/^#<struct a=#<struct #<.*?>:...>>$/, o.inspect) - Struct.new("Foo", :a) - o = Struct::Foo.new(1) - assert_equal("#<struct Struct::Foo a=1>", o.inspect) - Struct.instance_eval { remove_const(:Foo) } + @Struct.new("Foo", :a) + o = @Struct::Foo.new(1) + assert_equal("#<struct #@Struct::Foo a=1>", o.inspect) + @Struct.instance_eval { remove_const(:Foo) } - klass = Struct.new(:a, :b) + klass = @Struct.new(:a, :b) o = klass.new(1, 2) assert_equal("#<struct a=1, b=2>", o.inspect) - klass = Struct.new(:@a) + klass = @Struct.new(:@a) o = klass.new(1) assert_equal(1, o.__send__(:@a)) assert_equal("#<struct :@a=1>", o.inspect) @@ -158,13 +158,13 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L158 end def test_init_copy - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal(o, o.dup) end def test_aref - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal(1, o[0]) assert_raise(IndexError) { o[-2] } @@ -172,7 +172,7 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L172 end def test_aset - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) o[0] = 2 assert_equal(2, o[:a]) @@ -181,22 +181,22 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L181 end def test_values_at - klass = Struct.new(:a, :b, :c, :d, :e, :f) + klass = @Struct.new(:a, :b, :c, :d, :e, :f) o = klass.new(1, 2, 3, 4, 5, 6) assert_equal([2, 4, 6], o.values_at(1, 3, 5)) assert_equal([2, 3, 4, 3, 4, 5], o.values_at(1..3, 2...5)) end def test_select - klass = Struct.new(:a, :b, :c, :d, :e, :f) + klass = @Struct.new(:a, :b, :c, :d, :e, :f) o = klass.new(1, 2, 3, 4, 5, 6) assert_equal([1, 3, 5], o.select {|v| v % 2 != 0 }) assert_raise(ArgumentError) { o.select(1) } end def test_equal - klass1 = Struct.new(:a) - klass2 = Struct.new(:a, :b) + klass1 = @Struct.new(:a) + klass2 = @Struct.new(:a, :b) o1 = klass1.new(1) o2 = klass1.new(1) o3 = klass2.new(1) @@ -205,14 +205,14 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L205 end def test_hash - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert(o.hash.is_a?(Fixnum)) end def test_eql - klass1 = Struct.new(:a) - klass2 = Struct.new(:a, :b) + klass1 = @Struct.new(:a) + klass2 = @Struct.new(:a, :b) o1 = klass1.new(1) o2 = klass1.new(1) o3 = klass2.new(1) @@ -221,33 +221,47 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L221 end def test_size - klass = Struct.new(:a) + klass = @Struct.new(:a) o = klass.new(1) assert_equal(1, o.size) end def test_error assert_raise(TypeError){ - Struct.new(0) + @Struct.new(0) } end + def test_redefinition_warning + @Struct.new("RedefinitionWarning") + e = EnvUtil.verbose_warning do + @Struct.new("RedefinitionWarning") + end + assert_match(/redefining constant #@Struct::RedefinitionWarning/, e) + end + def test_nonascii - struct_test = Struct.new("R\u{e9}sum\u{e9}", :"r\u{e9}sum\u{e9}") - assert_equal(Struct.const_get("R\u{e9}sum\u{e9}"), struct_test, '[ruby-core:24849]') + struct_test = @Struct.new("R\u{e9}sum\u{e9}", :"r\u{e9}sum\u{e9}") + assert_equal(@Struct.const_get("R\u{e9}sum\u{e9}"), struct_test, '[ruby-core:24849]') a = struct_test.new(42) - assert_equal("#<struct Struct::R\u{e9}sum\u{e9} r\u{e9}sum\u{e9}=42>", a.inspect, '[ruby-core:24849]') + assert_equal("#<struct #@Struct::R\u{e9}sum\u{e9} r\u{e9}sum\u{e9}=42>", a.inspect, '[ruby-core:24849]') + e = EnvUtil.verbose_warning do + @Struct.new("R\u{e9}sum\u{e9}", :"r\u{e9}sum\u{e9}") + end + assert_nothing_raised(Encoding::CompatibilityError) do + assert_match(/redefining constant #@Struct::R\u{e9}sum\u{e9}/, e) + end end def test_junk - struct_test = Struct.new("Foo", "a\000") + struct_test = @Struct.new("Foo", "a\000") o = struct_test.new(1) assert_equal(1, o.send("a\000")) - Struct.instance_eval { remove_const(:Foo) } + @Struct.instance_eval { remove_const(:Foo) } end def test_comparison_when_recursive - klass1 = Struct.new(:a, :b, :c) + klass1 = @Struct.new(:a, :b, :c) x = klass1.new(1, 2, nil); x.c = x y = klass1.new(1, 2, nil); y.c = y @@ -289,14 +303,33 @@ class TestStruct < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_struct.rb#L303 end def test_to_h - klass = Struct.new(:a, :b, :c, :d, :e, :f) + klass = @Struct.new(:a, :b, :c, :d, :e, :f) o = klass.new(1, 2, 3, 4, 5, 6) assert_equal({a:1, b:2, c:3, d:4, e:5, f:6}, o.to_h) end def test_struct_question_mark bug9248 = '[ruby-core:59095]' - klass = Struct.new(:a?) + klass = @Struct.new(:a?) assert_include(klass.new.methods.inspect, ':a?', bug9248) end + + class TopStruct < Test::Unit::TestCase + include TestStruct + + def initialize(*) + super + @Struct = Struct + end + end + + class SubStruct < Test::Unit::TestCase + include TestStruct + SubStruct = Class.new(Struct) + + def initialize(*) + super + @Struct = SubStruct + end + end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r43440 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/