Skip to content

Commit

Permalink
Allow Pathname objects for Stackprof :out
Browse files Browse the repository at this point in the history
The code for `stackprof_results` currently only does checks to see if
the VALUE for `_stackprof.out` is a `T_STRING`, otherwise it assumes it
is an IO object.

This updates the code to first check if `Pathname` has been required and
defined.  If it is and the `_stackprof.out` is a `Pathname`, then open a
file in the same manner as if it was a string, but calls `.to_s` to
convert it to a ruby string first.

Fixes #79
  • Loading branch information
tenderlove committed Jan 6, 2019
1 parent eba085e commit fd7d6fc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/test_stackprof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'stackprof'
require 'minitest/autorun'
require 'tempfile'
require 'pathname'

class StackProfTest < MiniTest::Test
def test_info
Expand Down Expand Up @@ -180,6 +181,19 @@ def test_out_to_path_string
refute_empty profile[:frames]
end

def test_pathname_out
tmpfile = Tempfile.new('stackprof-out')
pathname = Pathname.new(tmpfile.path)
ret = StackProf.run(mode: :custom, out: pathname) do
StackProf.sample
end

assert_equal tmpfile.path, ret.path
tmpfile.rewind
profile = Marshal.load(tmpfile.read)
refute_empty profile[:frames]
end

def math
250_000.times do
2 ** 10
Expand Down

0 comments on commit fd7d6fc

Please sign in to comment.