test/printers_test.rb in ruby-prof-0.9.1 vs test/printers_test.rb in ruby-prof-0.9.2

- old
+ new

@@ -1,22 +1,29 @@ #!/usr/bin/env ruby require 'test/unit' require 'ruby-prof' require 'prime' +require 'stringio' +require 'fileutils' +require 'rubygems' # -- Tests ---- class PrintersTest < Test::Unit::TestCase def go - run_primes(10000) + run_primes(1000) end def setup - RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test + RubyProf::measure_mode = RubyProf::WALL_TIME # WALL_TIME so we can use sleep in our test and get same measurements on linux and doze @result = RubyProf.profile do - run_primes(10000) - go + begin + run_primes(1000) + go + rescue => e + p e + end end end def test_printers @@ -35,19 +42,29 @@ printer = RubyProf::GraphPrinter.new(@result) printer.print(output) printer = RubyProf::CallTreePrinter.new(@result) printer.print(output) + output_dir = 'examples2' + if ENV['SAVE_NEW_PRINTER_EXAMPLES'] + output_dir = 'examples' + end + FileUtils.mkdir_p output_dir + printer = RubyProf::DotPrinter.new(@result) - File.open("examples/graph.dot", "w") {|f| printer.print(f)} + File.open("#{output_dir}/graph.dot", "w") {|f| printer.print(f)} printer = RubyProf::CallStackPrinter.new(@result) - File.open("examples/stack.html", "w") {|f| printer.print(f, :application => "primes")} + File.open("#{output_dir}/stack.html", "w") {|f| printer.print(f, :application => "primes")} printer = RubyProf::MultiPrinter.new(@result) - printer.print(:path => "examples", :profile => "multi", :application => "primes") + printer.print(:path => "#{output_dir}", :profile => "multi", :application => "primes") + for file in ['empty.png', 'graph.dot', 'minus.png', 'multi.flat.txt', 'multi.graph.html', 'multi.grind.dat', 'multi.stack.html', 'plus.png', 'stack.html'] + existant_file = output_dir + '/' + file + assert File.size(existant_file) > 0 + end end end def test_flat_string output = helper_test_flat_string RubyProf::FlatPrinter @@ -71,16 +88,22 @@ assert_match(/prime.rb/, output) assert_no_match(/ruby_runtime:0/, output) assert_match(/called from/, output) # should combine common parents - if RUBY_VERSION < '1.9' - assert_equal(3, output.scan(/Object#is_prime/).length) - else - # 1.9 - assert_equal(2, output.scan(/Object#is_prime/).length) - end - assert_no_match(/\.\/test\/prime.rb/, output) # don't use relative paths + # lodo remove... + #if RUBY_VERSION < '1.9' + #require 'ruby-debug' + #debugger + #print output + assert_equal(3, output.scan(/Object#is_prime/).length) # failing this is prolly a 1.9.2 core bug + #else + # # 1.9 + # require 'ruby-debug' + # debugger + # assert_equal(2, output.scan(/Object#is_prime/).length) + #end + assert_no_match(/\.\/test\/prime.rb/, output) # don't use relative paths end def test_graph_html_string output = '' printer = RubyProf::GraphHtmlPrinter.new(@result)