Index: EcnlProtoTool/trunk/mruby-2.1.1/test/t/module.rb
===================================================================
--- EcnlProtoTool/trunk/mruby-1.3.0/test/t/module.rb	(revision 331)
+++ EcnlProtoTool/trunk/mruby-2.1.1/test/t/module.rb	(revision 439)
@@ -4,5 +4,5 @@
 def labeled_module(name, &block)
   Module.new do
-    singleton_class.class_eval do
+    (class <<self; self end).class_eval do
       define_method(:to_s) { name }
       alias_method :inspect, :to_s
@@ -14,5 +14,5 @@
 def labeled_class(name, supklass = Object, &block)
   Class.new(supklass) do
-    singleton_class.class_eval do
+    (class <<self; self end).class_eval do
       define_method(:to_s) { name }
       alias_method :inspect, :to_s
@@ -22,16 +22,32 @@
 end
 
+def assert_uninitialized_const(&block)
+  assert_raise_with_message_pattern(NameError, "uninitialized constant *", &block)
+end
+
+def assert_wrong_const_name(&block)
+  assert_raise_with_message_pattern(NameError, "wrong constant name *", &block)
+end
+
 assert('Module', '15.2.2') do
   assert_equal Class, Module.class
 end
 
+assert('Module#alias_method', '15.2.2.4.8') do
+  cls = Class.new do
+    def foo
+      "FOO"
+    end
+  end
+
+  assert_same(cls, cls.alias_method(:bar, :foo))
+  assert_equal("FOO", cls.new.bar)
+end
+
 # TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do
-
-# TODO not implemented ATM assert('Module.nesting', '15.2.2.3.2') do
 
 assert('Module#ancestors', '15.2.2.4.9') do
   class Test4ModuleAncestors
   end
-  sc = Test4ModuleAncestors.singleton_class
   r = String.ancestors
 
@@ -52,4 +68,5 @@
 
   assert_equal Test4AppendFeatures2, Test4AppendFeatures2.const_get(:Const4AppendFeatures2)
+  assert_raise(FrozenError) { Module.new.append_features Class.new.freeze }
 end
 
@@ -202,54 +219,7 @@
     end
   end
-  r = Test4ClassEval.instance_methods
-
   assert_equal 11, Test4ClassEval.class_eval{ @a }
   assert_equal 12, Test4ClassEval.class_eval{ @b }
-  assert_equal Array, r.class
-  assert_true r.include?(:method1)
-end
-
-assert('Module#class_variable_defined?', '15.2.2.4.16') do
-  class Test4ClassVariableDefined
-    @@cv = 99
-  end
-
-  assert_true Test4ClassVariableDefined.class_variable_defined?(:@@cv)
-  assert_false Test4ClassVariableDefined.class_variable_defined?(:@@noexisting)
-end
-
-assert('Module#class_variable_get', '15.2.2.4.17') do
-  class Test4ClassVariableGet
-    @@cv = 99
-  end
-
-  assert_equal 99, Test4ClassVariableGet.class_variable_get(:@@cv)
-end
-
-assert('Module#class_variable_set', '15.2.2.4.18') do
-  class Test4ClassVariableSet
-    @@foo = 100
-    def foo
-      @@foo
-    end
-  end
-
-  assert_true Test4ClassVariableSet.class_variable_set(:@@cv, 99)
-  assert_true Test4ClassVariableSet.class_variable_set(:@@foo, 101)
-  assert_true Test4ClassVariableSet.class_variables.include? :@@cv
-  assert_equal 99, Test4ClassVariableSet.class_variable_get(:@@cv)
-  assert_equal 101, Test4ClassVariableSet.new.foo
-end
-
-assert('Module#class_variables', '15.2.2.4.19') do
-  class Test4ClassVariables1
-    @@var1 = 1
-  end
-  class Test4ClassVariables2 < Test4ClassVariables1
-    @@var2 = 2
-  end
-
-  assert_equal [:@@var1], Test4ClassVariables1.class_variables
-  assert_equal [:@@var2, :@@var1], Test4ClassVariables2.class_variables
+  assert_equal true, Test4ClassEval.new.respond_to?(:method1)
 end
 
@@ -261,4 +231,5 @@
   assert_true Test4ConstDefined.const_defined?(:Const4Test4ConstDefined)
   assert_false Test4ConstDefined.const_defined?(:NotExisting)
