Sha256: 73a0316c99026875e5d19e80b76fc3e7f91743d895ec0ead9195fde506cdd43e

Contents?: true

Size: 1.78 KB

Versions: 16

Compression:

Stored size: 1.78 KB

Contents

#!/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

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
adamh-ruby-prof-0.7.3 test/printers_test.rb
ruby-prof-0.7.9 test/printers_test.rb
ruby-prof-0.7.8 test/printers_test.rb
ruby-prof-0.7.7 test/printers_test.rb
ruby-prof-0.7.6 test/printers_test.rb
ruby-prof-0.7.5 test/printers_test.rb
ruby-prof-0.7.4 test/printers_test.rb
rdp-ruby-prof-0.7.4 test/printers_test.rb
ruby-prof-0.7.0-x86-mswin32-60 test/printers_test.rb
ruby-prof-0.7.0 test/printers_test.rb
ruby-prof-0.7.1 test/printers_test.rb
ruby-prof-0.7.3 test/printers_test.rb
ruby-prof-0.7.3-x86-mswin32-60 test/printers_test.rb
ruby-prof-0.7.2-x86-mswin32-60 test/printers_test.rb
ruby-prof-0.7.2 test/printers_test.rb
ruby-prof-0.7.1-x86-mswin32-60 test/printers_test.rb