ruby-changes:5017
From: mame <ko1@a...>
Date: Thu, 22 May 2008 00:31:36 +0900 (JST)
Subject: [ruby-changes:5017] mame - Ruby:r16510 (trunk): * test/ruby/test_require.rb: new tests for library requiring, to
mame 2008-05-22 00:31:15 +0900 (Thu, 22 May 2008) New Revision: 16510 Added files: trunk/test/ruby/test_require.rb Modified files: trunk/ChangeLog trunk/test/ruby/test_class.rb trunk/test/ruby/test_module.rb Log: * 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. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_module.rb?r1=16510&r2=16509&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16510&r2=16509&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_class.rb?r1=16510&r2=16509&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_require.rb?revision=16510&view=markup http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_require.rb?r1=16510&r2=16509&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16509) +++ ChangeLog (revision 16510) @@ -1,3 +1,13 @@ +Thu May 22 00:30:06 2008 Yusuke Endoh <mame@t...> + + * 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. + Thu May 22 00:15:44 2008 Koichi Sasada <ko1@a...> * insns.def, vm_insnhelper.c: specify "const". Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 16509) +++ test/ruby/test_module.rb (revision 16510) @@ -690,4 +690,23 @@ o.extend(m2) assert_equal(true, o.respond_to?(:foo)) end + + def test_cyclic_include + m1 = Module.new + m2 = Module.new + m1.instance_eval { include(m2) } + assert_raise(ArgumentError) do + m2.instance_eval { include(m1) } + end + end + + def test_include_p + m = Module.new + c1 = Class.new + c1.instance_eval { include(m) } + c2 = Class.new(c1) + assert_equal(true, c1.include?(m)) + assert_equal(true, c2.include?(m)) + assert_equal(false, m.include?(m)) + end end Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 0) +++ test/ruby/test_require.rb (revision 16510) @@ -0,0 +1,215 @@ +require 'test/unit' + +require 'tempfile' +require_relative 'envutil' + +class TestRequire < Test::Unit::TestCase + def ruby(*r, &b) + EnvUtil.rubyexec(*r, &b) + end + + def test_require_invalid_shared_object + t = Tempfile.new(["test_ruby_test_require", ".so"]) + t.puts "dummy" + t.close + + ruby do |w, r, e| + w.puts "begin" + w.puts " require \"#{ t.path }\"" + w.puts "rescue LoadError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal(":ok", r.read.chomp) + end + end + + def test_require_too_long_filename + ruby do |w, r, e| + w.puts "begin" + w.puts " require '#{ "foo/" * 10000 }foo'" + w.puts "rescue LoadError" + w.puts " p :ok" + w.puts "end" + w.close + e.read + assert_equal(":ok", r.read.chomp) + end + end + + def test_require_path_home + env_rubypath, env_home = ENV["RUBYPATH"], ENV["HOME"] + + ENV["RUBYPATH"] = "~" + ENV["HOME"] = "/foo" * 10000 + ruby("-S", "test_ruby_test_require") do |w, r, e| + w.close + e.read + assert_equal("", r.read) + end + + ENV["RUBYPATH"] = "~" + "/foo" * 10000 + ENV["HOME"] = "/foo" + ruby("-S", "test_ruby_test_require") do |w, r, e| + w.close + e.read + assert_equal("", r.read) + end + + t = Tempfile.new(["test_ruby_test_require", ".rb"]) + t.puts "p :ok" + t.close + ENV["RUBYPATH"] = "~" + ENV["HOME"], name = File.split(t.path) + ruby("-S", name) do |w, r, e| + w.close + assert_equal(":ok", r.read.chomp) + assert_equal("", e.read) + end + + ensure + env_rubypath ? ENV["RUBYPATH"] = env_rubypath : ENV.delete("RUBYPATH") + env_home ? ENV["HOME"] = env_home : ENV.delete("HOME") + end + + def test_define_class + begin + require "socket" + rescue LoadError + return + end + + ruby do |w, r, e| + w.puts "BasicSocket = 1" + w.puts "begin" + w.puts " require 'socket'" + w.puts " p :ng" + w.puts "rescue TypeError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + + ruby do |w, r, e| + w.puts "class BasicSocket; end" + w.puts "begin" + w.puts " require 'socket'" + w.puts " p :ng" + w.puts "rescue NameError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + + ruby do |w, r, e| + w.puts "class BasicSocket < IO; end" + w.puts "begin" + w.puts " require 'socket'" + w.puts " p :ok" + w.puts "rescue Exception" + w.puts " p :ng" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + end + + def test_define_class_under + begin + require "zlib" + rescue LoadError + return + end + + ruby do |w, r, e| + w.puts "module Zlib; end" + w.puts "Zlib::Error = 1" + w.puts "begin" + w.puts " require 'zlib'" + w.puts " p :ng" + w.puts "rescue TypeError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + + ruby do |w, r, e| + w.puts "module Zlib; end" + w.puts "class Zlib::Error; end" + w.puts "begin" + w.puts " require 'zlib'" + w.puts " p :ng" + w.puts "rescue NameError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + + ruby do |w, r, e| + w.puts "module Zlib; end" + w.puts "class Zlib::Error < StandardError; end" + w.puts "begin" + w.puts " require 'zlib'" + w.puts " p :ok" + w.puts "rescue Exception" + w.puts " p :ng" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + end + + def test_define_module + begin + require "zlib" + rescue LoadError + return + end + + ruby do |w, r, e| + w.puts "Zlib = 1" + w.puts "begin" + w.puts " require 'zlib'" + w.puts " p :ng" + w.puts "rescue TypeError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + end + + def test_define_module_under + begin + require "socket" + rescue LoadError + return + end + + ruby do |w, r, e| + w.puts "class BasicSocket < IO; end" + w.puts "class Socket < BasicSocket; end" + w.puts "Socket::Constants = 1" + w.puts "begin" + w.puts " require 'socket'" + w.puts " p :ng" + w.puts "rescue TypeError" + w.puts " p :ok" + w.puts "end" + w.close + assert_equal("", e.read) + assert_equal(":ok", r.read.chomp) + end + end +end Property changes on: test/ruby/test_require.rb ___________________________________________________________________ Name: svn:eol-style + LF Index: test/ruby/test_class.rb =================================================================== --- test/ruby/test_class.rb (revision 16509) +++ test/ruby/test_class.rb (revision 16510) @@ -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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/