File: minitest.rb

package info (click to toggle)
ruby-test-prof 1.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,448 kB
  • sloc: ruby: 13,093; sh: 4; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,306 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
# frozen_string_literal: true

require "minitest/base_reporter"

module Minitest
  module TestProf
    class MemoryProfReporter < BaseReporter # :nodoc:
      attr_reader :tracker, :printer, :current_example

      def initialize(io = $stdout, options = {})
        super

        configure_profiler(options)

        @tracker = ::TestProf::MemoryProf.tracker
        @printer = ::TestProf::MemoryProf.printer(tracker)

        @current_example = nil
      end

      def prerecord(group, example)
        set_current_example(group, example)
        tracker.example_started(current_example)
      end

      def record(example)
        tracker.example_finished(current_example)
      end

      def start
        tracker.start
      end

      def report
        tracker.finish
        printer.print
      end

      private

      def set_current_example(group, example)
        @current_example = {
          name: example.gsub(/^test_(?:\d+_)?/, ""),
          location: location_with_line_number(group, example)
        }
      end

      def configure_profiler(options)
        ::TestProf::MemoryProf.configure do |config|
          config.mode = options[:mem_prof_mode]
          config.top_count = options[:mem_prof_top_count] if options[:mem_prof_top_count]
        end
      end
    end
  end
end