Class: TestBench::DetectCoverage

Inherits:
Object
  • Object
show all
Defined in:
lib/test_bench/detect_coverage/trace.rb,
lib/test_bench/detect_coverage/detect_coverage.rb,
lib/test_bench/detect_coverage/controls/receiver.rb

Defined Under Namespace

Modules: Controls Classes: Invocation, Output, Trace

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths, run_arguments) ⇒ DetectCoverage

Returns a new instance of DetectCoverage.



6
7
8
9
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 6

def initialize(paths, run_arguments)
  @paths = paths
  @run_arguments = run_arguments
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



3
4
5
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 3

def paths
  @paths
end

#run_argumentsObject (readonly)

Returns the value of attribute run_arguments.



4
5
6
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 4

def run_arguments
  @run_arguments
end

Class Method Details

.build(path, *additional_paths, **run_arguments) ⇒ Object



11
12
13
14
15
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 11

def self.build(path, *additional_paths, **run_arguments)
  paths = [path, *additional_paths]

  new(paths, run_arguments)
end

.call(path, *additional_paths, **run_arguments, &block) ⇒ Object



17
18
19
20
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 17

def self.call(path, *additional_paths, **run_arguments, &block)
  instance = build(path, *additional_paths, **run_arguments)
  instance.(&block)
end

Instance Method Details

#call(&block) ⇒ Object



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
75
76
# File 'lib/test_bench/detect_coverage/detect_coverage.rb', line 22

def call(&block)
  reader, writer = IO.pipe

  child_process = fork do
    reader.close

    output = Output.new

    session = TestBench::Session.build(output:)

    TestBench::Run.(session: session, **run_arguments) do |run|
      actuator = proc {
        paths.each do |path|
          run.path(path)
        end
      }

      Trace.(actuator) do |method_specifier|
        if method_specifier.start_with?(TestBench::DetectCoverage.name)
          next
        end

        test_file = output.current_test_file

        text = [
          method_specifier,
          test_file
        ].join("\t")

        writer.puts(text)
      end

      writer.puts

    ensure
      writer.close
    end
  end

  writer.close

  until reader.eof?
    text = reader.gets.chomp

    break if text.empty?

    method_specifier, test_file = text.split("\t", 2)

    invocation = Invocation.new(method_specifier, test_file)

    block.(invocation)
  end

  Process.wait(child_process)
end