Sha256: b06f0335dc81b3a9452115a66b9aaf194a76d7016b8f66b7581676d872dc06cc

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require_relative 'helper'

class TestMemprof2 < Test::Unit::TestCase
  def rvalue_size
    GC::INTERNAL_CONSTANTS[:RVALUE_SIZE]
  end

  def find(results, key_match)
    results.find {|k, v| k =~ key_match }.last
  end

  def test_start_stop
    memprof = Memprof2.new.configure({})
    Memprof2.start
    a = "abc"
    12.times{ "abc" }
    results = memprof.collect_info
    Memprof2.stop
    assert_equal(rvalue_size, find(results, /test_memprof2.rb:15:String/))
    assert_equal(rvalue_size * 12, find(results, /test_memprof2.rb:16:String/))
  end

  def test_run
    memprof = Memprof2.new.configure({})
    results = nil
    Memprof2.run do
      a = "abc"
      results = memprof.collect_info
    end
    assert_equal(rvalue_size, find(results, /test_memprof2.rb:27:String/))
  end

  def test_report_out
    opts = {out: "tmp/test_report.out"}
    Memprof2.start
    a = "abc"
    Memprof2.report(opts)
    Memprof2.stop
    assert_match("test/test_memprof2.rb:36:String\n", File.read(opts[:out]))
  end

  def test_report!
    opts_bang = {out: "tmp/test_report_bang.out"}
    opts = {out: "tmp/test_report.out"}
    Memprof2.start
    a = "abc"
    Memprof2.report!(opts_bang) # clear
    Memprof2.report(opts)
    Memprof2.stop
    assert_match("test/test_memprof2.rb:46:String\n", File.read(opts_bang[:out]))
    assert_match("", File.read(opts[:out]))
  end

  def test_run_with_result
    opts = {out: "tmp/test_run_with_report.out"}
    Memprof2.run_with_report(opts) do
      a = "abc"
    end
    assert_match("test/test_memprof2.rb:57:String\n", File.read(opts[:out]))
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
memprof2-0.1.2 test/test_memprof2.rb