+  assert_wrong_const_name{ Test4ConstDefined.const_defined?(:wrong_name) }
 end
 
@@ -269,4 +240,39 @@
 
   assert_equal 42, Test4ConstGet.const_get(:Const4Test4ConstGet)
+  assert_equal 42, Test4ConstGet.const_get("Const4Test4ConstGet")
+  assert_equal 42, Object.const_get("Test4ConstGet::Const4Test4ConstGet")
+
+  assert_raise(TypeError){ Test4ConstGet.const_get(123) }
+  assert_uninitialized_const{ Test4ConstGet.const_get(:I_DO_NOT_EXIST) }
+  assert_uninitialized_const{ Test4ConstGet.const_get("I_DO_NOT_EXIST::ME_NEITHER") }
+  assert_wrong_const_name{ Test4ConstGet.const_get(:wrong_name) }
+end
+
+assert('Module#const_set', '15.2.2.4.23') do
+  module Test4ConstSet
+    Const4Test4ConstSet = 42
+  end
+
+  assert_equal 23, Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
+  assert_equal 23, Test4ConstSet.const_get(:Const4Test4ConstSet)
+  ["", "wrongNAME", "Wrong-Name"].each do |n|
+    assert_wrong_const_name { Test4ConstSet.const_set(n, 1) }
+  end
+end
+
+assert('Module#remove_const', '15.2.2.4.40') do
+  module Test4RemoveConst
+    ExistingConst = 23
+  end
+
+  assert_equal 23, Test4RemoveConst.remove_const(:ExistingConst)
+  assert_false Test4RemoveConst.const_defined?(:ExistingConst)
+  assert_raise_with_message_pattern(NameError, "constant * not defined") do
+    Test4RemoveConst.remove_const(:NonExistingConst)
+  end
+  %i[x X!].each do |n|
+    assert_wrong_const_name { Test4RemoveConst.remove_const(n) }
+  end
+  assert_raise(FrozenError) { Test4RemoveConst.freeze.remove_const(:A) }
 end
 
@@ -281,26 +287,14 @@
 end
 
-assert('Module#const_get', '15.2.2.4.23') do
-  module Test4ConstSet
-    Const4Test4ConstSet = 42
-  end
-
-  assert_true Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
-  assert_equal 23, Test4ConstSet.const_get(:Const4Test4ConstSet)
-end
-
-assert('Module#constants', '15.2.2.4.24') do
-  $n = []
-  module TestA
-    C = 1
-  end
-  class TestB
-    include TestA
-    C2 = 1
-    $n = constants.sort
-  end
-
-  assert_equal [ :C ], TestA.constants
-  assert_equal [ :C, :C2 ], $n
+assert('Module#extend_object', '15.2.2.4.25') do
+  cls = Class.new
+  mod = Module.new { def foo; end }
+  a = cls.new
+  b = cls.new
+  mod.extend_object(b)
+  assert_false a.respond_to?(:foo)
+  assert_true b.respond_to?(:foo)
+  assert_raise(FrozenError) { mod.extend_object(cls.new.freeze) }
+  assert_raise(FrozenError, TypeError) { mod.extend_object(1) }
 end
 
@@ -310,8 +304,13 @@
   end
   module Test4Include2
-    include Test4Include
+    @include_result = include Test4Include
+    class << self
+      attr_reader :include_result
+    end
   end
 
   assert_equal 42, Test4Include2.const_get(:Const4Include)
+  assert_equal Test4Include2, Test4Include2.include_result
+  assert_raise(FrozenError) { Module.new.freeze.include Test4Include }
 end
 
@@ -345,44 +344,12 @@
 end
 
-assert('Module#included_modules', '15.2.2.4.30') do
-  module Test4includedModules
-  end
-  module Test4includedModules2
-    include Test4includedModules
-  end
-  r = Test4includedModules2.included_modules
-
-  assert_equal Array, r.class
-  assert_true r.include?(Test4includedModules)
-end
-
 assert('Module#initialize', '15.2.2.4.31') do
   assert_kind_of Module, Module.new
   mod = Module.new { def hello; "hello"; end }
-  assert_equal [:hello], mod.instance_methods
+  cls = Class.new{include mod}
+  assert_true cls.new.respond_to?(:hello)
   a = nil
   mod = Module.new { |m| a = m }
   assert_equal mod, a
