Skip to content

Commit

Permalink
Various fixes to make testing easier:
Browse files Browse the repository at this point in the history
* Support for 1.8.7 and 1.9.* load paths
* Add 1.9 encodings to each file
* Load the shared library from local lib directory instead of installed gem - makes testing much quicker/easier.
* Centralize path management for tests in test_helper.
* Adopt the lib/1.8 and lib/1.9 standard for fat gems for Windows.
  • Loading branch information
Charlie Savage committed Sep 5, 2011
1 parent 364ea80 commit 8b80da8
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 82 deletions.
18 changes: 9 additions & 9 deletions lib/ruby-prof.rb
@@ -1,12 +1,13 @@
# require the .so file...
require File.dirname(__FILE__) + "/../ext/ruby_prof/ruby_prof"
# Load the C-based binding.
begin
RUBY_VERSION =~ /(\d+.\d+)/
require "#{$1}/ruby_prof"
rescue LoadError
require "ruby_prof"
end


module RubyProf

if RUBY_VERSION < '1.8.7'
require File.dirname(__FILE__) + '/ruby-prof/symbol_to_proc'
end

def self.camelcase(phrase)
('_' + phrase).gsub(/_([a-z])/){|b| b[1..1].upcase}
end
Expand All @@ -28,7 +29,6 @@ def self.camelcase(phrase)

# we don't require unprof.rb, as well, purposefully


# Checks if the user specified the clock mode via
# the RUBY_PROF_MEASURE_MODE environment variable
def self.figure_measure_mode
Expand Down Expand Up @@ -64,4 +64,4 @@ def self.figure_measure_mode
end
end

RubyProf::figure_measure_mode
RubyProf::figure_measure_mode
4 changes: 2 additions & 2 deletions test/aggregate_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

# Test data
# A B C
Expand Down
4 changes: 2 additions & 2 deletions test/basic_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

class C1
def C1.hello
Expand Down
4 changes: 2 additions & 2 deletions test/duplicate_names_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

class DuplicateNames < Test::Unit::TestCase
def test_names
Expand Down
4 changes: 2 additions & 2 deletions test/enumerable_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

# -- Test for bug
# http://github.com/rdp/ruby-prof/issues#issue/12
Expand Down
5 changes: 3 additions & 2 deletions test/exceptions_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'

class ExceptionsTest < Test::Unit::TestCase
def test_profile
Expand Down
4 changes: 2 additions & 2 deletions test/exclude_threads_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'


# -- Tests ----
Expand Down
4 changes: 2 additions & 2 deletions test/exec_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'os'
require './test_helper'

# -- Test for bug when it loads with no frames

Expand Down
5 changes: 3 additions & 2 deletions test/line_number_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'
require 'prime'

class LineNumbers
Expand Down
5 changes: 3 additions & 2 deletions test/measurement_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'

class MeasurementTest < Test::Unit::TestCase
def setup
Expand Down
4 changes: 2 additions & 2 deletions test/method_elimination_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'
require 'tmpdir'

# Test data
Expand Down
5 changes: 3 additions & 2 deletions test/module_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'

# Need to use wall time for this test due to the sleep calls
RubyProf::measure_mode = RubyProf::WALL_TIME
Expand Down
4 changes: 2 additions & 2 deletions test/multi_printer_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'
require 'tmpdir'

# Test data
Expand Down
4 changes: 3 additions & 1 deletion test/no_method_class_test.rb
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'

# Make sure this works with no class or method
result = RubyProf.profile do
Expand Down
6 changes: 3 additions & 3 deletions test/prime_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require 'prime'
# encoding: UTF-8

require './test_helper'

# -- Tests ----
class PrimeTest< Test::Unit::TestCase
Expand Down
8 changes: 4 additions & 4 deletions test/printers_test.rb
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
require File.dirname(__FILE__) + '/prime'
# encoding: UTF-8

require './test_helper'
require './prime'
require 'stringio'
require 'fileutils'
require 'rubygems'

# -- Tests ----
class PrintersTest < Test::Unit::TestCase
Expand Down
5 changes: 3 additions & 2 deletions test/recursive_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'

def simple(n)
sleep(1)
Expand Down
4 changes: 2 additions & 2 deletions test/singleton_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'
require 'timeout'

# -- Test for bug [#5657]
Expand Down
4 changes: 2 additions & 2 deletions test/stack_printer_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'
require 'tmpdir'

# Test data
Expand Down
4 changes: 2 additions & 2 deletions test/stack_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

# Test data
# A
Expand Down
4 changes: 2 additions & 2 deletions test/start_stop_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

class StartStopTest < Test::Unit::TestCase
def setup
Expand Down
14 changes: 14 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,14 @@
# encoding: UTF-8

# To make testing/debugging easier, test within this source tree versus an installed gem

dir = File.dirname(__FILE__)
root = File.expand_path(File.join(dir, '..'))
lib = File.expand_path(File.join(root, 'lib'))
ext = File.expand_path(File.join(root, 'ext', 'ruby_prof'))

$LOAD_PATH << lib
$LOAD_PATH << ext

require 'ruby-prof'
require 'test/unit'
48 changes: 21 additions & 27 deletions test/test_suite.rb
@@ -1,32 +1,26 @@
begin
require 'rubygems'
require 'redgreen'
rescue LoadError
end
require './test_helper'

require 'test/unit'

require 'aggregate_test'
require 'basic_test'
require 'duplicate_names_test'
require 'exceptions_test'
require 'line_number_test'
require 'measurement_test'
require 'module_test'
require 'no_method_class_test'
require 'prime_test'
require 'printers_test'
require 'recursive_test'
require 'singleton_test'
require 'stack_test'
require 'start_stop_test'
require 'thread_test'
require 'unique_call_path_test'
require 'stack_printer_test'
require 'multi_printer_test'
require 'method_elimination_test'
require './aggregate_test'
require './basic_test'
require './duplicate_names_test'
require './exceptions_test'
require './line_number_test'
require './measurement_test'
require './module_test'
require './no_method_class_test'
require './prime_test'
require './printers_test'
require './recursive_test'
require './singleton_test'
require './stack_test'
require './start_stop_test'
require './thread_test'
require './unique_call_path_test'
require './stack_printer_test'
require './multi_printer_test'
require './method_elimination_test'

# Can't use this one here cause it breaks
# the rest of the unit tets (Ruby Prof gets
# started twice).
#require 'profile_unit_test'
#require './profile_unit_test'
5 changes: 3 additions & 2 deletions test/thread_test.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'test/unit'
require 'ruby-prof'
# encoding: UTF-8

require './test_helper'
require 'timeout'

# -- Tests ----
Expand Down
4 changes: 2 additions & 2 deletions test/unique_call_path_test.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: UTF-8

require 'test/unit'
require 'ruby-prof'
require './test_helper'

class UniqueCallPath
def method_a(i)
Expand Down

0 comments on commit 8b80da8

Please sign in to comment.