Sha256: eb2f1b7c5a7fa5bef13c42a4cdbe935f866496ad3183b3e0dde8339fa82fb939

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby
require 'test/unit'
require 'rubygems'; require 'require_relative'
require 'redcard/rubinius'
# require_relative '../../app/core'
require_relative '../../processor'
require_relative '../../processor/command/exit'
require_relative '../../processor/command/base/subcmd'

$errors = []
class TestBaseSubCommand < Test::Unit::TestCase

  Trepan::Subcommand.const_set(:NAME, 'bogus')
  def setup
    $errors   = []
    $msgs     = []
    @dbgr     = Trepan.new
    # @core     = Trepan::Core.new(@dbgr)
    @cmdproc  = Trepan::CmdProcessor.new(@dbgr)
    @cmds     = @cmdproc.instance_variable_get('@commands')
    @exit_cmd = @cmds['exit']
    @exit_subcmd = Trepan::Subcommand.new(@exit_cmd)
    def @exit_subcmd.msg(message)
      $msgs << message
    end
    def @exit_subcmd.errmsg(message)
      $errors << message
    end
  end

  def get_const(klass, name)
    name = name.to_sym if RedCard.check '1.9'
    if klass.constants.member?(name)
      klass.const_get(name)
    else
      nil
    end
  end

  def test_base_subcommand
    assert @exit_subcmd
    assert_raises RuntimeError do
      @exit_subcmd.run
    end
    assert_equal([], $errors)
    @exit_subcmd.run_set_int('', 'testing 1 2 3')
    assert_equal(1, $errors.size)
    assert_equal(Fixnum, @exit_subcmd.settings[:maxwidth].class)
    @cmds.each do |cmd_name, cmd_obj|
      next unless cmd_obj.is_a?(Trepan::SubcommandMgr)
      cmd_obj.subcmds.subcmds.each do |subcmd_name, subcmd_obj|
        %w(HELP NAME PREFIX).each do |attr|
          val = get_const(subcmd_obj.class, attr)
          assert_equal(true, !!val,
                       "Constant #{attr} should be defined in \"#{cmd_obj.name} #{subcmd_obj.class::NAME}\"")
        end
      end

    end
  end

  def test_show_on_off
    assert_equal('on', @exit_subcmd.show_onoff(true))
    assert_equal('off', @exit_subcmd.show_onoff(false))
    assert_equal('unset', @exit_subcmd.show_onoff(nil))
    assert_equal('??', @exit_subcmd.show_onoff(5))
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbx-trepanning-0.2.1-universal-rubinius-2.0 test/unit/test-base-subcmd.rb
rbx-trepanning-0.2.1-universal-rubinius-1.2 test/unit/test-base-subcmd.rb