-end
-
-assert('Module#instance_methods', '15.2.2.4.33') do
-  module Test4InstanceMethodsA
-    def method1()  end
-  end
-  class Test4InstanceMethodsB
-    def method2()  end
-  end
-  class Test4InstanceMethodsC < Test4InstanceMethodsB
-    def method3()  end
-  end
-
-  r = Test4InstanceMethodsC.instance_methods(true)
-
-  assert_equal [:method1], Test4InstanceMethodsA.instance_methods
-  assert_equal [:method2], Test4InstanceMethodsB.instance_methods(false)
-  assert_equal [:method3], Test4InstanceMethodsC.instance_methods(false)
-  assert_equal Array, r.class
-  assert_true r.include?(:method3)
-  assert_true r.include?(:method2)
 end
 
@@ -410,5 +377,4 @@
 end
 
-
 assert('Module#module_eval', '15.2.2.4.35') do
   module Test4ModuleEval
@@ -419,53 +385,4 @@
   assert_equal 11, Test4ModuleEval.module_eval{ @a }
   assert_equal 12, Test4ModuleEval.module_eval{ @b }
-end
-
-assert('Module#remove_class_variable', '15.2.2.4.39') do
-  class Test4RemoveClassVariable
-    @@cv = 99
-  end
-
-  assert_equal 99, Test4RemoveClassVariable.remove_class_variable(:@@cv)
-  assert_false Test4RemoveClassVariable.class_variables.include? :@@cv
-end
-
-assert('Module#remove_const', '15.2.2.4.40') do
-  module Test4RemoveConst
-    ExistingConst = 23
-  end
-
-  result = Test4RemoveConst.module_eval { remove_const :ExistingConst }
-
-  name_error = false
-  begin
-    Test4RemoveConst.module_eval { remove_const :NonExistingConst }
-  rescue NameError
-    name_error = true
-  end
-
-  # Constant removed from Module
-  assert_false Test4RemoveConst.const_defined? :ExistingConst
-  # Return value of binding
-  assert_equal 23, result
-  # Name Error raised when Constant doesn't exist
-  assert_true name_error
-end
-
-assert('Module#remove_method', '15.2.2.4.41') do
-  module Test4RemoveMethod
-    class Parent
-      def hello
-      end
-     end
-
-     class Child < Parent
-      def hello
-      end
-    end
-  end
-
-  assert_true Test4RemoveMethod::Child.class_eval{ remove_method :hello }
-  assert_true Test4RemoveMethod::Child.instance_methods.include? :hello
-  assert_false Test4RemoveMethod::Child.instance_methods(false).include? :hello
 end
 
@@ -490,8 +407,30 @@
   assert_false Test4UndefMethod::Child.new.respond_to?(:hello)
   assert_false Test4UndefMethod::GrandChild.new.respond_to?(:hello)
-  assert_false Test4UndefMethod::Child.instance_methods(false).include? :hello
 end
 
 # Not ISO specified
+
+assert('Module#dup') do
+  module TestModuleDup
+    @@cvar = :cvar
+    class << self
+      attr_accessor :cattr
+      def cmeth; :cmeth end
+    end
+    def cvar; @@cvar end
+    def imeth; :imeth end
+    self.cattr = :cattr
+  end
+
+  m = TestModuleDup.dup
+  o = Object.include(m).new
+  assert_equal(:cattr, m.cattr)
+  assert_equal(:cmeth, m.cmeth)
+  assert_equal(:cvar, o.cvar)
+  assert_equal(:imeth, o.imeth)
+  assert_match("#<Module:0x*>", m.to_s)
+  assert_not_predicate(m, :frozen?)
+  assert_not_predicate(TestModuleDup.freeze.dup, :frozen?)
+end
 
 assert('Module#define_method') do
@@ -507,4 +446,13 @@
 end
 
+assert 'Module#prepend_features' do
+  mod = Module.new { def m; :mod end }
+  cls = Class.new { def m; :cls end }
+  assert_equal :cls, cls.new.m
+  mod.prepend_features(cls)
+  assert_equal :mod, cls.new.m
+  assert_raise(FrozenError) { Module.new.prepend_features(Class.new.freeze) }
+end
+
 # @!group prepend
   assert('Module#prepend') do
@@ -539,4 +487,16 @@
     expected = [:M2,[:M3,[:C1,[:M4,[:M1,[:C0,[:M0],:C0],:M1],:M4],:C1],:M3],:M2]
     assert_equal(expected, obj.m1)
