diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-21 15:31:15 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-21 15:31:15 +0000 |
commit | 2c8dd794e9c86846f5989569b76c8c8006b18853 (patch) | |
tree | e2557f8521156567643b56776c2818cdfa04e871 /test/ruby/test_class.rb | |
parent | 4c094940aa8544e3ee149dee57ec294a47f3099d (diff) | |
download | ruby-2c8dd794e9c86846f5989569b76c8c8006b18853.tar.gz |
* test/ruby/test_require.rb: new tests for library requiring, to
achieve over 90% test coverage of dln.c.
* test/ruby/test_class.rb: add tests to achieve over 90% test coverage
of class.c.
* test/ruby/test_module.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_class.rb')
-rw-r--r-- | test/ruby/test_class.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index d4813a5f07..8c035b5d59 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -1,6 +1,10 @@ require 'test/unit' +require_relative 'envutil' class TestClass < Test::Unit::TestCase + def ruby(*r, &b) + EnvUtil.rubyexec(*r, &b) + end # ------------------ # Various test classes @@ -105,4 +109,41 @@ class TestClass < Test::Unit::TestCase end end + def test_check_inheritable + assert_raise(TypeError) { Class.new(Object.new) } + + o = Object.new + c = class << o; self; end + assert_raise(TypeError) { Class.new(c) } + + assert_nothing_raised { Class.new(Class) } # is it OK? + assert_raise(TypeError) { eval("class Foo < Class; end") } + end + + def test_initialize_copy + c = Class.new + assert_raise(TypeError) { c.instance_eval { initialize_copy(1) } } + + o = Object.new + c = class << o; self; end + assert_raise(TypeError) { c.dup } + end + + def test_singleton_class + assert_raise(TypeError) { 1.extend(Module.new) } + assert_raise(TypeError) { :foo.extend(Module.new) } + + ruby do |w, r, e| + w.puts "module Foo; def foo; :foo; end; end" + w.puts "false.extend(Foo)" + w.puts "true.extend(Foo)" + w.puts "p false.foo" + w.puts "p true.foo" + w.puts "p FalseClass.include?(Foo)" + w.puts "p TrueClass.include?(Foo)" + w.close + assert_equal("", e.read) + assert_equal(":foo\n:foo\ntrue\ntrue", r.read.chomp) + end + end end |