#!/usr/bin/env ruby # encoding: UTF-8 require File.expand_path('../test_helper', __FILE__) # Test data # A # / \ # B C # \ # B class MSTPT def a 100.times{b} 300.times{c} c;c;c end def b sleep 0 end def c 5.times{b} end end class MultiPrinterTest < TestCase def setup # Need to use wall time for this test due to the sleep calls RubyProf::measure_mode = RubyProf::WALL_TIME end def test_refuses_io_objects # we don't need a real profile for this test p = RubyProf::MultiPrinter.new nil begin p.print(STDOUT) flunk "should have raised an ArgumentError" rescue ArgumentError => e assert_match(/IO/, e.to_s) end end def test_refuses_non_hashes # we don't need a real profile for this test p = RubyProf::MultiPrinter.new nil begin p.print([]) flunk "should have raised an ArgumentError" rescue ArgumentError => e assert_match(/hash/, e.to_s) end end def test_all_profiles_can_be_created start_time = Time.now RubyProf.start 5.times{MSTPT.new.a} result = RubyProf.stop end_time = Time.now expected_time = end_time - start_time graph = print(result)[1] re = Regexp.new(' \s*
Thread ID | \s*(Fiber ID | )? \s*Total Time | \s*
---|---|---|
([\.0-9]+) | )? \s*-?\d+ | \s*([\.0-9e]+) | \s*