+  end
+
+  assert('Module#prepend result') do
+    module TestPrepended; end
+    module TestPrependResult
+      @prepend_result = prepend TestPrepended
+      class << self
+        attr_reader :prepend_result
+      end
+    end
+
+    assert_equal TestPrependResult, TestPrependResult.prepend_result
   end
 
@@ -573,39 +533,4 @@
     bug8357 = '[ruby-core:54742] [Bug #8357]'
     assert_kind_of(b, c.new, bug8357)
-  end
-
-  assert('Moduler#prepend + #instance_methods') do
-    bug6655 = '[ruby-core:45915]'
-    assert_equal(Object.instance_methods, Class.new {prepend Module.new}.instance_methods, bug6655)
-  end
-
-  assert 'Module#prepend + #singleton_methods' do
-    o = Object.new
-    o.singleton_class.class_eval {prepend Module.new}
-    assert_equal([], o.singleton_methods)
-  end
-
-  assert 'Module#prepend + #remove_method' do
-    c = Class.new do
-      prepend Module.new { def foo; end }
-    end
-    assert_raise(NameError) do
-      c.class_eval do
-        remove_method(:foo)
-      end
-    end
-    c.class_eval do
-      def foo; end
-    end
-    removed = nil
-    c.singleton_class.class_eval do
-      define_method(:method_removed) {|id| removed = id}
-    end
-    assert_nothing_raised(NoMethodError, NameError, '[Bug #7843]') do
-      c.class_eval do
-        remove_method(:foo)
-      end
-    end
-    assert_equal(:foo, removed)
   end
 
@@ -650,10 +575,4 @@
   end
 
-  assert 'Module#prepend #instance_methods(false)' do
-    bug6660 = '[ruby-dev:45863]'
-    assert_equal([:m1], Class.new{ prepend Module.new; def m1; end }.instance_methods(false), bug6660)
-    assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false), bug6660)
-  end
-
   assert 'cyclic Module#prepend' do
     bug7841 = '[ruby-core:52205] [Bug #7841]'
@@ -666,5 +585,5 @@
   end
 
-  # these assertions will not run without a #assert_seperately method
+  # these assertions will not run without a #assert_separately method
   #assert 'test_prepend_optmethod' do
   #  bug7983 = '[ruby-dev:47124] [Bug #7983]'
@@ -682,74 +601,59 @@
 
   # mruby has no visibility control
-  assert 'Module#prepend visibility' do
-    bug8005 = '[ruby-core:53106] [Bug #8005]'
-    c = Class.new do
-      prepend Module.new {}
-      def foo() end
-      protected :foo
-    end
-    a = c.new
-    assert_true a.respond_to?(:foo), bug8005
-    assert_nothing_raised(NoMethodError, bug8005) {a.send :foo}
-  end
+  # assert 'Module#prepend visibility' do
+  #   bug8005 = '[ruby-core:53106] [Bug #8005]'
+  #   c = Class.new do
+  #     prepend Module.new {}
+  #     def foo() end
+  #     protected :foo
+  #   end
+  #   a = c.new
+  #   assert_true a.respond_to?(:foo), bug8005
+  #   assert_nothing_raised(bug8005) {a.send :foo}
+  # end
 
   # mruby has no visibility control
