summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-15 11:50:01 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-15 11:50:01 +0000
commitfd7dc23d281f38a71fa7f9c32812cd468c4b1788 (patch)
treef22532584562bfa9d45da35f1c845f415e8dbf4b /test
parente272790d1103d12afc98feac8e441fb66147836b (diff)
Kernel#inspect: improve consistency and do not call #to_s.
* object.c (rb_obj_inspect): Kernel#inspect: do not call #to_s. A class can now benefit from the nice default #inspect even if it defines #to_s. Also, there is no more unexpected change in #inspect result. * NEWS: Add note about the change. * bignum.c, io.c, numeric.c, object.c, proc.c, vm.c (Init_*): Adapt internal structures (by aliasing #inspect to #to_s) so they don't rely on the removed behavior (#inspect calling overridden #to_s). * test/ruby/test_object.rb (test_inspect): add tests for Kernel#inspect. * lib/pp.rb (class PP): do not call #to_s anymore, as #inspect no more does (mame). * test/test_pp.rb (class PPInspectTest): remove related assertion (mame). [ruby-core:43238][Feature #6130] * test/drb/drbtest.rb (DRbCore#teardown, DRbAry#teardown): adapt DRb tests with the new change (shirosaki). [ruby-core:47182][Bug #6866] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/drb/drbtest.rb4
-rw-r--r--test/ruby/test_object.rb25
-rw-r--r--test/test_pp.rb1
3 files changed, 27 insertions, 3 deletions
diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb
index 1cb8b1f95b..d0156fd9e4 100644
--- a/test/drb/drbtest.rb
+++ b/test/drb/drbtest.rb
@@ -73,7 +73,7 @@ module DRbCore
def teardown
@ext.stop_service if defined?(@ext) && @ext
DRbService.manager.unregist(@service_name)
- while (@there.inspect rescue nil)
+ while (@there.to_s rescue nil)
# nop
end
signal = /mswin|mingw/ =~ RUBY_PLATFORM ? :INT : :TERM
@@ -294,7 +294,7 @@ module DRbAry
def teardown
@ext.stop_service if defined?(@ext) && @ext
DRbService.manager.unregist(@service_name)
- while (@there.inspect rescue nil)
+ while (@there.to_s rescue nil)
# nop
end
signal = /mswin|mingw/ =~ RUBY_PLATFORM ? :INT : :TERM
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 70dcd04201..61482f7c1a 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -690,6 +690,31 @@ class TestObject < Test::Unit::TestCase
assert_equal(true, s.tainted?)
end
+ def test_inspect
+ x = Object.new
+ assert_match(/\A#<Object:0x\h+>\z/, x.inspect)
+
+ x.instance_variable_set(:@ivar, :value)
+ assert_match(/\A#<Object:0x\h+ @ivar=:value>\z/, x.inspect)
+
+ x = Object.new
+ x.instance_variable_set(:@recur, x)
+ assert_match(/\A#<Object:0x\h+ @recur=#<Object:0x\h+ \.\.\.>>\z/, x.inspect)
+
+ x = Object.new
+ x.instance_variable_set(:@foo, "value")
+ x.instance_variable_set(:@bar, 42)
+ assert_match(/\A#<Object:0x\h+ (?:@foo="value", @bar=42|@bar=42, @foo="value")>\z/, x.inspect)
+
+ # #inspect does not call #to_s anymore
+ feature6130 = '[ruby-core:43238]'
+ x = Object.new
+ def x.to_s
+ "to_s"
+ end
+ assert_match(/\A#<Object:0x\h+>\z/, x.inspect, feature6130)
+ end
+
def test_exec_recursive
Thread.current[:__recursive_key__] = nil
a = [[]]
diff --git a/test/test_pp.rb b/test/test_pp.rb
index fe65287d88..acd3e835b9 100644
--- a/test/test_pp.rb
+++ b/test/test_pp.rb
@@ -118,7 +118,6 @@ class PPInspectTest < Test::Unit::TestCase
def a.to_s() "aaa" end
result = PP.pp(a, '')
assert_equal("#{a.inspect}\n", result)
- assert_equal("aaa\n", result)
end
end