Sha256: d7cd2b4d14294c869e0de0abe0eedae9660272ada071a70bfb19997e4c5d5c2b

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

#!/usr/bin/env ruby
require 'test/unit'
require 'rubygems'; require 'require_relative'
# 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 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|
          assert_equal(true, subcmd_obj.class.constants.member?(attr),
                       "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.0-universal-rubinius-2.0 test/unit/test-base-subcmd.rb
rbx-trepanning-0.1.0-universal-rubinius-1.2 test/unit/test-base-subcmd.rb