$:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'test/unit' require 'ruby-debug' class XmlPrinterTest < Test::Unit::TestCase def teardown Debugger.xml_debug = false end def test_print_msg interface = MockInterface.new printer = Debugger::XmlPrinter.new(interface) printer.print_msg('%s test', 'message') assert_equal(['message test'], interface.data) end def test_print_msg_with_debug Debugger.xml_debug = true interface = MockInterface.new printer = Debugger::XmlPrinter.new(interface) printer.print_msg('%s test', 'message') expected = ["message test"] assert_equal(expected, interface.data) end def test_print_debug Debugger.xml_debug = true interface = MockInterface.new printer = Debugger::XmlPrinter.new(interface) printer.print_debug('%s test', 'debug message 1') printer.print_debug('%s test', 'debug message 2') expected = [ "debug message 1 test", "debug message 2 test"] assert_equal(expected, interface.data) end def test_print_frames interface = MockInterface.new printer = Debugger::XmlPrinter.new(interface) Debugger.start begin context = MockContext.new(2) printer.print_frames(context, 0) ensure Debugger.stop end test_path = File.join(Dir.pwd, 'test.rb') expected = [ "", "", "", ""] assert_equal(expected, interface.data) end def test_print_at_line interface = MockInterface.new printer = Debugger::XmlPrinter.new(interface) Debugger.start begin printer.print_at_line('test.rb', 1) ensure Debugger.stop end test_path = File.join(Dir.pwd, 'test.rb') expected = [""] assert_equal(expected, interface.data) end class MockContext < Debugger::Context attr_accessor :stack_size def initialize(stack_size) @stack_size = stack_size end def frame_file(id) "test.rb" end def frame_line(id) id * 10 end end class MockInterface attr_accessor :data def initialize @data = [] end def print(*args) @data << format(*args) end end end