1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require 'prime'
# -- Tests ----
class PrintersTest < Test::Unit::TestCase
def setup
RubyProf::measure_mode = RubyProf::PROCESS_TIME
@result = RubyProf.profile do
run_primes
end
end
def test_printers
printer = RubyProf::FlatPrinter.new(@result)
printer.print(STDOUT)
printer = RubyProf::GraphHtmlPrinter.new(@result)
printer.print
printer = RubyProf::GraphPrinter.new(@result)
printer.print
printer = RubyProf::CallTreePrinter.new(@result)
printer.print(STDOUT)
# we should get here
assert(true)
end
def test_flat_string
output = ''
printer = RubyProf::FlatPrinter.new(@result)
assert_nothing_raised { printer.print(output) }
assert_match(/Thread ID: -?\d+/i, output)
assert_match(/Total: \d+\.\d+/i, output)
assert_match(/Object#run_primes/i, output)
end
def test_graph_html_string
output = ''
printer = RubyProf::GraphHtmlPrinter.new(@result)
assert_nothing_raised { printer.print(output) }
assert_match( /DTD HTML 4\.01/i, output )
assert_match( %r{<th>Total Time</th>}i, output )
assert_match( /Object#run_primes/i, output )
end
def test_graph_string
output = ''
printer = RubyProf::GraphPrinter.new(@result)
assert_nothing_raised { printer.print(output) }
assert_match( /Thread ID: -?\d+/i, output )
assert_match( /Total Time: \d+\.\d+/i, output )
assert_match( /Object#run_primes/i, output )
end
def test_call_tree_string
output = ''
printer = RubyProf::CallTreePrinter.new(@result)
assert_nothing_raised { printer.print(output) }
assert_match(/fn=Object::find_primes/i, output)
assert_match(/events: process_time/i, output)
end
end
|