generate_code (ZenTest)

    # File lib/zentest.rb, line 469
      def generate_code
        @result.unshift "# Code Generated by ZenTest v. #{VERSION}"

        if $DEBUG then
          @result.push "# found classes: #{@klasses.keys.join(', ')}"
          @result.push "# found test classes: #{@test_klasses.keys.join(', ')}"
        end

        if @missing_methods.size > 0 then
          @result.push ""
          @result.push "require 'test/unit/testcase'"
          @result.push "require 'test/unit' if $0 == __FILE__"
          @result.push ""
        end

        indentunit = "  "

        @missing_methods.keys.sort.each do |fullklasspath|

          methods = @missing_methods[fullklasspath]
          cls_methods = methods.keys.grep(/^(self\.|test_class_)/)
          methods.delete_if {|k,v| cls_methods.include? k }

          next if methods.empty? and cls_methods.empty?

          indent = 0
          is_test_class = self.is_test_class(fullklasspath)
          klasspath = fullklasspath.split(/::/)
          klassname = klasspath.pop

          klasspath.each do | modulename |
            m = self.get_class(modulename)
            type = m.nil? ? "module" : m.class.name.downcase
            @result.push indentunit*indent + "#{type} #{modulename}"
            indent += 1
          end
          @result.push indentunit*indent + "class #{klassname}" + (is_test_class ? " < Test::Unit::TestCase" : '')
          indent += 1

          meths = []

          cls_methods.sort.each do |method|
            meth = create_method(indentunit, indent, method)
            meths.push meth.join("\n")
          end

          methods.keys.sort.each do |method|
            next if method =~ /pretty_print/
            meth = create_method(indentunit, indent, method)
            meths.push meth.join("\n")
          end

          @result.push meths.join("\n\n")

          indent -= 1
          @result.push indentunit*indent + "end"
          klasspath.each do | modulename |
            indent -= 1
            @result.push indentunit*indent + "end"
          end
          @result.push ''
        end

        @result.push "# Number of errors detected: #{@error_count}"
        @result.push ''
      end