-  assert 'Module#prepend inherited visibility' do
-    bug8238 = '[ruby-core:54105] [Bug #8238]'
-    module Test4PrependVisibilityInherited
-      class A
-        def foo() A; end
-        private :foo
-      end
-      class B < A
-        public :foo
-        prepend Module.new
-      end
-    end
-    assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}")
-  end
-
-  assert 'Module#prepend + #included_modules' do
-    bug8025 = '[ruby-core:53158] [Bug #8025]'
-    mixin = labeled_module("mixin")
-    c = labeled_module("c") {prepend mixin}
-    im = c.included_modules
-    assert_not_include(im, c, bug8025)
-    assert_include(im, mixin, bug8025)
-    c1 = labeled_class("c1") {prepend mixin}
-    c2 = labeled_class("c2", c1)
-    im = c2.included_modules
-    assert_not_include(im, c1, bug8025)
-    assert_not_include(im, c2, bug8025)
-    assert_include(im, mixin, bug8025)
-  end
-
-  assert 'Module#prepend super in alias' do
-    skip "super does not currently work in aliased methods"
-    bug7842 = '[Bug #7842]'
-
-    p = labeled_module("P") do
-      def m; "P"+super; end
-    end
-
-    a = labeled_class("A") do
-      def m; "A"; end
-    end
-
-    b = labeled_class("B", a) do
-      def m; "B"+super; end
-      alias m2 m
-      prepend p
-      alias m3 m
-    end
-
-    assert_nothing_raised do
-      assert_equal("BA", b.new.m2, bug7842)
-    end
-
-    assert_nothing_raised do
-      assert_equal("PBA", b.new.m3, bug7842)
-    end
-  end
+  # assert 'Module#prepend inherited visibility' do
+  #   bug8238 = '[ruby-core:54105] [Bug #8238]'
+  #   module Test4PrependVisibilityInherited
+  #     class A
+  #       def foo() A; end
+  #       private :foo
+  #     end
+  #     class B < A
+  #       public :foo
+  #       prepend Module.new
+  #     end
+  #   end
+  #   assert_equal(Test4PrependVisibilityInherited::A, Test4PrependVisibilityInherited::B.new.foo, "#{bug8238}")
+  # end
+
+  # assert 'Module#prepend super in alias' do
+  #   skip "super does not currently work in aliased methods"
+  #   bug7842 = '[Bug #7842]'
+
+  #   p = labeled_module("P") do
+  #     def m; "P"+super; end
+  #   end
+
+  #   a = labeled_class("A") do
+  #     def m; "A"; end
+  #   end
+
+  #   b = labeled_class("B", a) do
+  #     def m; "B"+super; end
+  #     alias m2 m
+  #     prepend p
+  #     alias m3 m
+  #   end
+
+  #   assert_nothing_raised do
+  #     assert_equal("BA", b.new.m2, bug7842)
+  #   end
+
+  #   assert_nothing_raised do
+  #     assert_equal("PBA", b.new.m3, bug7842)
+  #   end
+  # end
 
   assert 'Module#prepend each class' do
@@ -774,5 +678,5 @@
   end
 
-  # requires #assert_seperately
+  # requires #assert_separately
   #assert 'Module#prepend call super' do
   #  assert_separately([], <<-'end;') #do
@@ -785,11 +689,34 @@
   #  end;
   #end
+
+  assert 'Module#prepend to frozen class' do
+    assert_raise(FrozenError) { Class.new.freeze.prepend Module.new }
+  end
 # @!endgroup prepend
 
 assert('Module#to_s') do
-  module Test4to_sModules
-  end
-
-  assert_equal 'Test4to_sModules', Test4to_sModules.to_s
+  module Outer
+    class Inner; end
+    const_set :SetInner, Class.new
+  end
+
+  assert_equal 'Outer', Outer.to_s
+  assert_equal 'Outer::Inner', Outer::Inner.to_s
+  assert_equal 'Outer::SetInner', Outer::SetInner.to_s
+
+  outer = Module.new do
+    const_set :SetInner, Class.new
+  end
+  Object.const_set :SetOuter, outer
+
+  assert_equal 'SetOuter', SetOuter.to_s
+  assert_equal 'SetOuter::SetInner', SetOuter::SetInner.to_s
+
+  assert_match "#<Module:0x*>", Module.new.to_s
+  assert_match "#<Class:0x*>", Class.new.to_s
+
+  assert_equal "FrozenClassToS", (FrozenClassToS = Class.new.freeze).to_s
+  assert_equal "Outer::A", (Outer::A = Module.new.freeze).to_s
+  assert_match "#<Module:0x*>::A", (Module.new::A = Class.new.freeze).to_s
 end
 
@@ -819,6 +746,6 @@
   end
 
-  C1.new
-  C2.new
+  assert_kind_of(M1, C1.new)
+  assert_kind_of(M1, C2.new)
 end
 
@@ -834,5 +761,5 @@
   end
 
-  B.new.foo
+  assert_true(B.new.foo)
 end
 
@@ -849,4 +776,13 @@
   assert_raise(TypeError) { module 0::M1 end }
   assert_raise(TypeError) { module []::M2 end }
+end
+
+assert('module to return the last value') do
+  m = module M; :m end
+  assert_equal(m, :m)
+end
+
+assert('module to return nil if body is empty') do
+  assert_nil(module M end)
 end
 
