Class: SimpleCov::CurrentRun

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/current_run.rb

Overview

The state one measured run accumulates in one process: the pid and start time that identify it, the result it computes, the flags the merge coordination reads, and the serial the parent hands each forked subprocess. A new run is a new object, which is what lets anything needing a clean slate begin one instead of unsetting state by hand.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collating_result=(value) ⇒ Object (writeonly)

Sets the attribute collating_result

Parameters:

  • value

    the value to set the attribute collating_result to.



11
12
13
# File 'lib/simplecov/current_run.rb', line 11

def collating_result=(value)
  @collating_result = value
end

#pidObject

Returns the value of attribute pid.



10
11
12
# File 'lib/simplecov/current_run.rb', line 10

def pid
  @pid
end

#process_start_timeObject

Returns the value of attribute process_start_time.



10
11
12
# File 'lib/simplecov/current_run.rb', line 10

def process_start_time
  @process_start_time
end

#resultObject

Returns the value of attribute result.



10
11
12
# File 'lib/simplecov/current_run.rb', line 10

def result
  @result
end

#subprocess_serialObject

A monotonically increasing serial the parent assigns to each forked subprocess. The default at_fork builds the worker's command_name from this rather than the OS pid: the serial sequence is the same from one run to the next, so a re-run overwrites the previous run's resultset entries instead of writing uniquely-named ones that pile up (#1171).



49
50
51
# File 'lib/simplecov/current_run.rb', line 49

def subprocess_serial
  @subprocess_serial ||= 0
end

Instance Method Details

#collating_result?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/simplecov/current_run.rb', line 31

def collating_result?
  !!@collating_result
end

#forked_subprocess?Boolean

Reading a mark that was never set answers nil, which is the answer wanted.

Returns:

  • (Boolean)


36
37
38
# File 'lib/simplecov/current_run.rb', line 36

def forked_subprocess?
  !!@forked_subprocess
end

#mark_forked_subprocess!Object



40
41
42
# File 'lib/simplecov/current_run.rb', line 40

def mark_forked_subprocess!
  @forked_subprocess = true
end

#next_subprocess_serial!Object



53
54
55
# File 'lib/simplecov/current_run.rb', line 53

def next_subprocess_serial!
  @subprocess_serial = subprocess_serial + 1
end

#result?Boolean

Answers exactly false while no result was ever stored, which is how "never computed" stays distinct from "cleared to nil".

Returns:

  • (Boolean)


27
28
29
# File 'lib/simplecov/current_run.rb', line 27

def result?
  instance_variable_defined?(:@result) && (_ = @result)
end

#successorObject

The result, the coordination flags and the identity belong to the run that ends; the fork genealogy belongs to the process and carries over. A child that restarts tracking must not forget it was forked, or it would produce the final report itself, and a parent must not recount from zero, or its next children's names would collide with its first ones (#1171).



18
19
20
21
22
23
# File 'lib/simplecov/current_run.rb', line 18

def successor
  following = self.class.new
  following.subprocess_serial = @subprocess_serial
  following.mark_forked_subprocess! if forked_subprocess?
  following
end