File: printers_test.rb

package info (click to toggle)
ruby-prof 0.6.0-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 412 kB
  • ctags: 343
  • sloc: ruby: 1,669; ansic: 1,138; makefile: 29
file content (74 lines) | stat: -rwxr-xr-x 1,869 bytes parent folder | download
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
72
73
74
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require 'prime'
require 'test_helper'


# --  Tests ----
class PrintersTest < Test::Unit::TestCase
  
  def setup
    @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_flatprinter_duckfriendliness
    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_graphhtmlprinter_duckfriendliness
    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_graphprinter_duckfriendliness
    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_calltreeprinter_duckfriendliness
    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